Jump to content

Bit stuck with update...


rik72

Recommended Posts

I dab into PHP probably once a year for small projects and i've gone very rusty!

 

<?php
if(isset($_POST['update']))
{

$con = mysql_connect("localhost","user","pass");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("tbl", $con);
mysql_query("UPDATE order_manager SET order_status='$_POST[order_status]'");

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "<div id='red'>order updated!</div>";

mysql_close($con);

} ?>

<form method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">
<?php
$con = mysql_connect("localhost","user","pass");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("tbl", $con);

$result = mysql_query("SELECT * FROM order_manager WHERE active='1'");

echo "<table border='0' cellpadding='2' cellpadding='2'>
<tr>
<th>Client Name:</th>
<th>Invoice Number:</th>
<th>Status:</th>
<th>Notes:</th>
<th>Deadline:</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['client_name'] . "</td>";
  echo "<td>" . $row['invoice_number'] . "</td>";
    echo "<td>"; 
echo "<select name='order_status' id='order_status'>";
 echo "<option value='" . $row['status'] .  "' selected='selected'>Payment Received</option>";
         echo "<option value='Payment Received'>Payment Received</option>";
         echo "  <option value='Awaiting Payment'>Awaiting Payment</option>";
        echo "   <option value='Stock Ordered'>Stock Ordered</option>";
        echo "   <option value='Awaiting Digitising'>Awaiting Digitising</option>";
        echo "   <option value='Processing Order'>Processing Order</option>";
         echo "  <option value='Waiting for email from client'>Waiting for email from client</option>";
       echo "</select></td>";
 echo "<td>" . $row['notes'] . "</td>";
  echo "<td>" . $row['deadline'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

?>
      <input type="submit" name="update" id="button" value="Submit" />
</form>

 

I know my dropdown box isn't ideal, but I'll work on that later on, i'm basically trying to make my table update the status when i hit submit. It's an internal system so it doesn't need to be perfect,  but i'm currently just getting errors.

 

Link to comment
Share on other sites

Please post the entire error. All the information is important.

Put this at the beginning of the file:

error_reporting(-1);

 

and do this with the mysql_query instead:

$result = mysql_query("SELECT * FROM order_manager WHERE active='1'") or die(mysql_error());

Link to comment
Share on other sites

Okay, since earlier i am still stuck with it all.

 

<h2>Current Orders</h2>
<form method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">
<?php
$con = mysql_connect("localhost","user","pass");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("tbl", $con);

$result = mysql_query("SELECT * FROM order_manager WHERE order_status != 3");

echo "<table border='0' cellpadding='2' cellpadding='2'>
<tr>
<th>Client ID</th>
<th>Client Name</th>
<th>Invoice Number</th>
<th>Status</th>
<th width='300px'>Notes</th>
<th>Deadline</th>
<th>Delete</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
     echo "<td  width='20px'>" . $row['client_id'] . "</td>";
  echo "<td  width='100px'>" . $row['client_name'] . "</td>";
  echo "<td  width='100px'>" . $row['invoice_number'] . "</td>";
    echo "<td  width='200px'>"; 
echo "<select name='order_status' id='order_status'>";
$result2 = mysql_query("SELECT * FROM order_status");
while($row2 = mysql_fetch_array($result2))
{ 
  echo "<option value='$row2[status_id]'";
  if($row2['status_id'] === $row['order_status'])
      {
       echo "selected='selected'";
  }
  echo "> $row2[order_status] </option>";
     }       echo "</select></td>";



 echo "<td  width='300px'><textarea name='notes'>" . $row['notes'] . "</textarea></td>";
  echo "<td  width='100px'>" . $row['deadline'] . "</td>";
    echo "<td><input name='delete' type='checkbox' value='del' /></td>";
  echo "</tr>";
  }
echo "</table>";

mysql_close($con);

?>

      <input type="submit" name="update" id="button" value="Update Orders" />
</form>

 

This all works but i basically need an update statement so that i can change order_status's and notes within the table. If someone could point me in the right direction of how to go about it, that would be fantastic.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.