tobimichigan Posted May 13, 2009 Share Posted May 13, 2009 Hi there, Code gurus please help me check this code and probably help me identify what is wrong with it. I keep getting "Query was empty" and nothing is inserted into the table. Here's the form: <form action='Register_Action.php' method='post' enctype="multipart/form-data" name='register'> <table width='28%' border='0' align='center' cellpadding='0' cellspacing='0'> <tr> <td colspan='2'><div align='center'> <p><font size='2' face='verdana'>WELCOME TO STAFFCAMS Registration FORM</font></p> </div></td> </tr> <tr> <td width='31%'> </td> <td width='69%'> </td> </tr> <tr> <td colspan='2'><hr></td> </tr> <tr> <td height='26'><font size='2' face='verdana'>PF NO.</font></td> <td><font size='2' face='verdana'> <input type='text' name='pfno'> </font></td> </tr> <tr> <td height='28'><font size='2' face='verdana'>LEDGER NO.</font></td> <td><font size='2' face='verdana'> <input type='text' name='ledgerno'> </font></td> </tr> <tr> <td height='25'><font size='2' face='verdana'>FIRST NAME</font></td> <td><font size='2' face='verdana'> <input type='text' name='fname'> </font></td> </tr> <tr> <td height='25'><font size='2' face='verdana'>OTHER NAMES</font><font size='2' face='verdana'></td> <td><font size='2' face='verdana'> <input type='text' name='oname'> </font></td> </tr> <tr> <td height='25'><font size='2' face='verdana'>LAST NAME</font></td> <td><font size='2' face='verdana'> <input type='text' name='lname'> </font></td> </tr> <tr> <td height='25'><font size='2' face='verdana'>STATE OF ORIGIN</font></td> <td><font size='2' face='verdana'> <input type='text' name='stateoforigin'> </font></td> </tr> <tr> <td height='25'><font size='2' face='verdana'>LOCAL GOVERNMENT</font></td> <td><font size='2' face='verdana'> <input type='text' name='soorigin'> </font></td> </tr> <tr> <td height='25'><font size='2' face='verdana'>NATIONALITY</font></td> <td><font size='2' face='verdana'> <input type='text' name='Nationality'> </font></td> </tr> <tr> <td height='26'><font size='2' face='verdana'>Email address</font></td> <td><font size='2' face='verdana'> <input type='text' name='email'> </font></td> </tr> <tr> <td height='25'><font size='2' face='verdana'>RESIDENTIAL ADDRESS</font></td> <td><font size='2' face='verdana'> <input type='text' name='residentialadd' /> </font></td> </tr> <tr> <td height='25'><font size='2' face='verdana'>TELEPHONE NUMBER</font></td> <td><font size='2' face='verdana'> <input type='text' name='residentialadd'> </font></td> </tr> <tr> <td height='25'><font size='2' face='verdana'>DEPARTMENT</font></td> <td><font size='2' face='verdana'> <input type='text' name='department' /> </font></td> </tr> <tr> <td height='25'><font size='2' face='verdana'>MARITAL STATUS</font></td> <td><font size='2' face='verdana'> <input type='text' name='marital'> </font></td> </tr> <tr> <td height='25'><font size='2' face='verdana'>SEX</font></td> <td><font size='2' face='verdana'> <input type='text' name='sex'> </font></td> </tr> <tr> <td height='25'><font size='2' face='verdana'>AMOUNT DEDUCTIBLE</font></td> <td><font size='2' face='verdana'> <input type='text' name='amountd' /> </font></td> </tr> <tr> <td> </td> <td><font size='2' face='verdana'> <input type='submit' name='Submit' value='Register'> </font></td> </tr> <tr> <td colspan='2'><hr></td> </tr> <tr> <td> </td> <td> </td> </tr> </table> </form><div align='center'><font size='1' face='verdana'><a href='index.php'>Back to login page</a></font></div> <td colspan='2'><div align='center'><font size='1' face='verdana'>TM</font></div></td> and here's the Register_Action.php action script code: <?php $link = mysql_connect("localhost", "root", "") or die("Could not connect"); $db = mysql_select_db("lasustaffcams", $link) or die("Could not select database"); $amountd=$_POST['amountd']; $dpt=$_POST['department']; $email=$_POST['email']; $fname =$_POST['fname']; $id=$POST['id']; $ledgerno =$_POST['ledgerno']; $lga =$_POST['lga']; $lname=$_POST['lname']; $Nationalty=$_POST['Nationalty']; $oname=$_POST['oname']; $pfno=$_POST['pfno']; $residentialaddress=$_POST['pfno']; $soorigin=$_POST['soorigin']; $today= date("Ymd H:i:s"); $result = mysql_query("Insert into uaer_table(amountd,department,email,fname,ledgerno,lga,lname,nationalty,oname,pfno,residentialadd,soorigin) values('$amountd','$department','$email','$fname','$ledgerno','$lga','$nationalty','$oname',$pfno,$residentialadd,$soorigin)"); //$result_p_ticket= mysql_query("Insert into pawn_ticket(pawn_ticket_customer_number,pawn_ticket_ticket_number,pawn_ticket_ticket_check_digit,pawn_ticket_ticket_issue_date) values('$cust_no','$pawn_ticket_number','$check_digit_only','$today')"); if (!mysql_query($result)) { die('Error: ' . mysql_error()); } echo "1 record added"; mysql_close($con) ?> <html> <body> </body> </html> Please can someone identify for me why this form returns "Query was empty" each time I click Register Button? Quote Link to comment https://forums.phpfreaks.com/topic/158022-query-was-empty/ Share on other sites More sharing options...
jackpf Posted May 13, 2009 Share Posted May 13, 2009 Jesus...put that in code tags... And also, put or die(mysql_error()); after every query. Quote Link to comment https://forums.phpfreaks.com/topic/158022-query-was-empty/#findComment-833557 Share on other sites More sharing options...
merck_delmoro Posted May 13, 2009 Share Posted May 13, 2009 #Your Code: $result = mysql_query("Insert into uaer_table(amountd,department,email,fname,ledgerno,lga,lname,nationalty,oname,pfno,residentialadd,soorigin) values('$amountd','$department','$email','$fname','$ledgerno','$lga','$nationalty','$oname',$pfno,$residentialadd,$soorigin)"); #Check every variables in your values you forgot to place semi quote on some variables. Quote Link to comment https://forums.phpfreaks.com/topic/158022-query-was-empty/#findComment-833621 Share on other sites More sharing options...
tobimichigan Posted May 13, 2009 Author Share Posted May 13, 2009 Jesus...put that in code tags... And also, put or die(mysql_error()); after every query. What codes do you want me to put in tags. I implemented the die(mysql_error() after every query like you said but it gave a new error in sql saying: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'epe)' at line 1 The field value its refering to actually has to do with the LOCAL GOVERNMENT $lga variable. Here's my modified Register_Action.php script: <?php $link = mysql_connect("localhost", "root", "") or die("Could not connect"); $db = mysql_select_db("lasustaffcams", $link) or die("Could not select database"); $amountd=$_POST['amountd']; $dpt=$_POST['department']; $email=$_POST['email']; $fname =$_POST['fname']; $id=$POST['id']; $ledgerno =$_POST['ledgerno']; $lga =$_POST['lga']; $lname=$_POST['lname']; $Nationalty=$_POST['Nationalty']; $oname=$_POST['oname']; $pfno=$_POST['pfno']; $residentialaddress=$_POST['pfno']; $soorigin=$_POST['soorigin']; $today= date("Ymd H:i:s"); $result = mysql_query("Insert into uaer_table(amountd,department,email,fname,ledgerno,lga,lname,nationalty,oname,pfno,residentialadd,soorigin) values('$amountd','$department','$email','$fname','$ledgerno','$lga','$nationalty','$oname',$pfno,$residentialadd,$soorigin)") or die(mysql_error()); if (!mysql_query($result)) { die('Error: ' . mysql_error()); } echo "1 record added"; mysql_close($con) ?> <html> <body> </body> </html> What am I doing wrong this time? Quote Link to comment https://forums.phpfreaks.com/topic/158022-query-was-empty/#findComment-833623 Share on other sites More sharing options...
tobimichigan Posted May 13, 2009 Author Share Posted May 13, 2009 #Your Code: $result = mysql_query("Insert into uaer_table(amountd,department,email,fname,ledgerno,lga,lname,nationalty,oname,pfno,residentialadd,soorigin) values('$amountd','$department','$email','$fname','$ledgerno','$lga','$nationalty','$oname',$pfno,$residentialadd,$soorigin)"); #Check every variables in your values you forgot to place semi quote on some variables. There's been a little improvement in the code. Now its giving a new type_error saying: "Column count doesn't match value count at row 1" what does this mean? Quote Link to comment https://forums.phpfreaks.com/topic/158022-query-was-empty/#findComment-833627 Share on other sites More sharing options...
jackpf Posted May 13, 2009 Share Posted May 13, 2009 It means that you've got INSERT INTO (columnames...) VALUES (values...) but you've got more column names than you have values. Quote Link to comment https://forums.phpfreaks.com/topic/158022-query-was-empty/#findComment-833628 Share on other sites More sharing options...
tobimichigan Posted May 13, 2009 Author Share Posted May 13, 2009 It means that you've got INSERT INTO (columnames...) VALUES (values...) but you've got more column names than you have values. Please could you be more specific? Here's my sql.table: CREATE TABLE `User_table` ( `id` bigint(20) NOT NULL auto_increment, `pfno` varchar(255) NOT NULL, `ledgerno`varchar(255) NOT NULL, `fname` text NOT NULL, `oname` text NOT NULL, `lname` text NOT NULL, `soorigin` text NOT NULL, `lga` text NOT NULL, `Nationalty` text NOT NULL, `email` text NOT NULL, `residentialadd` text NOT NULL, `department` text NOT NULL, `amountd` text NOT NULL, PRIMARY KEY (`id`) ) TYPE=MyISAM COMMENT='cUser - User Table' AUTO_INCREMENT=1 ; and her's my php $variables: $amountd=$_POST['amountd']; $dpt=$_POST['department']; $email=$_POST['email']; $fname =$_POST['fname']; $id=$POST['id']; $ledgerno =$_POST['ledgerno']; $lga =$_POST['lga']; $lname=$_POST['lname']; $Nationalty=$_POST['Nationalty']; $oname=$_POST['oname']; $pfno=$_POST['pfno']; $residentialaddress=$_POST['pfno']; $soorigin=$_POST['soorigin']; What could be responsible for "Column count doesn't match value count at row 1"? Quote Link to comment https://forums.phpfreaks.com/topic/158022-query-was-empty/#findComment-833631 Share on other sites More sharing options...
jackpf Posted May 13, 2009 Share Posted May 13, 2009 Count your column names on the left side of "VALUES", and then count the values on the right. You'll find they don't match. Idk what doesn't match, you'll just have to look. You know your db/what it's supposed to be doing better than me. Quote Link to comment https://forums.phpfreaks.com/topic/158022-query-was-empty/#findComment-833635 Share on other sites More sharing options...
tobimichigan Posted May 14, 2009 Author Share Posted May 14, 2009 Count your column names on the left side of "VALUES", and then count the values on the right. You'll find they don't match. Idk what doesn't match, you'll just have to look. You know your db/what it's supposed to be doing better than me. Yea, you're right, the columns did not match. I've corrected it. But now its saying "Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1" Here's my updated data: <form action='Register_Action.php' method='post' enctype="multipart/form-data" name='register'> <table width='28%' border='0' align='center' cellpadding='0' cellspacing='0'> <tr> <td colspan='2'><div align='center'> <p><font size='2' face='verdana'>WELCOME TO LASUSTAFFCAMS Registration FORM</font></p> </div></td> </tr> <tr> <td width='31%'> </td> <td width='69%'> </td> </tr> <tr> <td colspan='2'><hr></td> </tr> <tr> <td height='26'><font size='2' face='verdana'>PF NO.</font></td> <td><font size='2' face='verdana'> <input type='text' name='pfno'> </font></td> </tr> <tr> <td height='28'><font size='2' face='verdana'>LEDGER NO.</font></td> <td><font size='2' face='verdana'> <input type='text' name='ledgerno'> </font></td> </tr> <tr> <td height='25'><font size='2' face='verdana'>FIRST NAME</font></td> <td><font size='2' face='verdana'> <input type='text' name='fname'> </font></td> </tr> <tr> <td height='25'><font size='2' face='verdana'>OTHER NAMES</font><font size='2' face='verdana'></td> <td><font size='2' face='verdana'> <input type='text' name='oname'> </font></td> </tr> <tr> <td height='25'><font size='2' face='verdana'>LAST NAME</font></td> <td><font size='2' face='verdana'> <input type='text' name='lname'> </font></td> </tr> <tr> <td height='25'><font size='2' face='verdana'>STATE OF ORIGIN</font></td> <td><font size='2' face='verdana'> <input type='text' name='soorigin'> </font></td> </tr> <tr> <td height='25'><font size='2' face='verdana'>LOCAL GOVERNMENT</font></td> <td><font size='2' face='verdana'> <input type='text' name='lga'> </font></td> </tr> <tr> <td height='25'><font size='2' face='verdana'>NATIONALITY</font></td> <td><font size='2' face='verdana'> <input type='text' name='Nationality'> </font></td> </tr> <tr> <td height='26'><font size='2' face='verdana'>Email address</font></td> <td><font size='2' face='verdana'> <input type='text' name='email'> </font></td> </tr> <tr> <td height='25'><font size='2' face='verdana'>RESIDENTIAL ADDRESS</font></td> <td><font size='2' face='verdana'> <input type='text' name='residentialadd' /> </font></td> </tr> <tr> <td height='25'><font size='2' face='verdana'>TELEPHONE NUMBER</font></td> <td><font size='2' face='verdana'> <input type='text' name='residentialadd'> </font></td> </tr> <tr> <td height='25'><font size='2' face='verdana'>DEPARTMENT</font></td> <td><font size='2' face='verdana'> <input type='text' name='department' /> </font></td> </tr> <tr> <td height='25'><font size='2' face='verdana'>MARITAL STATUS</font></td> <td><font size='2' face='verdana'> <input type='text' name='marital'> </font></td> </tr> <tr> <td height='25'><font size='2' face='verdana'>SEX</font></td> <td><font size='2' face='verdana'> <input type='text' name='sex'> </font></td> </tr> <tr> <td height='25'><font size='2' face='verdana'>AMOUNT DEDUCTIBLE</font></td> <td><font size='2' face='verdana'> <input type='text' name='amountd' /> </font></td> </tr> <tr> <td> </td> <td><font size='2' face='verdana'> <input type='submit' name='Submit' value='Register'> </font></td> </tr> <tr> <td colspan='2'><hr></td> </tr> <tr> <td> </td> <td> </td> </tr> </table> </form> Here's now Register_Action.php, <?php $link = mysql_connect("localhost", "root", "") or die("Could not connect"); $db = mysql_select_db("lasustaffcams", $link) or die("Could not select database"); $amountd=$_POST['amountd']; $dpt=$_POST['department']; $email=$_POST['email']; $fname =$_POST['fname']; $ledgerno =$_POST['ledgerno']; $lga=$_POST['lga']; $lname=$_POST['lname']; $nationalty=$_POST['Nationalty']; $oname=$_POST['oname']; $pfno=$_POST['pfno']; $residentialadd=$_POST['residentialadd']; $sex=$_POST['sex']; $soorigin=$_POST['soorigin']; //$today= date("Ymd H:i:s"); $result = mysql_query("Insert into user_table(amountd,department,email,fname,ledgerno,lga,lname,Nationalty,oname,pfno,residentialadd,sex,soorigin) values('$amountd','$department','$email','$fname','$ledgerno','$lga','$lname','$nationalty','$oname','$pfno','$residentialadd','$sex','$soorigin')") or die(mysql_error()); if (!mysql_query($result)) { die('Error: ' . mysql_error()); } echo "1 record added"; mysql_close($link) ?> The error its giving now seems to be in along the insert query I guess its embeded in the php sql script, ""Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1" Where could this be coming from? Quote Link to comment https://forums.phpfreaks.com/topic/158022-query-was-empty/#findComment-833960 Share on other sites More sharing options...
jackpf Posted May 14, 2009 Share Posted May 14, 2009 Try running addslashes on your post data. Quote Link to comment https://forums.phpfreaks.com/topic/158022-query-was-empty/#findComment-833968 Share on other sites More sharing options...
tobimichigan Posted May 14, 2009 Author Share Posted May 14, 2009 Try running addslashes on your post data. Here's what I did, For Register_Action.php <?php include("input_cl.php"); $link = mysql_connect("localhost", "root", "") or die("Could not connect"); $db = mysql_select_db("lasustaffcams", $link) or die("Could not select database"); $amountd=$_POST['amountd']; $dpt=$_POST['department']; $email=$_POST['email']; $fname =$_POST['fname']; $ledgerno =$_POST['ledgerno']; $lga=$_POST['lga']; $lname=$_POST['lname']; $nationalty=$_POST['Nationalty']; $oname=$_POST['oname']; $pfno=$_POST['pfno']; $residentialadd=$_POST['residentialadd']; $sex=$_POST['sex']; $soorigin=$_POST['soorigin']; //$today= date("Ymd H:i:s"); $result = mysql_query("Insert into user_table(amountd,department,email,fname,ledgerno,lga,lname,Nationalty,oname,pfno,residentialadd,sex,soorigin) values('$amountd','$department','$email','$fname','$ledgerno','$lga','$lname','$nationalty','$oname','$pfno','$residentialadd','$sex','$soorigin')") or die(mysql_error()); if (!mysql_query($result)) { die('Error: ' . mysql_error()); } echo "1 record added"; mysql_close($link) For input_cl.php (where the addslashes array was set: <?php //create array to temporarily grab variables $input_arr = array(); //grabs the $_POST variables and adds slashes foreach ($_POST as $key => $input_arr) { $_POST[$key] = addslashes($input_arr); } ?> But that ugly error "Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1" still comes up. What's wrong now? Quote Link to comment https://forums.phpfreaks.com/topic/158022-query-was-empty/#findComment-833998 Share on other sites More sharing options...
tobimichigan Posted May 14, 2009 Author Share Posted May 14, 2009 I commented the line referring to the input_cl.php Here's now the code: <?php //include("input_cl.php"); $link = mysql_connect("localhost", "root", "") or die("Could not connect"); $db = mysql_select_db("lasustaffcams", $link) or die("Could not select database"); addslashes($amountd)=$_POST['amountd']; addslashes($dpt)=$_POST['department']; addslashes($email)=$_POST['email']; addslashes($fname) =$_POST['fname']; addslashes($ledgerno) =$_POST['ledgerno']; addslashes($lga)=$_POST['lga']; addslashes($lname)=$_POST['lname']; addslashes($nationalty)=$_POST['Nationalty']; addslashes($oname)=$_POST['oname']; addslashes($pfno)=$_POST['pfno']; addslashes($residentialadd)=$_POST['residentialadd']; addslashes($sex)=$_POST['sex']; addslashes($soorigin)=$_POST['soorigin']; //$today= date("Ymd H:i:s"); $result = mysql_query("Insert into user_table(amountd,department,email,fname,ledgerno,lga,lname,Nationalty,oname,pfno,residentialadd,sex,soorigin) values('$amountd','$department','$email','$fname','$ledgerno','$lga','$lname','$nationalty','$oname','$pfno','$residentialadd','$sex','$soorigin')") or die(mysql_error()); if (!mysql_query($result)) { die('Error: ' . mysql_error()); } echo "1 record added"; mysql_close($link) ?> However it returned this error: Fatal error: Can't use function return value in write context in C:\wamp\www\staffCams\Register_Action.php on line 8 Please I need a sharp pointer to resolve this problem... Quote Link to comment https://forums.phpfreaks.com/topic/158022-query-was-empty/#findComment-834033 Share on other sites More sharing options...
jackpf Posted May 14, 2009 Share Posted May 14, 2009 You're running addslashes on the variable. You're supposed to run it on the data. Quote Link to comment https://forums.phpfreaks.com/topic/158022-query-was-empty/#findComment-834052 Share on other sites More sharing options...
tobimichigan Posted May 14, 2009 Author Share Posted May 14, 2009 You're running addslashes on the variable. You're supposed to run it on the data. ..and Sir, how may I do that? Quote Link to comment https://forums.phpfreaks.com/topic/158022-query-was-empty/#findComment-834056 Share on other sites More sharing options...
nadeemshafi9 Posted May 14, 2009 Share Posted May 14, 2009 $result = mysql_query("Insert into uaer_table(amountd,department,email,fname,ledgerno,lga,lname,nationalty,oname,pfno,residentialadd,soorigin) values('$amountd','$department','$email','$fname','$ledgerno','$lga','$nationalty','$oname',$pfno,$residentialadd,$soorigin)"); //$result_p_ticket= mysql_query("Insert into pawn_ticket(pawn_ticket_customer_number,pawn_ticket_ticket_number,pawn_ticket_ticket_check_digit,pawn_ticket_ticket_issue_date) values('$cust_no','$pawn_ticket_number','$check_digit_only','$today')"); if (!mysql_query($result)) { die('Error: ' . mysql_error()); } echo "1 record added"; to $sql = "Insert into uaer_table(amountd,department,email,fname,ledgerno,lga,lname,nationalty,oname,pfno,residentialadd,soorigin) values('$amountd','$department','$email','$fname','$ledgerno','$lga','$nationalty','$oname',$pfno,$residentialadd,$soorigin)"; $result = mysql_query(); //$result_p_ticket= mysql_query("Insert into pawn_ticket(pawn_ticket_customer_number,pawn_ticket_ticket_number,pawn_ticket_ticket_check_digit,pawn_ticket_ticket_issue_date) values('$cust_no','$pawn_ticket_number','$check_digit_only','$today')"); if (!mysql_query($result)) { die('Error: ' . mysql_error()." SQL: ".$sql); } echo "1 record added"; see what your query looks like Quote Link to comment https://forums.phpfreaks.com/topic/158022-query-was-empty/#findComment-834062 Share on other sites More sharing options...
Jibberish Posted May 14, 2009 Share Posted May 14, 2009 With the add slashes function i think you want it to be formatted like this $amountd = addslashes($_POST['amountd']); addslashes is a function that takes a string as an argument and returns it back with backslashes before characters that need to be quoted in database queries etc. (shamelessly stolen form php.net) So you can't make it = a variable, but you can make a variable = to what it returns. Which is what I imagen you want to do. Oh and on another not they seem to recommend using DBMS specific escape function ie. mysqli_real_eascape_string(). you can read more on : http://www.php.net/addslashes Quote Link to comment https://forums.phpfreaks.com/topic/158022-query-was-empty/#findComment-834063 Share on other sites More sharing options...
nadeemshafi9 Posted May 14, 2009 Share Posted May 14, 2009 AAHAHAHHAHAH you are trying to execture a result a result of mysqlquery into mysqlquery WRONG <?php $result = mysql_query("Insert into uaer_table(amountd,department,email,fname,ledgerno,lga,lname,nationalty,oname,pfno,residentialadd,soorigin) values('$amountd','$department','$email','$fname','$ledgerno','$lga','$nationalty','$oname',$pfno,$residentialadd,$soorigin)"); //$result_p_ticket= mysql_query("Insert into pawn_ticket(pawn_ticket_customer_number,pawn_ticket_ticket_number,pawn_ticket_ticket_check_digit,pawn_ticket_ticket_issue_date) values('$cust_no','$pawn_ticket_number','$check_digit_only','$today')"); if (!mysql_query($result)) ?> when in teh above you say if (!mysql_query($result)) - $result is an array derived from teh previouse $result = mysql_query("Insert into uaer_table(amountd,departmen ..... basicaly you already executed it and put teh result into result then you try to execute it again with the variable result which is not an sql statement but is infact a result array from the first mysql query result. CORRECT <?php $sql= "Insert into uaer_table(amountd,department,email,fname,ledgerno,lga,lname,nationalty,oname,pfno,residentialadd,soorigin) values('$amountd','$department','$email','$fname','$ledgerno','$lga','$nationalty','$oname',$pfno,$residentialadd,$soorigin)"); if (!mysql_query($sql)) { die('Error: ' . mysql_error()." SQL: ".$sql); } echo "1 record added"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/158022-query-was-empty/#findComment-834065 Share on other sites More sharing options...
tobimichigan Posted May 14, 2009 Author Share Posted May 14, 2009 AAHAHAHHAHAH you are trying to execture a result a result of mysqlquery into mysqlquery WRONG <?php $result = mysql_query("Insert into uaer_table(amountd,department,email,fname,ledgerno,lga,lname,nationalty,oname,pfno,residentialadd,soorigin) values('$amountd','$department','$email','$fname','$ledgerno','$lga','$nationalty','$oname',$pfno,$residentialadd,$soorigin)"); //$result_p_ticket= mysql_query("Insert into pawn_ticket(pawn_ticket_customer_number,pawn_ticket_ticket_number,pawn_ticket_ticket_check_digit,pawn_ticket_ticket_issue_date) values('$cust_no','$pawn_ticket_number','$check_digit_only','$today')"); if (!mysql_query($result)) ?> when in teh above you say if (!mysql_query($result)) - $result is an array derived from teh previouse $result = mysql_query("Insert into uaer_table(amountd,departmen ..... basicaly you already executed it and put teh result into result then you try to execute it again with the variable result which is not an sql statement but is infact a result array from the first mysql query result. CORRECT <?php $sql= "Insert into uaer_table(amountd,department,email,fname,ledgerno,lga,lname,nationalty,oname,pfno,residentialadd,soorigin) values('$amountd','$department','$email','$fname','$ledgerno','$lga','$nationalty','$oname',$pfno,$residentialadd,$soorigin)"); if (!mysql_query($sql)) { die('Error: ' . mysql_error()." SQL: ".$sql); } echo "1 record added"; ?> Well code guru, I did as you said: <?php //include("input_cl.php"); $link = mysql_connect("localhost", "root", "") or die("Could not connect"); $db = mysql_select_db("lasustaffcams", $link) or die("Could not select database"); $amountd = addslashes($_POST['amountd']); $dpt=addslashes($_POST['department']); $email=addslashes($_POST['email']); $fname =addslashes($_POST['fname']); $ledgerno =addslashes($_POST['ledgerno']); $lga=addslashes($_POST['lga']); $lname=addslashes($_POST['lname']); $nationalty=addslashes($_POST['Nationalty']); $oname=addslashes($_POST['oname']); $pfno=addslashes($_POST['pfno']); $residentialadd=addslashes($_POST['residentialadd']); $sex=addslashes($_POST['sex']); $soorigin=addslashes($_POST['soorigin']); //$today= date("Ymd H:i:s"); $sql = mysql_query("Insert into user_table(amountd,department,email,fname,ledgerno,lga,lname,Nationalty,oname,pfno,residentialadd,sex,soorigin) values('$amountd','$department','$email','$fname','$ledgerno','$lga','$lname','$nationalty','$oname','$pfno','$residentialadd','$sex','$soorigin')") or die(mysql_error()); if (!mysql_query($sql)) { die('Error: ' . mysql_error()." SQL: ".$sql); } echo "1 record added"; ?> But its giving "Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1 SQL: 1" any further suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/158022-query-was-empty/#findComment-834073 Share on other sites More sharing options...
nadeemshafi9 Posted May 14, 2009 Share Posted May 14, 2009 still wrong you are inserting an array into your mysqlquer in if the if actualy executes teh function i said do this $sql = "Insert into user_table(amountd,department,email,fname,ledgerno,lga,lname,Nationalty,oname,pfno,residentialadd,sex,soorigin) values('$amountd','$department','$email','$fname','$ledgerno','$lga','$lname','$nationalty','$oname','$pfno','$residentialadd','$sex','$soorigin')"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()." SQL: ".$sql); } stop being a homo and listen Quote Link to comment https://forums.phpfreaks.com/topic/158022-query-was-empty/#findComment-834081 Share on other sites More sharing options...
jackpf Posted May 14, 2009 Share Posted May 14, 2009 Oh yeah I didn't notice that Quote Link to comment https://forums.phpfreaks.com/topic/158022-query-was-empty/#findComment-834083 Share on other sites More sharing options...
tobimichigan Posted May 14, 2009 Author Share Posted May 14, 2009 Oh yeah I didn't notice that Well thank God I'm not alone....guess I didn't see that too. Nad, I'm so sorry I didn't mean to hurt your feelings. One more thing Nad, since I've now got a working form, how can I introduce a file upload (picture precisely) into these variables and also insert them into the same table? I mean these variables: <?php $amountd = addslashes($_POST['amountd']); $department=addslashes($_POST['department']); $email=addslashes($_POST['email']); $fname =addslashes($_POST['fname']); $ledgerno =addslashes($_POST['ledgerno']); $lga=addslashes($_POST['lga']); $lname=addslashes($_POST['lname']); $nationalty=addslashes($_POST['Nationalty']); $oname=addslashes($_POST['oname']); $pfno=addslashes($_POST['pfno']); $residentialadd=addslashes($_POST['residentialadd']); $sex=addslashes($_POST['sex']); $soorigin=addslashes($_POST['soorigin']); $regdate= date("Ymd H:i:s"); $sql= "Insert into user_table(amountd,department,email,fname,ledgerno,lga,lname,Nationalty,oname,pfno,residentialadd,sex,soorigin,regdate) values('$amountd','$department','$email','$fname','$ledgerno','$lga','$lname','$nationalty','$oname','$pfno','$residentialadd','$sex','$soorigin','$regdate')"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()." SQL: ".$sql); } echo ("1 record added"); ?> Thanks for your help guys...you folks are great Quote Link to comment https://forums.phpfreaks.com/topic/158022-query-was-empty/#findComment-834261 Share on other sites More sharing options...
nadeemshafi9 Posted May 14, 2009 Share Posted May 14, 2009 use a file feild post it lets you pick a file and then it gets posted to teh server , that feild then is not liek normal feild but more complex Quote Link to comment https://forums.phpfreaks.com/topic/158022-query-was-empty/#findComment-834311 Share on other sites More sharing options...
jackpf Posted May 14, 2009 Share Posted May 14, 2009 You will need to make use of <input type="file" /> and the $_FILES array. There are undobtedly some good tutorials on google. Quote Link to comment https://forums.phpfreaks.com/topic/158022-query-was-empty/#findComment-834331 Share on other sites More sharing options...
tobimichigan Posted May 15, 2009 Author Share Posted May 15, 2009 use a file feild post it lets you pick a file and then it gets posted to teh server , that feild then is not liek normal feild but more complex <?php $amountd = addslashes($_POST['amountd']); $department=addslashes($_POST['department']); $email=addslashes($_POST['email']); $fname =addslashes($_POST['fname']); $ledgerno =addslashes($_POST['ledgerno']); $lga=addslashes($_POST['lga']); $lname=addslashes($_POST['lname']); $nationalty=addslashes($_POST['Nationalty']); $oname=addslashes($_POST['oname']); $pfno=addslashes($_POST['pfno']); $residentialadd=addslashes($_POST['residentialadd']); $sex=addslashes($_POST['sex']); $soorigin=addslashes($_POST['soorigin']); $regdate= date("Ymd H:i:s"); $sql= "Insert into user_table(amountd,department,email,fname,ledgerno,lga,lname,Nationalty,oname,pfno,residentialadd,sex,soorigin,regdate) values('$amountd','$department','$email','$fname','$ledgerno','$lga','$lname','$nationalty','$oname','$pfno','$residentialadd','$sex','$soorigin','$regdate')"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()." SQL: ".$sql); } echo ("1 record added"); ?> Nad, please kindly demonstrate what exactly you mean in code tags. So grateful... Quote Link to comment https://forums.phpfreaks.com/topic/158022-query-was-empty/#findComment-834638 Share on other sites More sharing options...
nadeemshafi9 Posted May 15, 2009 Share Posted May 15, 2009 <?php $amountd = addslashes($_POST['amountd']); $department=addslashes($_POST['department']); $email=addslashes($_POST['email']); $fname =addslashes($_POST['fname']); $ledgerno =addslashes($_POST['ledgerno']); $lga=addslashes($_POST['lga']); $lname=addslashes($_POST['lname']); $nationalty=addslashes($_POST['Nationalty']); $oname=addslashes($_POST['oname']); $pfno=addslashes($_POST['pfno']); $residentialadd=addslashes($_POST['residentialadd']); $sex=addslashes($_POST['sex']); $soorigin=addslashes($_POST['soorigin']); $regdate= date("Ymd H:i:s"); $sql= "Insert into user_table(amountd,department,email,fname,ledgerno,lga,lname,Nationalty,oname,pfno,residentialadd,sex,soorigin,regdate) values('$amountd','$department','$email','$fname','$ledgerno','$lga','$lname','$nationalty','$oname','$pfno','$residentialadd','$sex','$soorigin','$regdate')"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()." SQL: ".$sql); } echo ("1 record added"); ?> inside yout form put this <input type="file" name="thefile"> then upload your file like this and referenc eit in the sql to identify teh file with teh record http://us3.php.net/features.file-upload Quote Link to comment https://forums.phpfreaks.com/topic/158022-query-was-empty/#findComment-834647 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.