cturner Posted January 25, 2007 Share Posted January 25, 2007 With the code below I get query was empty. I wondering if there is a better way to do this than what I am doing. Thanks in advance.[code=php:0] $insert = "INSERT INTO `clearingsales` (`selectDay`, `selectDate`, `selectMonth`, `selectYear`, `propertyname`, `time`, `ampm`, `accountname`, `comments`, `select1`, `txt1`, `select2`, `txt2`, `select3`, `txt3`, `select4`, `txt4`, `select5`, `txt5`, `select6`, `txt6`, `select7`, `txt7`, `select8`, `txt8`, `select9`, `txt9`, `select10`, `txt10`, `select11`, `txt11`) VALUES ('$selectDay', '$selectDate', '$selectMonth', '$selectYear', '$propertyname', '$time', '$ampm', '$accountname', '$comments', '$select1', '$txt1', '$select2', '$txt2', '$select3', '$txt3', '$select4', '$txt4', '$select5', '$txt5', '$select6', '$txt6', '$select7', '$txt7', '$select8', '$txt8', '$select9', '$txt9', '$select10', '$txt10', '$select11', '$txt11')"; if (mysql_query ($insert)) { if (($select1 == 'other') && (!empty($other1))) { $update = "UPDATE clearingsales SET select1 = '$other1' WHERE propertyname = '$propertyname'"; } if (mysql_query ($update)) { header ("Location: clearing_sale_added.php"); } else { print "<p>Could not update the entry because: <b>" . mysql_error() . "</b>. The query was $update.</p>"; } } else { print "<p>Could not add the entry because: <b>" . mysql_error() . "</b>. The query was $insert.</p>"; }[/code] Link to comment https://forums.phpfreaks.com/topic/35609-query-was-empty/ Share on other sites More sharing options...
spfoonnewb Posted January 25, 2007 Share Posted January 25, 2007 Is register globals on? Or have you defined all of the variables..?It is much better to leave globals off and use..$_REQUEST[""][code]('$selectDay', '$selectDate', '$selectMonth', '$selectYear', '$propertyname', '$time', '$ampm', '$accountname', '$comments', '$select1', '$txt1', '$select2', '$txt2', '$select3', '$txt3', '$select4', '$txt4', '$select5', '$txt5', '$select6', '$txt6', '$select7', '$txt7', '$select8', '$txt8', '$select9', '$txt9', '$select10', '$txt10', '$select11', '$txt11')[/code] Link to comment https://forums.phpfreaks.com/topic/35609-query-was-empty/#findComment-168676 Share on other sites More sharing options...
cturner Posted January 25, 2007 Author Share Posted January 25, 2007 I have defined all of the variables it is just I didn't want to post them here because there are so many. Link to comment https://forums.phpfreaks.com/topic/35609-query-was-empty/#findComment-168688 Share on other sites More sharing options...
Psycho Posted January 25, 2007 Share Posted January 25, 2007 Why must people put everything on one line?You said that you are getting the query is empty. None of your queries are selecting data, so they won't return any results. What is the exact error message you are receiving and for with query???Also, ther is a problem with the logic. This line: [b]if (mysql_query ($update)) {[/b] assumes that $update has a value. But if the test on the previous if statement was false $update would not have a value. Perhaps that is where the problem is???Try this:[code]<?php $insert = "INSERT INTO `clearingsales` (`selectDay`, `selectDate`, `selectMonth`, `selectYear`, `propertyname`, `time`, `ampm`, `accountname`, `comments`, `select1`, `txt1`, `select2`, `txt2`, `select3`, `txt3`, `select4`, `txt4`, `select5`, `txt5`, `select6`, `txt6`, `select7`, `txt7`, `select8`, `txt8`, `select9`, `txt9`, `select10`, `txt10`, `select11`, `txt11`) VALUES ('$selectDay', '$selectDate', '$selectMonth', '$selectYear', '$propertyname', '$time', '$ampm', '$accountname', '$comments', '$select1', '$txt1', '$select2', '$txt2', '$select3', '$txt3', '$select4', '$txt4', '$select5', '$txt5', '$select6', '$txt6', '$select7', '$txt7', '$select8', '$txt8', '$select9', '$txt9', '$select10', '$txt10', '$select11', '$txt11')"; if (mysql_query ($insert)) { if (($select1 == 'other') && (!empty($other1))) { $update = "UPDATE clearingsales SET select1 = '$other1' WHERE propertyname = '$propertyname'"; if (mysql_query ($update)) { header ("Location: clearing_sale_added.php"); } else { print "<p>Could not update the entry because: <b>" . mysql_error() . "</b>. The query was $update.</p>"; } } else { print "<p>Could not continue because the query would be blank."; } } else { print "<p>Could not add the entry because: <b>" . mysql_error() . "</b>. The query was $insert.</p>"; }?>[/code] Link to comment https://forums.phpfreaks.com/topic/35609-query-was-empty/#findComment-168694 Share on other sites More sharing options...
cturner Posted January 25, 2007 Author Share Posted January 25, 2007 When I test the code I have content in the text box for $other.I have changed my code a bit:[code=php:0] $insert = "INSERT INTO `clearingsales` (`selectDay`, `selectDate`, `selectMonth`, `selectYear`, `propertyname`, `time`, `ampm`, `accountname`, `comments`, `select1`, `txt1`, `select2`, `txt2`, `select3`, `txt3`, `select4`, `txt4`, `select5`, `txt5`, `select6`, `txt6`, `select7`, `txt7`, `select8`, `txt8`, `select9`, `txt9`, `select10`, `txt10`, `select11`, `txt11`) VALUES ('$selectDay', '$selectDate', '$selectMonth', '$selectYear', '$propertyname', '$time', '$ampm', '$accountname', '$comments', '$select1', '$txt1', '$select2', '$txt2', '$select3', '$txt3', '$select4', '$txt4', '$select5', '$txt5', '$select6', '$txt6', '$select7', '$txt7', '$select8', '$txt8', '$select9', '$txt9', '$select10', '$txt10', '$select11', '$txt11')"; if (mysql_query ($insert)) { if (($select1 == 'other') && (!empty($other1))) { $update = "UPDATE clearingsales SET select1 = '$other1' WHERE propertyname = '$propertyname'"; header ("Location: clearing_sale_added.php"); } else { print "<p>Could not update the entry because: <b>" . mysql_error() . "</b>. The query was $update.</p>"; }[/code]and now I get this message: Could not update the entry because: . The query was .. How can I insert data into the database, and if $select1 has been selected and $other1 has content in it then replace $select1 with $other1? That is what I want to achieve. Link to comment https://forums.phpfreaks.com/topic/35609-query-was-empty/#findComment-168704 Share on other sites More sharing options...
cturner Posted January 25, 2007 Author Share Posted January 25, 2007 I have solved the problem. Link to comment https://forums.phpfreaks.com/topic/35609-query-was-empty/#findComment-168711 Share on other sites More sharing options...
kenrbnsn Posted January 25, 2007 Share Posted January 25, 2007 What was the solution?Ken Link to comment https://forums.phpfreaks.com/topic/35609-query-was-empty/#findComment-168712 Share on other sites More sharing options...
Psycho Posted January 25, 2007 Share Posted January 25, 2007 I think it's pretty evident from Reply#4 that his test [b]if (($select1 == 'other') && (!empty($other1))) {[/b] was failing. The message he was receiving was the one for a false result. That is why the original script was getting an empty query. The query variable was only being given a value if the above test was true. and there was no handling if the test was false. Link to comment https://forums.phpfreaks.com/topic/35609-query-was-empty/#findComment-168982 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.