I'm having a slight problem with my application.... when I submit a form it comes up with this error:
User insert failed. Incorrect integer value: '' for column 'usersID' at row 1
INSERT INTO news (usersID, title, story, image, datetoday, expires) VALUES ('', 'TITLE WILL GO HERE', 'NEWS STORY WILL GO HERE', '', '2011-04-21', '1303397348')
The code to submit the form is the following:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Loudspeaker - Your Number One Music Review Website</title>
<link href="Loudspeaker.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?php
include_once("functions.php");
session_start();
$submit = clean_string($_POST['submit']);
$title = clean_string($_POST['title']);
$story = clean_string($_POST['story']);
$daystoexpire = '7';
$expires = time() + (86400 * $daystoexpire);
$datetoday = date('Y-m-d', $expires);
$usersid = $_SESSION['usersID'];
$newsimage = $_SESSION['imagelocation'];
$message = '';
require_once('../../../2740/recaptcha/recaptchalib.php');
$privatekey = "6Ldbd8ASAAAAAFz8VT29H5w4WLNjsbI-mFY2QkaC";
$resp = recaptcha_check_answer($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);
$message = "";
if ($submit == 'Submit') {
if (!$resp->is_valid) {
// What happens when the CAPTCHA was entered incorrectly
$errMessage = $resp->error;
$message = "<strong>The reCAPTCHA wasn't entered correctly. Please try again.</strong><br />" . "(reCAPTCHA said: $errMessage)<br />";
} else {
// Process valid submission data here
if ($title && $story) {
//process details here
if (strlen($title) > 80) {
$message = "The title you have provided is too long. Please <a href='news_entry.php'>try again</a>";
} else {
if (strlen($story) > 300) {
$message = "The news story you have provided is too long. Please <a href='news_entry.php'>try again</a>";
} else {
require_once("db_connect.php");
if ($db_server) {
mysql_select_db("a200458721");
//Insert news story into news table
$query = "INSERT INTO news (usersID, title, story, image, datetoday, expires) VALUES ('$usersid', '$title', '$story', '$image', '$datetoday', '$expires')";
mysql_query($query) or die("User insert failed. " . mysql_error() . "<br />" . $query);
$message = "News Story Successfully Submitted! Return to <a href='index.php'>homepage</a>";
}
}
}
} else {
$message = "Failed to connect to database";
}
if ($expires < time()) {
// Expired!
}
require_once("db_close.php");
}
} else {
$message = "please fill in all the required fields";
}
echo $message;
mysql_close($db_server);
?>
</body>
</html>
My table in mysql looks like this:
Table name: news
ID (int)
usersID (int)
title (varchar)
story (longtext)
image (varchar)
datetoday (date)
expires (timestrap)
I really don't know why its throwing up the error.... but then again, I'm a newbie at PHP!
Your help is much appreciated! 🙂