Jump to content

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.

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>";
}
}

 

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','')

 

Oh, duh. Remove $result from the call to mysql_affected_rows() . . .

 

At any rate, it doesn't appear $_GET['cat_id'] has a value at that point in the script for some reason. Now the thing is to figure out why that's the case.

If you're submitting the form multiple times and the data is getting lost at that point, using a hidden field can work. You could also use a $_SESSION var, and unset it after the query executes successfully if needed.

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.

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.