1

In my buyBook.php I have a form that when it is submitted it will go to check_buy.php that will do the process of inserting. This is what I have in the buyBook.php

<div class="form-group" style="width:1px;width:1px;">
    <input type="hidden" name="user_id" value="<?php echo $_SESSION['user_id']?>" />
</div>

And this is what I have in the check_buy.php

    $user_id = $_SESSION['user_id'];
.
.
.

    $ins = mysql_query("INSERT INTO `librarydb`.`buy` (`user_id`) VALUES ('$user_id');");

Why it isn't inserting? I tried referencing what it is in here PHP $_SESSION error when posting to the database but still no luck.

6
  • 1
    You're using session_start() somewhere? Commented Mar 2, 2015 at 16:03
  • 1
    If this field is inside a <form> tag, why aren't you use $_POST['user_id'] or $_GET['user_id'] instead of $_SESSION['user_id']; inside check_buy.php? Commented Mar 2, 2015 at 16:05
  • You @Abra are one hell of a magician! Thanks! I didn't think of it man. Commented Mar 2, 2015 at 16:07
  • @bcesars, can i just remove the supposed to be session that will pass to check_buy.php? and just start adding via session_start()? Commented Mar 2, 2015 at 16:08
  • @WTFZane, of course you can use session_start(). But this input hidden field will be useless for you. You can remove it as well. Commented Mar 2, 2015 at 16:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.