...

View Full Version : Stuck on an INSERT..



XBleed
07-12-2005, 04:23 AM
I feel really dumb for asking this. :o

I'm still fairly new to coding in PHP so I'm a little confused here: Simply put, I'm trying to insert data into a table from a simple form but I can't get it to work. I've tried everything I can think of and I still don't understand.. Can anyone see an obvious error in the code?



if ($_POST['do'] == 'insertnewcomment') {
globalize($_POST, array('comment' => INT,'title' => STR_NOHTML));

$DB_site->query("
INSERT INTO ".TABLE_PREFIX."usercomment (userid,postedbyid,comment,title,dateline)
VALUES (".$userinfo[userid].",".$bbuserinfo[userid].",".mysql_escape_string($comment)."',".mysql_escape_string($title)."',".TIMENOW."')");
//Redirect to Member Profile
$url = "member.php?$session[sessionurl]u=$userinfo[userid]";
eval(print_standard_redirect('redirect_postthanks'));

}



<form action="member.php" method="post">
<input type="hidden" name="do" value="insertnewcomment" />
<input type="hidden" name="userid" />
<input type="hidden" name="postedbyid" />
<input type="hidden" name="s" value="$session[sessionhash]" />
<input class="bginput" type="text" name="title" size="45" maxlength="80" /><br />
<input class="bginput" type="text" name="comment" size="45" maxlength="80" /><br />
<input type="submit" class="button" value="Submit" accesskey="s" />
</form>


Thanks,

nikkiH
07-12-2005, 04:43 PM
First thing that popped out at me was a missing space here.

INSERT INTO ".TABLE_PREFIX."usercomment
should be
INSERT INTO ".TABLE_PREFIX." usercomment

Next thing was that I personally wouldn't name anything something that is a keyword in any language I might use. That includes "do".

Other than that, when you get an error, it helps us if you post it.

delinear
07-12-2005, 04:51 PM
I think maybe the space is meant to be missing, since the prefix and the string form the name of the field, eg if TABLE_PREFIX was "delinear_" then the query would be INSERT INTO delinear_usercomment - so putting in a space would break it. But I agree, if there's an error show us what it says, it helps massively to debug what's going wrong and where.

XBleed
07-14-2005, 03:43 AM
Sorry for not getting back.

There actually wasn't an error at all, it just won't insert into the database at all.

I have slightly modified the code since this post (I'll post it as soon as I get home and have access to it) but it's still not inserting any data.

Thanks,

nikkiH
07-14-2005, 02:28 PM
I find that when often where there is no error, yet things don't happen, it's often the fault of an IF that I thought would evaluate to true, but didn't.

See what this actually evaluates to:
if ($_POST['do'] == 'insertnewcomment')

Maybe the insert statement isn't even running.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum