theflea912 Posted April 7, 2006 Share Posted April 7, 2006 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? Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted April 7, 2006 Share Posted April 7, 2006 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!!!!! Quote Link to comment Share on other sites More sharing options...
theflea912 Posted April 7, 2006 Author Share Posted April 7, 2006 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 Reportingif (!$res) {echo "Error " . mysql_errno() . " in SQL ";echo "<PRE>$sql</PRE>";echo mysql_error;exit;} ?>[/code] Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted April 7, 2006 Share Posted April 7, 2006 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 Reportingif (!$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 abovemysql_query($query) or die("MySQL Error: " . mysql_error());[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.