Jump to content

getting variable value from one page to another...


pjc2003

Recommended Posts

Hi,

How can i get a value of variable part_number from one page to another.. This is what I have tried..



From the first page I created a link that goes to stock_control page and sends the part number value


<a class='LinkText' href='stock_control.php?part_number=<?php echo $part_number?>'>Edit Item</a>


but now im on the stock_control.php  page how can I access the variable again!???


many thanks...
$_GET['$part_number'] to access it, also you have a bogus ? in that line, use this:

[code]
<a class='LinkText' href='stock_control.php?part_number=<?php echo $part_number>'>Edit Item</a>
[/code]



edit, got post and get mixed up :(
as you have included it in the URL it becomes a $_GET variable so for your code you would neede to type on your new page

[code]
<?php

$part_number = $_GET['part_number'];

echo $part_number; //would output the url value of part_number

?>
[/code]

ok my stock_control page looks like this now but its still not comparing the value of part_number to the database value:

<?php
require('./header.php');
require('./dbconn.php');




$action = 'show_form';
if(!empty($_POST)) {
$action= 'process_data';
$part_number = $_GET['part_number'];

}




if($action== 'process_data')  {

$location_name = trim($_POST['location']);
$valid = intval(trim($_POST['valid']));

$sql= "UPDATE stockdata ( location , valid)  " .
"VALUES ('$location_name', '$valid' )
WHERE  part_number=$part_number ";
$ok= mysql_query($sql);

if($ok){
echo "<p class='ErrorText'>Update OK!</p>";

}
else
{
echo "<p class ='ErrorText'>Update Failed!</p>";
}
}
else {
$action = 'show_form';
}

echo $sql;   

//end running database query


if($action == 'show_form')  {
?>



<form method="post" action="stock_control.php">
  <p class ='MainText'>
  Change Location -
      <select name="location">
      <option =1 <?php if ($location_name ="A") echo ' selected '?> >A</option>
      <option =2 <?php if ($location_name ="B") echo ' selected '?> >B</option>
  <option =3 <?php if ($location_name ="C") echo ' selected '?> >C</option>
      <option =4 <?php if ($location_name ="D") echo ' selected '?> >D</option>
  <option =5 <?php if ($location_name ="E") echo ' selected '?> >E</option>
      <option =6 <?php if ($location_name ="F") echo ' selected '?> >F</option>
  <option =7 <?php if ($location_name ="G") echo ' selected '?> >G</option>
      <option =8 <?php if ($location_name ="H") echo ' selected '?> >H</option>
  <option =9 <?php if ($location_name ="I") echo ' selected '?> >I</option>
      <option =10 <?php if ($location_name ="J") echo ' selected '?> >J</option>
  <option =11 <?php if ($location_name ="K") echo ' selected '?> >K</option>
      <option =12 <?php if ($location_name ="L") echo ' selected '?> >L</option>
  <option =13 <?php if ($location_name ="M") echo ' selected '?> >M</option>
      <option =14 <?php if ($location_name ="N") echo ' selected '?> >N</option>
  <option =15 <?php if ($location_name ="O") echo ' selected '?> >O</option>
      <option =16 <?php if ($location_name ="P") echo ' selected '?> >P</option>
  <option =17 <?php if ($location_name ="Q") echo ' selected '?> >Q</option>
      <option =18 <?php if ($location_name ="R") echo ' selected '?> >R</option>
  <option =19 <?php if ($location_name ="S") echo ' selected '?> >S</option>
      <option =20 <?php if ($location_name ="T") echo ' selected '?> >T</option>
  <option =21 <?php if ($location_name ="U") echo ' selected '?> >U</option>
      <option =22 <?php if ($location_name ="V") echo ' selected '?> >V</option>
  <option =23 <?php if ($location_name ="W") echo ' selected '?> >W</option>
      <option =24 <?php if ($location_name ="X") echo ' selected '?> >X</option>
  <option =25 <?php if ($location_name ="Y") echo ' selected '?> >Y</option>
      <option =26 <?php if ($location_name ="Z") echo ' selected '?> >Z</option>
    </select>
</p>
  <p class ='MainText'>
    Change Validity-
      <select name="valid">
      <option =1 <?php if ($valid =0) echo ' selected '?> > 0</option>
      <option =2 <?php if ($valid =1) echo ' selected '?> > 1</option>
    </select>
</p>
  <input type="submit" value="save"/>
  </p>
</form> 
<?php
}
require('./footer.php');
?>



Any Ideas??

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.