Jump to content

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

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.