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
https://forums.phpfreaks.com/topic/169906-hit-submit-loses-variable/
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.

 

 

 

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

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.