Code to insert check box elements in the database
<?php
if(isset($_POST['button']))
{
//count-counts varibale in array
$num=count($_POST['hobbies']);
$errors=array();
$total_hobbies="";
for($i=0;$i<$num;$i++)
{
$total_hobbies=$total_hobbies.$_POST['hobbies'][$i].",";
}
$total_hobbies = substr($total_hobbies, 0,-1); // returns "ef"
//echo $total_hobbies;
if(empty($_POST['name']))
{
$errors[]="Your Name field is empty.Please fill it";
}
else
{
$name=$_POST['name'];
}
if(empty($_POST['address']))
{
$errors[]="Your address field is empty.Please fill it";
}
else
{
$address=$_POST['address'];
}
if(empty($_POST['user_name']))
{
$errors[]="Your user_name field is empty.Please fill it";
$user_name=FALSE;
}
else
{
$user_name=$_POST['user_name'];
}
$education=$_POST['education'];
$gender=$_POST['gender'];
if(strlen($_POST['pass'])<4)
{
$errors[]="Password field cannot be less than 4 character.Please fill it";
}
else
{
$pass=$_POST['pass'];
}
if (empty($errors))
{
require_once('connect.php');
//echo "$name $address $user_name $pass";
$query1="select user_id from profile where user_name=\"$user_name\"";
$result1=mysql_query($query1);
if(mysql_num_rows($result1)>0)
{
echo "This username is not available";
}
else
{
$query="insert into profile(name,address,user_name,pass,added_on) values ('$name','$address','$user_name',MD5('$pass'),NOW())";
//echo $query;
$result=mysql_query($query);
if (mysql_affected_rows()==1)
{
echo "You Are registered";
$id=mysql_insert_id();//gives last inserted id which is useful auto increment
if($_FILES['photo']['type']=='image/jpeg' or $_FILES['photo']['type']=='image/pjpeg')
{
$ext=".jpg";
}
else if ($_FILES['photo']['type']=='image/gif')
{
$ext=".gif";
}
else
{
echo "This image format is not allowed";
}
$file_name=$id.$ext;//7.jpg
$file_name1="tb".$id.$ext;//7.jpg
$query12="update profile set image='$file_name' where user_id=$id";
mysql_query($query12);//for image as image id is not initially known which is required to make file name
if (copy($_FILES['photo']['tmp_name'],"images/$file_name"))
{
echo "File Uploaded";
$sizes = getimagesize("images/$file_name");
//give image width and height//0-width 1 heigh
$thumb = imagecreatetruecolor(100, 100);//creates empty canvas
$source = imagecreatefromjpeg("images/$file_name");//this is source
// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, 100, 100, $sizes[0], $sizes[1]);
// Output
//imagejpeg($thumb);
imagejpeg($thumb,"images/$file_name1");
/*$thumb1 = imagecreatetruecolor(400, 400);//creates empty canvas
$source1 = imagecreatefromjpeg("images/$file_name");//this is source
// Resize
imagecopyresized($thumb1, $source1, 0, 0, 0, 0, 400, 400, $sizes[0], $sizes[1]);
// Output
//imagejpeg($thumb);
imagejpeg($thumb1,"images/$file_name");*/
}
else
{
echo "File could not be uploaded";
}
}
else
{
echo "You Are NOT registered";
}
}
}
else
{
$errors_num=count($errors);
for($i=0;$i<$errors_num;$i++)
{
echo "{$errors[$i]}<br/>";
}
}
}//end of submit
?>
<form action="register.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
<p>Name
<label>
<input type="text" name="name" id="name" />
</label>
</p>
<p>Address
<input type="text" name="address" id="address" />
</p>
<p>Education
<label>
<select name="education">
<option value="1">Under Slc</option>
<option value="2">Intermediate</option>
<option value="3">Above Intermediate</option>
</select>
</label>
</p>
<p>Gender:
<label>
<input type="radio" name="gender" value="1" checked="checked"/>
Male</label>
<label>
<input type="radio" name="gender" value="2"/>
Female</label>
<br />
</p>
<p>Hobbies
<label>
<input type="checkbox" name="hobbies[]" value="playing" />
Playing</label>
<label>
<input type="checkbox" name="hobbies[]" value="Singing" />
Singing</label>
<br />
</p>
<p>Image
<label>
<input type="file" name="photo" />
</label>
</p>
<p>Username
<input type="text" name="user_name" id="user_name" />
</p>
<p>Password
<input type="password" name="pass" id="pass" />
</p>
<p>
<input type="submit" name="button" id="button" value="Submit" />
</p>
</form>
<?php
/*
mysql_connect()//connects
mysql_select_db()//
mysql_query()//passes query to mysql from php/
//CUD-Create-Unpdate-Delete---
//R-Read
mysql_affected_rows
mysql_num_rows
mysql_fetch_array
*/
?>
Related posts
Popular posts
-
Damber Nepali Songs
Top & Famous Songs Aja Aakash Ma Euta Tara Tara Antim Palta Bhetna Aau Sabai Sathi Gaye Bigreko Manche Ma Ke Samjhi Khelyau Timro Pauju ...
-
ACKNOWLEDGEMENT and table of content of E-shopping
ACKNOWLEDGEMENT This report has been prepared for the Final Year Project on topic “E-shoppin...
-
Questions for boring minds
1) Without touching,how will you kill a Plant ? a) By Knife b) By Rope and Gun c) By Scolding d) None 2) I was in Dream. In Dream I visited ...
Featured Post
If Something Happened to You, Could Your Family Find Your Money?
Nobody likes this question, so let's get it over with quickly. If you were seriously ill or died tomorrow, would your family know whe...
Popular Posts
-
Your Loan History Follows You: CIB Reports and Blacklisting in Nepal
Every time you apply for a loan from a bank or financial institution in Nepal, someone checks your record with the Credit Information Bur...
-
What a Share Trade Really Costs: Commission, Fees and Capital Gains Tax
You buy a share at Rs 500 and sell it at Rs 540. That's Rs 40 profit per share, right? Not quite. By the time the broker, SEBON, the ...
-
SIP in Nepal: Investing a Fixed Amount Every Month in Mutual Funds
A question I get a lot: "I don't have a big sum to invest. Is it even worth starting?" Yes. In fact, for most salaried peop...
-
Reading Your Salary Slip: Where Your Pay Goes Before It Reaches You
Your offer letter said Rs 60,000 a month. Your bank account says something smaller. Most people shrug and assume "tax," but a s...
-
Drupal JavaScripts to hide and show resources
{# 1. Main slider paragraph template #} {# File: templates/paragraph--slider-with-resources.html.twig #} <div class="slider-with-res...
-
Buying Gold This Tihar? Jewellery Isn't the Same as Investing in Gold
In most Nepali families, gold isn't really a financial decision. It's a wedding gift, a mother's security, something you buy ...
-
EPF, CIT and SSF: Where the Retirement Deduction on Your Payslip Goes
If you have a salaried job in Nepal, your payslip probably has a line that quietly takes a chunk of your pay before you see it. It might ...
-
Small Scans, Big Leaks: Getting Control of Your Wallet and QR Spending
A few years ago, paying for tea meant opening your purse and seeing the notes get thinner. Now it's a scan, a beep, done. eSewa, Khal...
-
Festival Spending Without the Hangover: Start Saving for Next Dashain Now
Dashain is just behind us and Tihar is a couple of weeks away. If you're like most Nepali households, this is the most expensive stre...
-
Cloudflare Settings for Marketing Websites
Cloudflare is a widely-used content delivery network (CDN) and cybersecurity company that offers a suite of performance and security solutio...
No comments:
Post a Comment