Jump to content


Photo

MySQL INSERT


  • Please log in to reply
3 replies to this topic

#1 theflea912

theflea912
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 07 April 2006 - 02:39 AM

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:
Error: 1065 SQLSTATE: 42000 (ER_EMPTY_QUERY) Message: Query was empty

<?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; 
} 
 ?>
So what is wrong?

#2 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 07 April 2006 - 03:08 AM

You didn't check enough times!!!!!

//Insert pilots
$query=mysql_query("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!!!!!
follow me on twitter @PHPsycho

#3 theflea912

theflea912
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 07 April 2006 - 04:08 AM

Yeah I tried that. One problem, it doesn't work. Heres the code now:

<?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;
}
 ?>


#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 07 April 2006 - 03:36 PM

You have a few problems with the code below:
//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;
}
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:
//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());





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users