Jump to content

Archived

This topic is now archived and is closed to further replies.

theflea912

MySQL INSERT

Recommended Posts

Ok so I have this form that submits the data entered into a database. I have double and triple checked the simple things such as names of fields, names of variables, etc. And yet I still get this error 1065 whih looks like this:
[b]Error: 1065 SQLSTATE: 42000 (ER_EMPTY_QUERY) Message: Query was empty [/b]

[code]
<?php

//begining of the conversion to variables
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$userid = $_POST['userid'];
$comments = $_POST['comments'];
$hiredate = date("Y-m-d");

//db connection stuff
$link = mysql_connect("mysql18.powweb.com","theflea912","**********");
mysql_select_db("qantasvaforums",$link);

//Insert pilots
$query=mysql_result("INSERT INTO pilot (fname, lname, email, userid, comments, hiredate) values ('$fname', '$lname','$email','$userid','$comments','$hiredate' )");
$query=mysql_query($query);
$result=mysql_result($result);

if (!$res) {
echo "Error " . mysql_errno() . " in SQL ";
echo "<PRE>$sql</PRE>";
echo mysql_error;
exit;
}
?> [/code]
So what is wrong?

Share this post


Link to post
Share on other sites
You didn't check enough times!!!!!

//Insert pilots
$query=mysql_[b]query[/b]("INSERT INTO pilot (fname, lname, email, userid, comments, hiredate) values ('$fname', '$lname','$email','$userid','$comments','$hiredate' )");

you can do your own checking on the query results!!!!!

Share this post


Link to post
Share on other sites
Yeah I tried that. One problem, it doesn't work. Heres the code now:

[code]
<?php

//begining of the conversion to variables
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$userid = $_POST['userid'];
$comments = $_POST['comments'];
$hiredate = date("Y-m-d");

//db connection stuff
$link = mysql_connect("mysql18.powweb.com","theflea912","**********");
mysql_select_db("qantasvaforums",$link);

//Insert pilots
$query=mysql_query("INSERT INTO pilot (fname, lname, email, userid, comments, hiredate) values ('$fname', '$lname','$email','$userid','$comments','$hiredate' )");
$query = mysql_query($query);
$res = mysql_result($result);

//Error Reporting
if (!$res) {
echo "Error " . mysql_errno() . " in SQL ";
echo "<PRE>$sql</PRE>";
echo mysql_error;
exit;
}
?>
[/code]

Share this post


Link to post
Share on other sites
You have a few problems with the code below:
[code]//Insert pilots
$query=mysql_query("INSERT INTO pilot (fname, lname, email, userid, comments, hiredate) values ('$fname', '$lname','$email','$userid','$comments','$hiredate' )");
$query = mysql_query($query);
$res = mysql_result($result);

//Error Reporting
if (!$res) {
echo "Error " . mysql_errno() . " in SQL ";
echo "<PRE>$sql</PRE>";
echo mysql_error;
exit;
}[/code]
You are using mysql_query twice! Which isnot needed as in affect you are quering an already queriey query. Change the above code to the following:
[code]//Insert pilots
//setup our query
$query = "INSERT INTO pilot (fname, lname, email, userid, comments, hiredate) VALUES ('$fname', '$lname', '$email', '$userid',' $comments', '$hiredate' )");

//run our query we setup above
mysql_query($query) or die("MySQL Error: " . mysql_error());[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.