Jump to content

[SOLVED] Mysql SELECT returns 0


TomGrooby

Recommended Posts


					$authorid = mysql_query("SELECT id FROM users WHERE username='$cookieuser'") or die(mysql_error());


						$category = $_GET['cat'];
						$date = date("j F Y");
						$title = $_POST['title'];
						$topicbody = addslashes(strip_tags($_POST['topicbody']));
						$image = $_POST['group1'];


					$querytopic = mysql_query("

					INSERT INTO topics VALUES ('', '$authorid', '$date', '$title', '$topicbody', '$category', '$image')						
					");

					echo "Topic sucessfully created.. Click <a href=\"category.php?cat=".$category."\">here</a> to view.";

 

 

I am using the code above as part of a simple post and reply forum that I am building for my site.

This part is inserting data from a form into a database to make a new topic. The script works for every variable apart from $authorid. It inserts 0 for every user. I have tried using mysql_fetch_assoc in a loop but then I cant insert the data aswell.

 

I am really confused here, all help will be appreciated.  :confused:

Link to comment
Share on other sites

$query = mysql_query("SELECT id FROM users WHERE username='$cookieuser'") or die(mysql_error());

list($authorid) = mysql_fetch_array($query, MYSQL_NUM);

 

that doesn't work either. It just inserts 0 when it should be 1.  :(

 

 

EDIT: IF I ECHO OUT THE $AUTHORID IT GIVES A RESOURCE ID.

Link to comment
Share on other sites

$query = mysql_query("SELECT id FROM users WHERE username='$cookieuser'") or die(mysql_error());

list($authorid) = mysql_fetch_array($query, MYSQL_NUM);

 

that doesn't work either. It just inserts 0 when it should be 1.  :(

 

 

EDIT: IF I ECHO OUT THE $AUTHORID IT GIVES A RESOURCE ID.

 

Then you are not using my code.

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.