PHP Programming > Beginners - Learning PHP
Inserting data into database
(1/1)
Joanna:
Hey, I am trying to insert data into a table wbsUser in the database but can't. What is the problem with this code?
--- PHP Code: ---<html>
<?php
include'connect.php';
if (isset($_POST['submit']))
{
$fullname =$_POST['fullname'];
$username =$_POST['username'];
$password =$_POST['password'];
$address =$_POST['address'];
$email =$_POST['email'];
$cellno =$_POST['cellno'];
$selection = $_POST['selection'];
$birth_month =$_POST['birth_month'];
$birth_day =$_POST['birth_day'];
$birth_year =$_POST['birth_year'];
$agree =$_POST['agree'];
$sql =("INSERT into wbsUser(fullname, username,password,address,
email,cellno,birth_month,birth_day,birth_year,
gender,)
VALUES('$fullname','$username','$password','$address','$email',
'$cellno','$birth_month','$birth_day','$birth_year','$agree')");
$result = mysql_query($sql);
if($sql)
echo"You have successfully registered";
<a href="calendar.php"> To Continue </a> <p> </p>
}
else
{
echo"Invalid registration";
}
?>
<a href="wbsreg.php"> Go Back </a>
</html>
--- End code ---
daveismyname:
you have an extra comma on the fields:
--- PHP Code: ---(fullname, username,password,address,
email,cellno,birth_month,birth_day,birth_year,
gender,)
--- End code ---
lose the last comma
Noodles:
I so so much wrong I do nto know where to start ;D
You will need to sanatise your code before entering it in to mysql.
and yes remove the comma and also no php tags to open close the php when entering html.
field gender but have agree ????
Are you missing a field like agree and gender ?
Try using or die to help with simple errrors
--- PHP Code: ---
$result = mysql_query($sql)or die (mysql_error);
--- End code ---
Navigation
[0] Message Index
Go to full version