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
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);

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.