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
https://forums.phpfreaks.com/topic/171855-solved-mysql-select-returns-0/
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.

$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.

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.