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())" ); Quote Link to comment 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); Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Psycho Posted March 10, 2011 Share Posted March 10, 2011 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.