TomGrooby Posted August 25, 2009 Share Posted August 25, 2009 $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. Link to comment https://forums.phpfreaks.com/topic/171855-solved-mysql-select-returns-0/ Share on other sites More sharing options...
mikesta707 Posted August 25, 2009 Share Posted August 25, 2009 read your question wrong. nevermind ig got it. Link to comment https://forums.phpfreaks.com/topic/171855-solved-mysql-select-returns-0/#findComment-906147 Share on other sites More sharing options...
ignace Posted August 25, 2009 Share Posted August 25, 2009 $query = mysql_query("SELECT id FROM users WHERE username='$cookieuser'") or die(mysql_error()); list($authorid) = mysql_fetch_array($query, MYSQL_NUM); Link to comment https://forums.phpfreaks.com/topic/171855-solved-mysql-select-returns-0/#findComment-906149 Share on other sites More sharing options...
TomGrooby Posted August 25, 2009 Author Share Posted August 25, 2009 $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 https://forums.phpfreaks.com/topic/171855-solved-mysql-select-returns-0/#findComment-906161 Share on other sites More sharing options...
ignace Posted August 25, 2009 Share Posted August 25, 2009 $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 https://forums.phpfreaks.com/topic/171855-solved-mysql-select-returns-0/#findComment-906181 Share on other sites More sharing options...
TomGrooby Posted August 25, 2009 Author Share Posted August 25, 2009 I solved it. It was an error in one of my variables your code works. thank you. Link to comment https://forums.phpfreaks.com/topic/171855-solved-mysql-select-returns-0/#findComment-906186 Share on other sites More sharing options...
Maq Posted August 25, 2009 Share Posted August 25, 2009 I solved it. It was an error in one of my variables your code works. thank you. Then please mark as so. Link to comment https://forums.phpfreaks.com/topic/171855-solved-mysql-select-returns-0/#findComment-906191 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.