sw9 Posted April 24, 2007 Share Posted April 24, 2007 Hi All, So I've got a page that runs a mysql update query based on a drop down select box. But for some reason, I can't access the GET variable called id in this statement (when I do a die statement it is empty where the variable should be). I am sure this is a noobie thing, so i am hoping someone can help me on this easily. I can access the $_GET["id"] variable everywhere else in my page, but not here. if( $listAction && ( $listAction == "pending" ) ){ // listAction relates to the select box action that actually calls this mysql query $first = true; $date = date("Y-m-d"); $update_sql = "UPDATE prog_proposal SET active = '0', active_date = '".$date."' WHERE pp_id = \"".$_GET["id"]."\""; // die($update_sql); $res = mysql_db_query(DB_NAME, $update_sql) || $sql_error .= mysql_error() . "<hr><pre>". $update_sql."</pre>"; header ( "location: ".$_SERVER['HTTP_REFERER'] ); } Help would be greatly appreciated. Thanks! Link to comment https://forums.phpfreaks.com/topic/48527-why-cant-i-access-the-get-variable-help/ Share on other sites More sharing options...
Barand Posted April 24, 2007 Share Posted April 24, 2007 Is $listAction being set anywhere? If it isn't then none of that code executes. Link to comment https://forums.phpfreaks.com/topic/48527-why-cant-i-access-the-get-variable-help/#findComment-237420 Share on other sites More sharing options...
shaunrigby Posted April 24, 2007 Share Posted April 24, 2007 Are you passing the ID via URL? or via a form? URL = $_GET Form = form method $_GET/$_POST also, try $_GET[i'd'] Link to comment https://forums.phpfreaks.com/topic/48527-why-cant-i-access-the-get-variable-help/#findComment-237421 Share on other sites More sharing options...
sw9 Posted April 24, 2007 Author Share Posted April 24, 2007 So listaction is based on a select box named resultsAction. And I am using $_GET variable because the URL looks like this http://mysite.com/proposal_detail.php?id=238 or some other number. I am including a bigger snippet of code here so that you can get the bigger picture. Thanks! <?php $listAction = ( isset( $_POST["resultsAction"] ) && $_POST["resultsAction"] != "" )?$_POST["resultsAction"]:false; // parse session cache $cache = explode( "|", $_SESSION["cacheData"] ); $cacheSize = sizeof($cache); if( isset( $_GET["id"] ) ){ $currentIndex = array_search($_GET["id"], $cache); }else{ $currentIndex = 0; $_GET["id"] = $cache[0]; } $current_id = $_GET["id"]; $prev_id = isset( $cache[$currentIndex - 1] )?$cache[$currentIndex - 1]:false; $next_id = isset( $cache[$currentIndex + 1] )?$cache[$currentIndex + 1]:false; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>RETN Internal Database: Program Proposal Details</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link href="css/style.css" rel="stylesheet" type="text/css"> <script language="javascript"> window.resizeTo(600, 750); function doRadio( obj ){ var frm = obj.form; var val = obj.value; // alert( val ); if( val == "reset" ){ frm.reset(); } else{ frm.submit(); } } function checkField( id ){ if( document.getElementById && document.getElementById(id) ){ obj = document.getElementById(id); if( obj.checked ){ obj.checked = false; } else{ obj.checked = true; } } } </script> <?php $radioAction = 'onClick="doRadio(this);"'; if( $listAction && ( $listAction == "pending" ) ){ $first = true; $date = date("Y-m-d"); $update_sql = "UPDATE prog_proposal SET active = '0', active_date = '".$date."' WHERE pp_id = \"".$_GET["id"]."\""; $sql_error = ""; // Act as a flag. We could use true|false but I also want it to make a list of all statements // that fail to help facilitate debugging. $res = mysql_db_query(DB_NAME, $update_sql) || $sql_error .= mysql_error() . "<hr><pre>". $update_sql."</pre>"; header ( "location: ".$_SERVER['HTTP_REFERER'] ); } </head> <body> <?php // $id = $_GET["id"] ; $sql = "SELECT a.*, c.user_id, c.fname, c.lname, c.street, c.street2, c.city, c.state, c.zip, c.email, c.phone, b.* FROM prog_proposal AS a LEFT JOIN user AS c ON (a.user_id = c.user_id) LEFT JOIN pp_series AS b ON (a.series_id = b.series_id) WHERE a.user_id = c.user_id AND a.pp_id ='".$current_id."'"; // die($sql); $rval = mysql_query( $sql ); $data = mysql_fetch_assoc( $rval ) ; $bgColor = $row % 2 == 0?"#CBC497":"#E4DFC6"; $_SESSION["user_id"] = $data["user_id"]; $_SESSION["series_id"] = $data["series_id"]; $_SESSION["pp_id"] = $data["pp_id"]; // echo $_SESSION["user_id"]."UserID"; // echo "seriesid = " .$_SESSION["series_id"]; ?> <!-- Session data: <?php echo $_SESSION["cacheData"]; ?> <hr> --> <table> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" id="pp_process"> <input type="hidden" name="id" id="id" value="<?=$current_id?>"> <tr> <td align="left" width="5%" valign="top" class="textbold"><span class="textbold">Records Found: <?php echo " " . $currentIndex+1; ?>/<?php echo $cacheSize; ?> </span> </td> </tr> <tr> <td class="textbold"> <?php if( $prev_id ){ ?> <button class="textbold" type="button" onclick="document.location='<?php echo $_SERVER['PHP_SELF']."?id=".$prev_id; ?>'">« Prev</button> <?php }else{ ?> <button class="textbold" type="button" disabled="disabled">« Prev</button> <?php } ?> <?php if( $next_id ){ ?> <button class="textbold" type="button" onclick="document.location='<?php echo $_SERVER['PHP_SELF']."?id=".$next_id; ?>'">Next »</button> <?php }else{ ?> <button type="button" class="textbold" disabled="disabled">Next »</button> <?php } ?> </td> <td class="archive"><?php $m = $_GET["m"]; if($m=='1'){echo "You have successfully added the program proposal shown below. A confirmation email has been sent to the producer.";}?></td> </tr> </table> <table width="100%"><tr class="textbold"><td align="center" class="textbold"> <hr> <?php // HERE IS WHERE THE RESULTS ACTION IS SET THAT CORRESPONDS TO $listAction?> <select name="resultsAction" id="resultsAction"> <option value="">------ SELECT ACTION HERE ------</option> <option value="approve" <?php echo $radioAction; ?>>Approve</option> <option value="pending" <?php echo $radioAction; ?>>Set to Pending</option> <option value="reject" <?php echo $radioAction; ?>>Reject</option> <option value="" >===================</option> <option value="reply" <?php echo $radioAction; ?>>Set Response to Sent</option> <option value="print" <?php echo $radioAction; ?>>Printer-Friendly Version</option> <option value="" >===================</option> <option value="seriesedit" <?php echo $radioAction; ?>>EDIT Selected Series Information</option> <option value="showedit" <?php echo $radioAction; ?>>EDIT Selected Program Information</option> <option value="showadd" <?php echo $radioAction; ?>>ADD Program to Selected Series</option> </select></table><br> <table cellpadding="2" cellspacing="3" width="100%"> <tr> <td class="textbold">Proposal ID:</td><td class="text"><?=$current_id;?></td></tr> <tr><td class="textbold">Status:</td><?php if( $data["active"] == '0' && $data["active_date"] != null ) { echo '<td class="archive">Pending' . ' on ' . retn_date($data["active_date"]); }elseif( $data["active"] == '0' && $data["active_date"] == null ) { echo '<td class="archive">Pending'; }elseif( $data["active"] == '1' ) { echo '<td class="textbold">Approved' . ' on ' . retn_date($data["active_date"]); }elseif( $data["active"] == '2' ) { echo '<td class="textbold" style="color:#3A4EAD">Rejected' . ' on ' . retn_date($data["active_date"]); } ?></td></tr> </table> <br><br> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/48527-why-cant-i-access-the-get-variable-help/#findComment-237442 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.