• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 185
  • Last Modified:

query after update

Hi,

The update works fine. However the REC_NO is null trying to do an query after the update.

The only way I can get it to work is to hardcode the $REC_NO.


Any suggestions to this problem ?

Thanks


<?

// Make a MySQL Connection
mysql_connect("xx", "xx", "xx") or die(mysql_error());
mysql_select_db("design") or die(mysql_error());



if( isset($_POST["H_IL_FILM_AOI"]) ) {
   $set_part = 'SET H_IL_FILM_AOI_STAMP = NOW()';
   $stamp = " H_IL_FILM_AOI = 'yes'";
   

     }
else {
   $set_part = 'SET R_IL_FILM_AOI_STAMP = NOW()';
   $stamp = " H_IL_FILM_AOI = 'no'";
     }

//$REC_NO = 90;  //works
//$REC_NO = $_POST['REC_NO']; // no go
//$REC_NO = $_GET['REC_NO']; // no go
//$REC_NO = $_REQUEST['REC_NO']; //no go
//$xx = $_GET['REC_NO'];  //no go


mysql_query("UPDATE PROJECT $set_part, $stamp WHERE REC_NO = REC_NO") or die("Upate error : " . mysql_error());


$query= "select * from PROJECT WHERE REC_NO = $REC_NO";
echo $query;

?>

QUERY OUTPUT select * from PROJECT WHERE REC_NO=$REC_NO
0
jjcheap1
Asked:
jjcheap1
  • 2
  • 2
  • 2
  • +1
1 Solution
 
alberthendriksCommented:
Can you give us the code of the page that submits the REC_NO?
0
 
jjcheap1Author Commented:
<?php

// Connecting, selecting database
mysql_connect("xx", "xx", "Pxx") or die(mysql_error());
mysql_select_db("design") or die(mysql_error());
//echo 'Connected successfully';
mysql_select_db('design') or die('Could not select database');

// Performing SQL query
// debug mode
//$query = 'SELECT * FROM `PROJECT` where REC_NO=89';
$query = "select * from PROJECT where REC_NO='".$_GET['REC_NO']."'";
//run mode
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

$num=mysql_num_rows($result);
$i=0;

// Count rows in database and assign variables to results

while ($i < $num) {
$REC_NO=mysql_result($result,$i,"REC_NO");
$CI_PART_NO=mysql_result($result,$i,"CI_PART_NO");
$FILE_NUMBER=mysql_result($result,$i,"FILE_NUMBER");
$RECEIVED_DATE=mysql_result($result,$i,"RECEIVED_DATE");
$H_IL_FILM_AOI=mysql_result($result,$i,"H_IL_FILM_AOI");
++$i;
}
?>


<title> Change AOI FILM HOLD... Design Services </title>
<form name="c1" method="post" action="11.php?$_GET['REC_NO']">
<h2>You are updating CI Part Number&nbsp;  <?=$CI_PART_NO?></h2>
<p>
<b>Is  Film on hold?&nbsp;&nbsp;&nbsp; <?=$H_IL_FILM_AOI?></b>
<p>
<B>If you want to place IL FILM on hold check box and click Change ! </b>
<p>
<b>If you want to release IL FILM hold click Change!</b>
<p>
<input type="checkbox" name="H_IL_FILM_AOI" onclick="checkDate(this.checked, '<?=$H_IL_FILM_AOI_STAMP?>', '<?=$R_IL_FILM_AOI_STAMP?>');" <?=$checkbox?>
<input type="submit" value="Change !" /></p>
</form>
0
 
_Marcel_Commented:
Maybe

<form name="c1" method="post" action="11.php?REC_NO=<?=$REC_NO?>">

will give you REC_NO in the $_REQUEST (or $_POST)...
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
alberthendriksCommented:
I don't know what Marcel means exactly, but I think the problem is in that line. I'd say

<form name="c1" method="post" action="11.php?REC_NO=<?php echo $_GET['REC_NO']; ?>">

In the other file you can fetch it with GET or REQUEST.
0
 
JKlatteCommented:
Marcel is right concerning the variable in the form line, since it comes from the line $REC_NO=mysql_result($result,$i,"REC_NO"); However, it's bad practice to call a form action with variables (11.php?...), since it mixes POST and GET requests. It should be like this:

  <form name="c1" method="POST" action="11.php">
  <input type="hidden" name="REC_NO" value="<?=$REC_NO?>">
  <input type="checkbox" name="H_IL_FILM_AOI" [...javascript...] > <?=$checkbox?>
  <input type="submit" value="Change !">


Then in 11.php, use $_POST['REC_NO'], since the form method is POST:

  mysql_query("UPDATE PROJECT $set_part, $stamp WHERE REC_NO = $_POST['REC_NO']");
 
0
 
_Marcel_Commented:
It might be indeed a bit confusing mixing GET and POST variables, but basically it will work. Sometimes with URL-rewriting it is even necessary...
0
 
jjcheap1Author Commented:
Marcel's

 Maybe

<form name="c1" method="post" action="11.php?REC_NO=<?=$REC_NO?>">

Worked !

I do not get to spend much time on this between "side shows".  

Thanks for all of your help

Scott
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now