Forum Moderators: coopster
Can anyone shed any light on this? I've only just started with php and sql and it's got me stumped.
$dbuser="root"; //database username
$dbpass=""; //password for the database
$dbname="asset"; //the name of the database
$chandle = mysql_connect("localhost", $dbuser, $dbpass) or die("Connection Failure to Database");
mysql_select_db($dbname, $chandle) or die ($dbname . " Database not found. " . $dbuser);
$mainsection="asset_register"; //The name of the table where web links are stored
$query1="insert into " . $mainsection . " (unitid,make,model,location,user,indreplace,estrelace,purchasedate,oskey,machinekey,officekey,notes) values (\"" . $unitid . "\",\"" . $make . "\",\"" . $model . "\",\"" . $location . "\",\"" . $user . "\",\"" . $indreplace . "\",\"" . $estreplace . "\"," . $purchasedate . "\"," . $oskey . "\"," . $machinekey . "\"," . $officekey . "\"," . $notes .")";
mysql_db_query($dbname, $query1) or die("Failed Query of " . $query1);
some tips:
execute your this query on command line and see whether it works or not then use in php page..
second and very handy tip is that DISPLAY YOUR QUERY on page and see that how does your query look like, because often we make some small mistake in php syntax that turns into an illegal query for mysql,
third tip,
make sure that u use quote for string values to be sent to table and no quotes for integer values..
if still having problems then please write the query without those double quotes so that i can understand and answer you..
$dbuser="root"; //database username
$dbpass=""; //password for the database
$dbname="asset"; //the name of the database
$chandle = mysql_connect("localhost", $dbuser, $dbpass) or die("Connection Failure to Database");
mysql_select_db($dbname, $chandle) or die ($dbname . " Database not found. " . $dbuser);
$mainsection="asset_register"; //The name of the table where web links are stored
$query1="insert into " . $mainsection . " (unitid,make,model,location) values ('$unitid','$make','$model','$location')";
mysql_db_query($dbname, $query1) or die("Failed Query of " . $query1);
What do you get if you do this right before executing the query:
echo $query1;
Do you have error reporting turned on?
Are there any non-null required values in asset_register for which you're not specifying a value?
Do the datatypes of your variables match the required datatypes in your db?