Jump to content

Wrong Info sent Using $get in form


LearningKid

Recommended Posts

Hi i have this code that i tried to make to send some info from one page to aother with lots of ppls hlp and it works ok but when i have multiple files it doesnt send the correct info.

What im tryin to get is the Num_Pages to another page it works fine if its just one file in the db but when its multiple and i select a file in the middle of the table or somewhere else i dont get tht info i get the last file info.

Can anyone help if I didnt confuse u?

Thank You

<?php
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$sql = "SELECT * FROM files where username = '".$_SESSION['myusername']."' ORDER BY id ASC ";
//$sql = "ORDER BY id ASC";
$result = mysql_query($sql);
$rows = mysql_num_rows($result);


echo "<form method='POST' action='count.php'><table border='2px'>\n";
echo " <tr>\n";
echo "  <td align='center'>Date Added</td>\n";
echo "  <td align='center'>Files</td>\n";
echo "  <td align='center'>Number of Pages</td>\n";
echo "  <td align='center'>Prepare To Print</td>\n";
echo "  <td> </td>\n";
echo " </tr>\n";

for ($i = 0; $i < $rows; $i++) {
  $data = mysql_fetch_object($result);
  // since our script is very small, i'm not going to escape out to html mode here
  echo " <tr>\n";
  echo "  <td>$data->Date</td>\n";
  echo "  <td>$data->File_Name</td>\n";
  echo "  <td align='center'><input name='pages' type='hidden' value='$data->Num_Pages'>$data->Num_Pages</td>\n";
  echo "  <td align='center'>
          <input type='submit' value='Edit' name='editbutton'></form></td>";
  echo "  </tr>\n";
}

?>

Link to comment
https://forums.phpfreaks.com/topic/185879-wrong-info-sent-using-get-in-form/
Share on other sites

Hello,

 

The thing is you have one form for all "edit" submit buttons. So what will happen is it will submit the "last" Num_Pages entry instead of the one you want.

 

What I suggest is removing the "form" from the script and adding a textual link like so.

 

echo "<a href=\"count.php?pages=".$data->Num_Pages."\">Edit ".$data->Num_Pages."</a>";

 

the above would replace

<input type='submit' value='Edit' name='editbutton'></form>

 

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.