OK, I've been hitting my head on the desk for an hour now, I'm just trying to do a simple insert, but it's not working somewhere. The page loads, and acts like everything is fine (no hanging on a blank page, no errors, nada) except that the row is not added to the DB. The page acts like everything is cool, mysql acts like no query was ever sent. Code follows:
mysql_query("insert into posts (UserName, Message, TimeStamp, PostID, Subject, IP, ForumID, Replies, LastPost) values ('$PostUserName', '$PostMessage', '$TimeStamp', '$PostID', '$PostSubject', '$IP', '$ForumID', 0, '$LastPost'");
I have echoed ALL of the variables, and their values are all correct. I just don't get it. In case it matters, see below for the complete code 🙂
I think the problem might be with variable types. (ie: if a variable is a string in php, would sending it to a int field in a mysql DB cause issues??) I know php is supposedly a typeless language, or something like that, but I'm an old c++ buff, and you will NEVER convince me that a variable doesn't have to have a type 🙂 (if I had a dollar for every time I've typed "int $test=0;" I'd be rich)
Thanks in advance for any insight,
-Chris
Complete page:
<?php
if(!session_id())
{
session_start();
}
//Verify login here later
require_once('DB_Connect.php');
$TimeStamp=date("m/d/Y h:i A");
$PostID=0;
$IDR=mysql_query("select * from posts");
while($IData=mysql_fetch_assoc($IDR))
{
if($IData['PostID']>=$PostID)
{
$PostID=$IData['PostID']+1;
}
}
$IP=$_SERVER['REMOTE_ADDR'];
$LastPost=$TimeStamp." ".$PostUserName;
mysql_query("insert into posts (UserName, Message, TimeStamp, PostID, Subject, IP, ForumID, Replies, LastPost) values ('$PostUserName', '$PostMessage', '$TimeStamp', '$PostID', '$PostSubject', '$IP', '$ForumID', 0, '$LastPost'");
echo $PostUserName."<br>".$PostMessage."<br>".$TimeStamp."<br>".$PostID."<br>".$PostSubject."<br>".$IP."<br>".$ForumID."<br>".$LastPost;
?>
<html>
<head>
<!-- <META HTTP-EQUIV="refresh" content="1; URL=index.php"> -->
<title>Post Added</title>
</head>
<body>
<h3>Your post was added successfully. You will be returned to the main page shortly</h3>
</body>
</html>