Jump to content

MySQL INSERT


theflea912

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?
Link to comment
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!!!!!
Link to comment
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]
Link to comment
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.