Stealthrelentless Posted March 10, 2011 Share Posted March 10, 2011 Hey all Im working on an assignment for school and currently I am trying to inser the variable $uid which currently = 2.. But for someone reason when the post happens it inserts a 0 instead of a 2. Here is my insert mysql_query( "INSERT INTO blog_posts (title, post, author_id, date_posted) ". "VALUES ('$btitle', '$bpost', '$uid', CURDATE())" ); Link to comment https://forums.phpfreaks.com/topic/230151-inserting-a-variable-into-a-database/ Share on other sites More sharing options...
Psycho Posted March 10, 2011 Share Posted March 10, 2011 How do you know it = 2??? Where is the code that sets the value? You shouldn't build your queries in the mysql_query() statement as it makes it difficult to debug. Create the query as a string so you can echo it to the page when there are problems. $query = "INSERT INTO `blog_posts` (`title`, `post`, `author_id`, `date_posted`) VALUES ('$btitle', '$bpost', '$uid', CURDATE())"; //Debug code echo $query; $result = mysql_query($query); Link to comment https://forums.phpfreaks.com/topic/230151-inserting-a-variable-into-a-database/#findComment-1185264 Share on other sites More sharing options...
Stealthrelentless Posted March 10, 2011 Author Share Posted March 10, 2011 Thank; I actually figured it out.. My declaration of it was below the insert. all i had to do is move it above the insert and whala it works. I was echoing the $uid to see that it was 2. so that was not the problem. Link to comment https://forums.phpfreaks.com/topic/230151-inserting-a-variable-into-a-database/#findComment-1185265 Share on other sites More sharing options...
Psycho Posted March 10, 2011 Share Posted March 10, 2011 Quote I was echoing the $uid to see that it was 2. so that was not the problem. Yeah, but you weren't echoing the QUERY. Had you done that you would have realized that $uid was not set at the time the query was created and you would have resolved your problem much quicker. Link to comment https://forums.phpfreaks.com/topic/230151-inserting-a-variable-into-a-database/#findComment-1185697 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.