WAMFT1 Posted October 21, 2013 Share Posted October 21, 2013 For some reason the attached code does not submit the data to the sql table. I get the "saved" message but cannot see any obvious reason why the data is not being entered. Can someone please use your expert eye to shed some light on why this is not working? I have a number of forms all using similar coding and they all appear to work fine. <?php if(isset($_POST['Submit'])){ $DateUploaded = protect($_POST['DateUploaded']); $Subject = protect($_POST['Subject']); $Text = protect($_POST['Text']); $URL1 = protect($_POST['URL1']); $ImageType1 = protect($_POST['ImageType1']); $cssclass1 = protect($_POST['cssclass1']); $Notes1 = protect($_POST['Notes1']); $URL2 = protect($_POST['URL2']); $ImageType2 = protect($_POST['ImageType2']); $cssclass2 = protect($_POST['cssclass2']); $Notes2 = protect($_POST['Notes2']); $URL3 = protect($_POST['URL3']); $ImageType3 = protect($_POST['ImageType3']); $cssclass3 = protect($_POST['cssclass3']); $Notes3 = protect($_POST['Notes3']); $URL4 = protect($_POST['URL4']); $ImageType4 = protect($_POST['ImageType4']); $cssclass4 = protect($_POST['cssclass4']); $Notes4 = protect($_POST['Notes4']); $URL5 = protect($_POST['URL5']); $ImageType5 = protect($_POST['ImageType5']); $cssclass5 = protect($_POST['cssclass5']); $Notes5 = protect($_POST['Notes5']); $URL6 = protect($_POST['URL6']); $ImageType6 = protect($_POST['ImageType6']); $cssclass6 = protect($_POST['cssclass6']); $Notes6 = protect($_POST['Notes6']); if(!$Subject || !$Text){ //if any weren't display the error message echo "<center>You need to fill in all of the required fields! This record <b>HAS NOT </b> been saved</center>"; }else{ $res = mysql_query("INSERT INTO `edocs_hoct_comms` (`DateUploaded`, `Subject`, `Text`, `URL1`, `ImageType1`, `cssclass1`, `Notes1`, `URL2`, `ImageType2`, `cssclass2`, `Notes2`, `URL3`, `ImageType3`, `cssclass3`, `Notes3`, `URL4`, `ImageType4`, `cssclass4`, `Notes4`, `URL5`, `ImageType5`, `cssclass5`, `Notes5`, `URL6`, `ImageType6`, `cssclass6`, `Notes6`) VALUES ('".$DateUploaded."', '".$Subject."', '".$Text."', '".$URL1."', '".$ImageType1."', '".$cssclass1."', '".$Notes1."', '".$URL2."', '".$ImageType2."', '".$cssclass2."', '".$Notes2.", '".$URL3."', '".$ImageType3."', '".$cssclass3."', '".$Notes3."'', '".$URL4."', '".$ImageType4."', '".$cssclass4."', '".$Notes4."', '".$URL5."', '".$ImageType5."', '".$cssclass5."', '".$Notes5."', '".$URL6."', '".$ImageType6."', '".$cssclass6."', '".$Notes6."')"); echo "Saved!"; }} ?> Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted October 21, 2013 Share Posted October 21, 2013 You should always check to see if mysql_qeuery executed the query, if there is a problem it will return false. When inserting/updating or deleting records use mysql_affected_rows to verify the query did perform the operation. // check that mysql_query did not return false if(($res = mysql_query($sql)) !== false) { // check that the query did the operation if(mysql_affected_rows() == 1) { echo "Saved!"; } else { echo 'Record not saved!'; } } // query could have a problem. Lets see else { echo 'DATABASE Error: ' . mysql_error(); } Quote Link to comment Share on other sites More sharing options...
BrodaNoel Posted October 21, 2013 Share Posted October 21, 2013 Try to do this:Replace the line 61 for this: echo("INSERT INTO `edocs_hoct_comms` (`DateUploaded`, `Subject`, `Text`, `URL1`, `ImageType1`, `cssclass1`, `Notes1`, `URL2`, `ImageType2`, `cssclass2`, `Notes2`, `URL3`, `ImageType3`, `cssclass3`, `Notes3`, `URL4`, `ImageType4`, `cssclass4`, `Notes4`, `URL5`, `ImageType5`, `cssclass5`, `Notes5`, `URL6`, `ImageType6`, `cssclass6`, `Notes6`) VALUES ('".$DateUploaded."', '".$Subject."', '".$Text."', '".$URL1."', '".$ImageType1."', '".$cssclass1."', '".$Notes1."', '".$URL2."', '".$ImageType2."', '".$cssclass2."', '".$Notes2.", '".$URL3."', '".$ImageType3."', '".$cssclass3."', '".$Notes3."'', '".$URL4."', '".$ImageType4."', '".$cssclass4."', '".$Notes4."', '".$URL5."', '".$ImageType5."', '".$cssclass5."', '".$Notes5."', '".$URL6."', '".$ImageType6."', '".$cssclass6."', '".$Notes6."')"); exit; Then, look in the browser the query, and execute that in a "IDE" of your database. Are you sure that exists this: $_POST['Submit'] ? or $_POST['submit'] ? Paste here the result of: var_dump($_['POST']); and var_dump($_['GET']); So, we can help you Quote Link to comment Share on other sites More sharing options...
BrodaNoel Posted October 21, 2013 Share Posted October 21, 2013 That is the problem: '".$Notes3."'', Replace for: '".$Notes3."', Quote Link to comment Share on other sites More sharing options...
WAMFT1 Posted October 21, 2013 Author Share Posted October 21, 2013 Hi have tried the affected rows solution and fixed up the notes typo and now narrowed down the problem to DATABASE Error: Query was empty Where to from here? Quote Link to comment Share on other sites More sharing options...
Barand Posted October 21, 2013 Share Posted October 21, 2013 if(($res = mysql_query($sql)) !== false) If you have "Query was empty" error then $sql above has no value set. Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted October 21, 2013 Share Posted October 21, 2013 Please use you own common sense before copy and pasting code. I posted an example of how to check if the query executed and inserted a record as well as detect any query errors. You will need to modify the mysql_query($sql) bit to work with your query. Quote Link to comment Share on other sites More sharing options...
Barand Posted October 21, 2013 Share Posted October 21, 2013 There's nought so rare as common sense! (Old Northern proverb) 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.