Jump to content

Inserting a variable into a database


Stealthrelentless

Recommended Posts

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

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

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.

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.