Simple Insert Not working

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bakshi.ishan
Forum Newbie
Posts: 1
Joined: Fri May 21, 2010 9:24 am

Simple Insert Not working

Post by bakshi.ishan »

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");
?>
mikosiko
Forum Regular
Posts: 757
Joined: Wed Jan 13, 2010 7:22 pm

Re: Simple Insert Not working

Post by mikosiko »

should be easy just give you the answer... but I rather prefer give you the tool to figure it out for yourself :wink:

here is your answer... http://dev.mysql.com/doc/refman/5.0/en/insert.html
Post Reply