Jump to content

Can't pull my $_GET['id'] into my if($_POST['submit']) sql INSERT


tysty7

Recommended Posts

Hi all!  I'm new to PHP but really enjoying it! I have this one issue i can't seem to figure out tho. When i get to this page, of which i included a snippet below, the GET['id'] holds a value, but if the value becomes erased when i try to use it in the POST-submit SQL Insert statement. I can't figure out how to get that value into the INSERT ->VALUES.

 

help??

 

 

<?php

 

session_start();

 

$secretID = $_GET['id'];

// echo secretID; // returns a correct value here

 

if (isset($_SESSION['id'])) {

 

if ($_POST['submit']) {

 

                $sql = "INSERT INTO comments (secretID, comment_body, dateAdded)

VALUES ( '$secretID', '$_POST[comment_body]', NOW())";

 

// echo secretID; // returns no value at all here

Hi,

 

Without the rest of the code it is hard but I would say that if the second string is not echoed the if statement may not be being satisfied.

 

To test this add echo 'Hello'; or something similar just after eac hconditional statement and see what you do / do not see. Then, try to echo the conditions (i.e $_SESSION['id'] etc). Plus, you could use session_is_registered('id') instead here.

 

Also, watch that you do not have standard variables named the same as session variables because this can cause problems.

 

Martin

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.