Jump to content

Recommended Posts

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!";
}}
?>
Link to comment
https://forums.phpfreaks.com/topic/283144-data-does-not-get-inserted-into-sql/
Share on other sites

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();
}

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

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.