Jump to content

Updating MySQL problem


timmah1

Recommended Posts

here is my form

<form name="processed" action"" method="POST">
	<input type="hidden" name="order_number" id="order_number" value="<?php echo $row['order_number']; ?>">
	<input type="hidden" name="update" id="update" value="y">
	<input type="hidden" name="status" id="status" value="y">
	<input type="submit" name="Submit" value="Mark as processed <?php echo $row['id']; ?>">
	</form>

 

Here is the update

if($_POST['update']=="y") {
$result = mysql_query("UPDATE `order` SET processed='".$_POST['status']."' where order_number = '".$_POST['order_number']."'") 
or die(mysql_error());  
echo "Order updated<br>Please wait...<meta http-equiv=\"refresh\" content=\"1; url=?cid=adminStatus\" />";;
}

 

Why won't this update?

 

Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/90333-updating-mysql-problem/
Share on other sites

I put my sql strings into a variable before calling mysql_query. Then when I have problems like this it is easy to look at the query and check it is OK or not. Try

 

if($_POST['update']=="y") {
  $sql = "UPDATE `order` SET processed='".$_POST['status']."' where order_number = '".$_POST['order_number']."'";
  echo '<pre>', $sql, '</pre>';
  $result = mysql_query($sql) 
     or die(mysql_error());  
  echo "Order updated<br>Please wait...<meta http-equiv=\"refresh\" content=\"1; url=?cid=adminStatus\" />";;
}

It does the exact same thing.

 

Here is my entire code for this page

<?php
include "DB_config.php";
//if($_POST['update']=="y")
//die("=)") {
//$result = mysql_query("UPDATE `order` SET processed='".$_POST['status']."' where order_number = '".$_POST['order_number']."'") 
//or die(mysql_error());  
//echo "Order updated<br>Please wait...<meta http-equiv=\"refresh\" content=\"1; url=?cid=adminStatus\" />";;
//}
if($_POST['update']=="y") {
  $sql = "UPDATE `order` SET processed='".$_POST['status']."' where order_number = '".$_POST['order_number']."'";
  echo '<pre>', $sql, '</pre>';
  $result = mysql_query($sql) 
     or die(mysql_error());  
  echo "Order updated<br>Please wait...<meta http-equiv=\"refresh\" content=\"1; url=?cid=adminStatus\" />";;
}
else {
$user = "SELECT * FROM `order`";
$result = mysql_query($user);

$numberall = mysql_Numrows($result);
?>
<h1>Main System Admin</h1>
<table width="90%" border="0" cellspacing="0" cellpadding="10">
  <tr> 
    <td bgcolor="#801013"><strong><font color="#FFFFFF">All Orders - Status </font></strong></td>
  </tr>

  <tr> 
    <td>

<table width="100%" border="0">
      <tr>

        <td>Name</td>
        <td>Address</td>
        <td>Phone</td>
        <td>Quantity</td>
        <td>Status</td>
        </tr>
	 <?php
if ($numberall==0) {
    echo "<strong>There are no orders</strong>"; 
}
?>
	 <?php
  while($row = mysql_fetch_array( $result )){
  ?>
      <tr valign="top">
    <td><?php echo $row['f_name']; ?> <?php echo $row['l_name']; ?></td>
        <td><?php echo $row['address']; ?><br>
	<?php echo $row['city']; ?>, <?php echo $row['state']; ?><br>
	<?php echo $row['zip']; ?></td>
        <td><?php echo $row['phone']; ?></td>
        <td><?php echo $row['quantity']; ?></td>
        <td><?php
	if($row['status']=="n"){
	?>
	<form name="processed" action"" method="POST">
	<input type="hidden" name="order_number" id="order_number" value="<?php echo $row['order_number']; ?>">
	<input type="hidden" name="update" id="update" value="y">
	<input type="hidden" name="status" id="status" value="y">
	<input type="submit" name="Submit" value="Mark as processed <?php echo $row['id']; ?>">
	</form>
	<?php
	}
	else {
	?>
	<form name="unprocessed" action"" method="POST">
	<input type="hidden" name="order_number" id="order_number" value="<?php echo $row['order_number']; ?>">
	<input type="hidden" name="update" id="update" value="y">
	<input type="hidden" name="status" id="status" value="n">
	<input type="submit" name="Submit" value="Mark as un-processed <?php echo $row['order_number']; ?>">
	</form>
	<?php
	}
	?></td>
        </tr>
	<?php
	}
	?>
    </table></td>
  </tr>

</table>
<?php
	}
	?>

It does the exact same thing.

 

 

 

I didn't expect it not to. It could be useful if we could see the actual query though. What is the ouput from

 

echo '<pre>', $sql, '</pre>';

 

I can't run and debug your code - I don't have your database.

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.