Jump to content

Hit Submit Loses Variable


richo89

Recommended Posts

Hi,

 

I have a page which sends the variable via the URL to the nextpage which in this case is listPlate.php

 

The code to pass the variable is

echo "<p><a href='listPlate.php?Customer_ID=$customerid'>Click here to start selling! </a></p>";

 

On listPlate.php I have the following code:

 

<? 
//initilize PHP

if($_POST['submit']) //If submit is hit
{
$plate = $_POST[plate];
$keywords = $_POST[keywords];
$category = $_POST[category];
$notes = $_POST[notes];
$cost = $_POST[cost];
$id = $_GET['Customer_ID'];

$plate1st = $plate{0};
$plate2nd = $plate{1};
$plate3rd = $plate{3};
$plate4th = $plate{4};
$plate5th = $plate{5};


   //Insert the values into the correct database with the right fields
   //mysql table = purchases
  $sql=("INSERT INTO prefix (Customer_ID, plate, keywords, category, notes, cost, plate1st, plate2nd, plate3rd, plate4th, plate5th)".
      "VALUES ('$id','$plate','$keywords','$category','$notes','$cost','$plate1st', '$plate2nd', '$plate3rd', '$plate4th', '$plate5th')");
  
$result = mysql_query($sql) or die (mysql_error());

echo "<font color='black'>$plate submitted succesfully,  $id is customer id</font>";

}

?> 

 

However, once I click submit it enters the Customer_ID as blank into my database and for some reason is forgetting what the variable is.

 

When i'm on listPlate.php the URL clearly shows the Customer_ID.. Example.. listPlate.php?Customer_ID=5

 

Any ideas?

Link to comment
Share on other sites

you'll have to do a hidden field with your customerid. When you post you're not passing through the URL so you're losing your variable.

<input type='hidden' name='customerid' value='".$_GET['Customer_ID']."'>

then you'll have $_POST['customerid'] available on the page you posted to.

 

I have the following:

<form action="listPlate.php" method="POST">
<input type='hidden' name='customerid' value='".$_GET['Customer_ID']."'>

 

However, when I echo whats been submitted I get the following:

 

Z2 ZZZ submitted succesfully, \".$_GET[ is customer id

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.