Jump to content

Variable wont record to database...


DiscoTrio

Recommended Posts

The following code works perfect but on the insert query the variable $id only rcords as 0.  I have no idea why becuase if I echo that variable it shows correctly...

 

The $id is in a address.

 

	if ($action == 'new_topic'){echo "<a href='forum.php?action=view'>GamePage101 Forums</a> >> <a href='$currentpage'>$forumname</a>";
echo "<form action='$currentpage?action=new_topic&go=post' method='POST'>";
echo "<br>Title:<br><input name='title' id='title' size='100'>";
echo "<br><br><textarea name='content' id='content' style='width:700px;height:400px;'></textarea>";
echo "<br><br><input type=submit value=Post></form>";
	if ($go == 'post'){
	if (!$title || !$content) {print "You must fill out all fields.";}
	if ($session->username == 'Guest') {print "You must be signed in to post.";}
	mysql_query ("INSERT INTO `bmvybfbk_website`.`forum` (`id2`, `title`, `content`, `writer`, `parent`)VALUES ('3', '$title', '$content', '$session->username', '$forum');");
	echo "<b>Posted, <a href='$currentpage'>Click here</a></b>";}}

Link to comment
https://forums.phpfreaks.com/topic/186053-variable-wont-record-to-database/
Share on other sites

not so much weird as it is going to be something that you are overlooking.  echo your query by removing the mysql_query():

 

$sql = "INSERT INTO `bmvybfbk_website`.`forum` (`id2`, `title`, `content`, `writer`, `parent`)VALUES ('3', '$title', '$content', '$session->username', '$forum')";
echo $sql;

 

and see if everything matches up.

so, if you were to echo $forum right above the query, it'd give a value?

 

echo $forum; // 2
$sql = "INSERT INTO `bmvybfbk_website`.`forum` (`id2`, `title`, `content`, `writer`, `parent`)VALUES ('3', '$title', '$content', '$session->username', '$forum')";
echo $sql;

 

let's see how you're defining $forum, 'cause it's not making any sense as to why it's not making it to the query.

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.