rik72 Posted August 20, 2012 Share Posted August 20, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/267341-bit-stuck-with-update/ Share on other sites More sharing options...
Ninjakreborn Posted August 20, 2012 Share Posted August 20, 2012 Copy/Paste the error message output your getting for the code. Quote Link to comment https://forums.phpfreaks.com/topic/267341-bit-stuck-with-update/#findComment-1370839 Share on other sites More sharing options...
rik72 Posted August 20, 2012 Author Share Posted August 20, 2012 Error: Query was empty Thanks, Quote Link to comment https://forums.phpfreaks.com/topic/267341-bit-stuck-with-update/#findComment-1370841 Share on other sites More sharing options...
MMDE Posted August 20, 2012 Share Posted August 20, 2012 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()); Quote Link to comment https://forums.phpfreaks.com/topic/267341-bit-stuck-with-update/#findComment-1370844 Share on other sites More sharing options...
PFMaBiSmAd Posted August 20, 2012 Share Posted August 20, 2012 The error is because you are calling a mysql_query statement a second time with a variable as the first parameter (the query statement) that does not exist. Quote Link to comment https://forums.phpfreaks.com/topic/267341-bit-stuck-with-update/#findComment-1370847 Share on other sites More sharing options...
rik72 Posted August 20, 2012 Author Share Posted August 20, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/267341-bit-stuck-with-update/#findComment-1370948 Share on other sites More sharing options...
PFMaBiSmAd Posted August 23, 2012 Share Posted August 23, 2012 The right direction to take would be to put back in the update logic you had and to find and fix what was causing the error in it. Quote Link to comment https://forums.phpfreaks.com/topic/267341-bit-stuck-with-update/#findComment-1371659 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.