Jump to content

[SOLVED] Passing Hidden Varaible help..


Siggles

Recommended Posts

Any ideas why this doesn't work...

 

$result3 = mysql_query("SELECT dateplayed, opponent, homeaway, id FROM fixtures WHERE id NOT IN (SELECT id FROM predictions WHERE username = '$session->username') AND NOW() < dateplayed ORDER BY dateplayed DESC");

while($row = mysql_fetch_array($result3))

  {

echo "<tr><td>".date('d/m/y',strtotime($row['dateplayed']))."</td>";

echo "<td>".date('G:ia',strtotime($row['dateplayed']))."</td>";

echo "<td align=\"center\">(".$row['homeaway'].")</td>";

echo "<td>".$row['opponent']."</td>";

$cid=$row['id'];

echo "<td>";

?>

<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post">

<input type="text" name="resultmfc" size="1"></td><td>

<input type="text" name="resultother" size="1"></td>

<td>

<input type="submit" name="submit" value="Add!"></td>

<input type="hidden" name="opt" value="addprediction" />

<input type="hidden" name="id" value="<? $cid  ?>">

</form>

 

<?

echo "</tr>";

}

echo "</table>";

}

 

?>

 

then later on

 

<?

//NEED ID, USERNAME, RESULTMFC, RESULTOTHER

//SQL FOR ADDING PREDICTION FOR EXISTING FIXTURE

switch($_POST['opt']) {

case "addprediction":

 

$pid=$_POST['id'];

$pusername=$session->username;

$presultmfc=$_POST['resultmfc'];

$presultother=$_POST['resultother'];

mysql_query("INSERT INTO predictions (username, id, resultmfc, resultother) VALUES ('$pusername', '$pid', '$presultmfc', '$presultother')");

echo "<table align=\"center\" style=\"border:#666666 dashed 1px\">

<tr><td>Prediction inserted successfully!</td></tr></table>";

break;

}

?>

 

Everything is passed and inserted into the dbase other than the id?

Link to comment
https://forums.phpfreaks.com/topic/89926-solved-passing-hidden-varaible-help/
Share on other sites

Change:

 

<input type="hidden" name="id" value="<? $cid  ?>">

 

 

To this:

 

<input type="hidden" name="id" value="<? echo $cid;  ?>">

 

or short notation (depending on server setting allowing it):

 

<input type="hidden" name="id" value="<?= $cid  ?>">

 

A handy utility to see what variables are you POST'ing is the print_r() function.

e.g.

echo "<pre>";
print_r($_POST);
echo "</pre>";

 

This way you can see ALL the POST variables that are being passed to the page in question and have them printed out in a nice format for you to see while debugging.

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.