Jump to content

strange issue: variable insert into database


final60

Recommended Posts

Hi,

Im having a problem with inserting my forum category id into the datase when a new forum post is submitted.

Heres part of the markup


$cat_id = $_GET['cat_id'];

			if(isset($submit) && ($title != 'Title') && strlen($title)>5)
			{
				if(!empty($title) )
				{
					if(!empty($content) && ($content != 'Enter your post content here..') && strlen($content)>9)
					{

						mysql_query("INSERT INTO urbex_forum_posts (user_id,title,content,date,sticky,category_id) VALUES('$_SESSION[urbex_user_id]','$title','$content',NOW(),'0','$_GET[cat_id]')");

					}else{

						echo "<p>Could not process post: Please make sure the content is atleast 10 characters!</p>";
					}

				}else{

					echo "<p>Could not process post: Please make sure the title is atleast 6 characters!</p>";
				}
			}


 

When I use both $cat_id or just $_GET['cat_id'] both submit 0 into the cell in the database table.

When I echo both out on the page the both echo the correct category name.

Link to comment
Share on other sites

For the time being, echo any errors, and some debugging info and see what it shows, if anything.

 

$cat_id = $_GET['cat_id'];
if(isset($submit) && ($title != 'Title') && strlen($title)>5) {
if(!empty($title) ) {
	if( !empty($content) && ($content != 'Enter your post content here..') && strlen($content)>9 ) {
		$query = "INSERT INTO urbex_forum_posts (user_id,title,content,date,sticky,category_id) VALUES('$_SESSION[urbex_user_id]','$title','$content',NOW(),'0','$_GET[cat_id]')";
		if( $result = mysql_query($query) ) {
			if( mysql_affected_rows($result) !== 1 ) {
				echo "<br>Query executed without inserting record.<br>Query string: $query<br>";
			}
		} else {
			echo "<br>Query: $query<br>Failed with error: " . mysql_error() . '<br>';
		}
	} else {
		echo "<p>Could not process post: Please make sure the content is atleast 10 characters!</p>";
	}
} else {
	echo "<p>Could not process post: Please make sure the title is atleast 6 characters!</p>";
}
}

Link to comment
Share on other sites

 

Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in //create_forum_post.php on line 90

 

Query executed without inserting record.

Query string: INSERT INTO urbex_forum_posts (user_id,title,content,date,sticky,category_id) VALUES('14','llllllllllllllllllllll','llllllllllllllllllllllllllllllllllll',NOW(),'0','')

 

Link to comment
Share on other sites

It is just  the single form. the cat_id is passed to the page in the url which i was trying to input directly using GET in the mysql_query which wouldnt work, I also tried putting the cat_id in a variable first but nada.

 

Ive changed it to using a hidden input field with the cat_id echoed into its value which works fine, but would have rather not done that.

Link to comment
Share on other sites

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.