Click to See Complete Forum and Search --> : mysql_query is not working


prathikanoe
07-02-2009, 02:22 AM
hi..
i am facing a basic silly problem that i am not able to solve.when i attempt to insert values into my database i am not able to do it.the mysql_query is not working here. it is not executing when i give id even it is not null..

here is my code:
<?php

include("connection.php");
if(isset($_POST['Submit']))
{
$name=$_POST['menuname'];
$de=$_POST['des'];
$ord=$_POST['order1'];
echo $q="insert into menureg(menuname,des,order1)values('$name','$de','$ord')";
echo $r=mysql_query($q);
/*if($q)
{
header("location:process.php");
ob_flush();
}*/
}
?>

as per my coe i am not inserting id field, but it is in my database..
id - int(15) , autoincrement,primary key..

can anyone help why mysql_query is not working.. please help me. expecting reply

ryanbutler
07-02-2009, 12:17 PM
My questions would be:

1) Are you connecting to the db in question?

If 1 is cool,

2) Is your script seeing the submit button.

If 1 and 2 are cool,

3) Try surrounding the column names of the query with ticks:

echo $q="insert into menureg(`menuname`,`des`,`order1`)values('$name','$de','$ord')";

aj_nsc
07-02-2009, 12:29 PM
Replace this line:


echo $r=mysql_query($q);


with the following:


mysql_query($q) or die(mysql_error());


and let us know what the error is.

brunoais
07-07-2009, 04:45 AM
Try also changing from this:echo $q="insert into menureg(menuname,des,order1)values('$name','$de','$ord')";to this:echo $q="insert into menureg(menuname,des,order1)values('".$name."','".$de."','".$ord."')";