Jump to content

form processing script


zhangy

Recommended Posts

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

?>

 

Link to comment
https://forums.phpfreaks.com/topic/163465-form-processing-script/
Share on other sites

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.