passing variable through url problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

passing variable through url problem

Post by aceconcepts »

Hi,

When I pass a value through the url from an extracted set of data from a mysql db, the first record's value is passed even when i select other records.

Here is the code i use to pass the value:

Code: Select all

<?php 
 while ($row = mysql_fetch_array($result)) {
	extract($row);
  echo "<form name=\"form1\" method=\"post\" action=\"order_summary.php?getdel=$del_id\">";
  echo "<tr bgcolor=\"#CAE0EE\"><td><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">";
  echo $del_destination;
  echo "</font></td>";
  echo "<td align=\"center\"><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">";
  echo $del_duration;
  echo "</td></font>";
  echo "<td align=\"center\"><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">";
  echo $del_price;
  echo "</td>";
  echo "<td align=\"center\">";
?>
    <input type="radio" name="radiobutton" value="radiobutton">
  <?php
  }
  ?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

why are you creating a form in a loop but not ending it in the same iteration?
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Post by aceconcepts »

Sorry.

Here is the entire page of code:

Code: Select all

<?php
//include "auth.inc.php";
//include "b2b_header.php";
//CONNECT TO SERVER AND DATABASE
session_start();
include "conn.inc.php";

$query = "SELECT * FROM delivery" ;

$result = mysql_query($query)
	or die(mysql_error());
?>
<html>
<body>
<table width="600" border="0">
  <tr bgcolor="#0099CC">
    <td width="414"><strong><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">Destination</font></strong></td>
    <td width="103"> 
      <div align="center"><font color="#FFFFFF"><strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Duration</font></strong></font></div></td>
    <td width="103"> 
      <div align="center"><font color="#FFFFFF"><strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Price</font></strong></font></div></td>
    <td width="83"></td>
  </tr>
  <?php 
 while ($row = mysql_fetch_array($result)) {
	extract($row);
  echo "<form name=\"form1\" method=\"post\" action=\"order_summary.php?getdel=$del_id\">";
  echo "<tr bgcolor=\"#CAE0EE\"><td><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">";
  echo $del_destination;
  echo "</font></td>";
  echo "<td align=\"center\"><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">";
  echo $del_duration;
  echo "</td></font>";
  echo "<td align=\"center\"><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">";
  echo $del_price;
  echo "</td>";
  echo "<td align=\"center\">";
?>
    <input type="radio" name="radiobutton" value="radiobutton">
  <?php
  }
  ?>
<tr><td height="25"></td></tr>
<tr><td colspan="4" align="right">
<input type="submit" name="submit" value="Proceed to checkout">
</td></tr>
</form>
</table>
</body>
</html>
I want to have a button at the bottom.
sikelsh
Forum Newbie
Posts: 8
Joined: Thu Mar 23, 2006 4:20 am

Post by sikelsh »

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I think its becuase you havent done the MySQL correct, your just telling it to get all rows, not specific ones, then when you come use the Row function lower down, it just gets the first row, as it doesnt know what else to do, 

Try something like

NOTE > Im assuming the variable passed is [b]$del_id[/b] using the POST method and not GET, and that your field name is [b]del_id[/b]

Code: Select all

<?php 
//include "auth.inc.php"; 
//include "b2b_header.php"; 
//CONNECT TO SERVER AND DATABASE 
session_start(); 
include "conn.inc.php"; 

$del_id = $_POST["del_id"];

$result  = mysql_query("SELECT * FROM delivery WHERE del_id = '$del_id'");

?> 
<html> 
<body> 
<table width="600" border="0"> 
  <tr bgcolor="#0099CC"> 
    <td width="414"><strong><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">Destination</font></strong></td> 
    <td width="103">  
      <div align="center"><font color="#FFFFFF"><strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Duration</font></strong></font></div></td> 
    <td width="103">  
      <div align="center"><font color="#FFFFFF"><strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Price</font></strong></font></div></td> 
    <td width="83"></td> 
  </tr> 
  <?php  
 while ($row = mysql_fetch_array($result)) { 
    extract($row); 
  echo "<form name=\"form1\" method=\"post\" action=\"order_summary.php?getdel=$del_id\">"; 
  echo "<tr bgcolor=\"#CAE0EE\"><td><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">"; 
  echo $del_destination; 
  echo "</font></td>"; 
  echo "<td align=\"center\"><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">"; 
  echo $del_duration; 
  echo "</td></font>"; 
  echo "<td align=\"center\"><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">"; 
  echo $del_price; 
  echo "</td>"; 
  echo "<td align=\"center\">"; 
?> 
    <input type="radio" name="radiobutton" value="radiobutton"> 
  <?php 
  } 
  ?> 
<tr><td height="25"></td></tr> 
<tr><td colspan="4" align="right"> 
<input type="submit" name="submit" value="Proceed to checkout"> 
</td></tr> 
</form> 
</table> 
</body> 
</html>

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

creating a form in each loop iteration is what's really killing it, like I hinted at before.

Code: Select all

<?php
//include "auth.inc.php";
//include "b2b_header.php";
//CONNECT TO SERVER AND DATABASE
session_start();
include "conn.inc.php";

$query = "SELECT * FROM delivery" ;

$result = mysql_query($query)
    or die(mysql_error());
?>
<html>
<body>
<form method="post" action="order_summary.php">
<table width="600" border="0">
  <tr bgcolor="#0099CC">
    <td width="414"><strong><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">Destination</font></strong></td>
    <td width="103"> 
      <div align="center"><font color="#FFFFFF"><strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Duration</font></strong></font></div></td>
    <td width="103"> 
      <div align="center"><font color="#FFFFFF"><strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Price</font></strong></font></div></td>
    <td width="83"></td>
  </tr>
  <?php 
 while ($row = mysql_fetch_array($result)) {
    extract($row);
  echo "<tr bgcolor=\"#CAE0EE\"><td><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">";
  echo $del_destination;
  echo "</font></td>";
  echo "<td align=\"center\"><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">";
  echo $del_duration;
  echo "</td></font>";
  echo "<td align=\"center\"><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">";
  echo $del_price;
  echo "</td>";
  echo "<td align=\"center\">";
  echo "    <input type=\"radio\" name=\"getdel\" value=\"$del_id\">";
  }
  ?>
<tr><td height="25"></td></tr>
<tr><td colspan="4" align="right">
<input type="submit" name="submit" value="Proceed to checkout">
</td></tr>
</table>
</form>
</body>
</html>
Post Reply