Simple Insert Not working
Posted: Fri May 21, 2010 9:33 am
Hi all,
I am new to php. I want to insert a record in student table with fields ( RollNo,Name,Class,Address). On design page i am fetching these values and sending them to Code.php page.
I have made the RollNo field primary key and is also auto_increment. I dont want the user to insert The rollno. When i dont send the RollNo from the code page in the insert query, the record does not gets added. but if i add $RollNo field and pass it in the query then the data gets added. Can you please tell me what am i missing ?
Thanks
Here is the code on the Code.php page.
<?
mysql_connect("localhost","root","");
mysql_select_db("mydatabase");
//$rollno = $_REQUEST["txt_rollno"];
$name = $_REQUEST["txt_name"];
$class = $_REQUEST["txt_class"];
$add = $_REQUEST["txt_address"];
$query = "insert into tbl_student values ($rollno,'$name','$class','$add')";
//$query = "insert into tbl_student values ($rollno,'$name','$class','$add')";
echo $query;
mysql_query($query);
//header("location:studentDesign.php");
?>
I am new to php. I want to insert a record in student table with fields ( RollNo,Name,Class,Address). On design page i am fetching these values and sending them to Code.php page.
I have made the RollNo field primary key and is also auto_increment. I dont want the user to insert The rollno. When i dont send the RollNo from the code page in the insert query, the record does not gets added. but if i add $RollNo field and pass it in the query then the data gets added. Can you please tell me what am i missing ?
Thanks
Here is the code on the Code.php page.
<?
mysql_connect("localhost","root","");
mysql_select_db("mydatabase");
//$rollno = $_REQUEST["txt_rollno"];
$name = $_REQUEST["txt_name"];
$class = $_REQUEST["txt_class"];
$add = $_REQUEST["txt_address"];
$query = "insert into tbl_student values ($rollno,'$name','$class','$add')";
//$query = "insert into tbl_student values ($rollno,'$name','$class','$add')";
echo $query;
mysql_query($query);
//header("location:studentDesign.php");
?>