PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Ok. i have a problem that whenever i visit the page it send the data into the database. i only want the data to be send when the user hit submit bottom.
franknu wrote:I know. i tried doing it , many diffrent ways.
but it should be there
To a degree, it should be there, yes. The degree being that a condition should be there, but not looking for a submit button. Although in this case it's not even looking for that; it's looking at a constant, which doesn't exist I bet.
Something tells me you are developing with E_NOTICE turned off. Tsk, tsk.
if(isset($_POST['BusinessName']))
{
$query = "INSERT INTO `messages` (`BusinessName`,`date`,`from`,`status`,`subject`,`message`)
VALUES ('".$_SESSION['BusinessName']."','".$date."','".$from."', '".$status."','".$subject."',
'".$message."')";
$result = mysql_query($query);
if(!$result)
{
echo mysql_error();
}else{
echo " Your Message have been sent. We will get back to you. <br>";
}
}
Basically your condition should check to see if a certain criteria is met before updating/inserting. Perhaps checking to see if the form data array is empty? Or perhaps checking to see if the servers request method was post? Of course, you could always check to see if the constant 'Submit' is set to true, which is what you are doing in the code you posted above, but then you would more than likely be setting that constant based on something else, which you have failed to show us in any code that you have provided as of yet.