zhangy Posted June 24, 2009 Share Posted June 24, 2009 Hi, I've been going over this script for days now and cant see the problem. If anyone can see what the heck I'm missing I'd appreciate it. As of now when the form is submitted it just goes to the header('Location: ../'); but it doesn't actually store any of the form info in the database. ??? <?php error_reporting(E_ALL); session_start(); function check_input($data, $problem='') { $data = mysql_real_escape_string(htmlentities($data)); if ($problem && strlen($data) == 0) { show_error($problem); } return $data; } function show_error($myError) { ?> <html> <body> <strong>Please correct the following error:</strong><br /> <?php echo $myError; ?> </body> </html> <?php exit(); } if ( isset($_POST['submit']) ) { require_once('load_data.php'); if (!mysql_connect($db_host, $db_user, $db_pwd)) die("Can't connect to database"); if (!mysql_select_db($database)) die("Can't select database"); $title = check_input($_POST['title'], "Please enter a title. Thanks."); $post = check_input($_POST['post'], "Please enter your post. Thanks."); $category = check_input($_POST['category'], "Please categorize your post. Thanks."); $tags = check_input($_POST['tags'], "Please tag your post. Thanks."); $ip = $_SERVER['REMOTE_ADDR']; $insert = mysql_query("INSERT INTO $table (title, post, tags, category, ip_address) VALUES ('$title', '$post', '$tags', '$category', '$ip')"); } header('Location: ../'); exit(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/163465-form-processing-script/ Share on other sites More sharing options...
Adam Posted June 24, 2009 Share Posted June 24, 2009 Most likely you have a MySQL syntax error, try changing the query to this: if (!$insert = mysql_query("INSERT INTO $table (title, post, tags, category, ip_address) VALUES ('$title', '$post', '$tags', '$category', '$ip')")) { throw new Exception('MySQL Error: ' . mysql_error()); } Quote Link to comment https://forums.phpfreaks.com/topic/163465-form-processing-script/#findComment-862495 Share on other sites More sharing options...
zhangy Posted June 24, 2009 Author Share Posted June 24, 2009 Hi, thanks for the response. I tried using the mysql_error() but unfortunately now when the form is submitted I just get a blank screen with no error message. Any other suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/163465-form-processing-script/#findComment-862497 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.