balamberas Posted March 7, 2009 Share Posted March 7, 2009 I have a html form which get validated and showed to the user at validate_form.php then i want it to be sobmited via submit_form.php. this is not working even though my coding is fine from what i can see. post_an_ad.html <form name="frmTerms" method="post" action="handle_form.php" id="frmTerms" onSubmit="return checkTerms();" enctype="multipart/form-data"> <input name="location" type="text" id="location" size="60"> <button type="submit" name="formSubmit" value="Submit" id="formSubmit">Submit</button> handle_form.php <form name="submit_form" method="POST" action="submit_form.php" id="submit_form" enctype="multipart/form-data"> <input type="hidden" name="location" value="<?=$_POST["location"]?>"> <input type="submit" name="submit" id="submit_form" value="Submit"> submit_form.php <?php if (isset($_POST['submit']) and $_POST['submit'] == 1) { $con = mysql_connect("host", "username", "password") or die(mysql_error()); mysql_select_db("DB", $con) or die(mysql_error()); $sql = "INSERT INTO properties (select, location, rent, title, images, description, contactEmail, number) VALUES ('$_POST[select]', '$_POST[location]', '$_POST[rent] ', '$_POST[title]','$_POST[image]',' $_POST[description]', '$_POST[contactEmail]', '$_POST[number]')"; $result = mysql_query($sql, $con); if($result == false) { user_error(mysql_error()."<br />\n$sql"); } mysql_close($con); } else { user_error("Submit not received in post data"); } ?> pls, help. Link to comment https://forums.phpfreaks.com/topic/148351-insert-data-into-a-database-php-script/ Share on other sites More sharing options...
MasterACE14 Posted March 7, 2009 Share Posted March 7, 2009 you can delete post_an_ad.html as that does the same as handle_form.php. and change this line in handle_form.php: <input type="hidden" name="location" value="<?=$_POST["location"]?>"> to: <input name="location" type="text" id="location" size="60"> in submit_form.php... change this: if (isset($_POST['submit']) and $_POST['submit'] == 1) to this: if (isset($_POST['submit'])) change this: ('$_POST[select]', '$_POST[location]', '$_POST[rent] ', '$_POST[title]','$_POST[image]',' $_POST[description]', '$_POST[contactEmail]', '$_POST[number]')"; to this: ('".$_POST['select']."', '".$_POST['location']."', '".$_POST['rent']."', '".$_POST['title']."','".$_POST['image']."','". $_POST['description']."', '".$_POST['contactEmail']."', '".$_POST['number']."')"; change this: $result = mysql_query($sql, $con); to this: $result = mysql_query($sql); change this: if($result == false) to this: if(!$result) Regards ACE Link to comment https://forums.phpfreaks.com/topic/148351-insert-data-into-a-database-php-script/#findComment-778836 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.