vomitbomb Posted May 12, 2008 Share Posted May 12, 2008 I can't find the syntax to remove an entry in the table once the order has been picked up, anyone know what it is? Link to comment https://forums.phpfreaks.com/topic/105229-deleting-an-entry-in-a-database-table/ Share on other sites More sharing options...
corbin Posted May 12, 2008 Share Posted May 12, 2008 DELTE FROM some_table WHERE <conditions> For example: DELETE FROM orders WHERE order_id = 4 Link to comment https://forums.phpfreaks.com/topic/105229-deleting-an-entry-in-a-database-table/#findComment-538830 Share on other sites More sharing options...
vomitbomb Posted May 12, 2008 Author Share Posted May 12, 2008 <? //make the database connection $conn = mysql_connect("localhost", "", ""); mysql_select_db("example", $conn); $search = $_POST['search']; //create a query $sql = "SELECT * FROM orders WHERE lname='$search'"; $result = mysql_query($sql, $conn); $row = mysql_fetch_array( $result ); echo "<h3>Showing Order for: </h3>"; echo "" .$row['fname']; echo "" .$row['lname']; echo "<br>"; if($row['pnumber'] != 0){ echo "Home Phone: ".$row['pnumber']; echo "<br>"; } if($row['mnumber'] != 0){ echo "Mobile Phone: ".$row['mnumber']; echo "<br>"; } mysql_close($conn); ?> Hmm.. Anyone know how I can put a button, form or link in there to execute the: DELTE FROM some_table WHERE <conditions> To delete this order? Link to comment https://forums.phpfreaks.com/topic/105229-deleting-an-entry-in-a-database-table/#findComment-538835 Share on other sites More sharing options...
kemo Posted May 12, 2008 Share Posted May 12, 2008 I can't find the syntax to remove an entry in the table once the order has been picked up, anyone know what it is? Please, be more specific... DO you want to delete row from the table you've selected right now? // kemo Link to comment https://forums.phpfreaks.com/topic/105229-deleting-an-entry-in-a-database-table/#findComment-538836 Share on other sites More sharing options...
vomitbomb Posted May 12, 2008 Author Share Posted May 12, 2008 yep, the one that has come up in the search result, thats the row I wanna delete, I think I've worked a way around it but having 2 buttons, one goes to a script that deletes the order, one just goes to the main page. Don't know if there's a better way to do it. How do I take the $row variable from this script to another, so I can delete it? Link to comment https://forums.phpfreaks.com/topic/105229-deleting-an-entry-in-a-database-table/#findComment-538839 Share on other sites More sharing options...
kemo Posted May 12, 2008 Share Posted May 12, 2008 Hope this helps you, if you want to delete the row on the another page I suppose, you have to send the value of the row with sessions.. <?php //make the database connection $conn = mysql_connect("localhost", "", ""); mysql_select_db("example", $conn); $search = $_POST['search']; //create a query $sql = "SELECT * FROM orders WHERE lname='{$search}'"; $result = mysql_query($sql, $conn); $row = mysql_fetch_array( $result ); echo "<h3>Showing Order for: </h3>"; echo "" .$row['fname']; echo "" .$row['lname']; echo "<br>"; if($row['pnumber'] != 0){ echo "Home Phone: ".$row['pnumber']; echo "<br>"; } if($row['mnumber'] != 0){ echo "Mobile Phone: ".$row['mnumber']; echo "<br>"; } // deleting the selected row if(!empty($row['fname']) && !empty($row['lname'])){ //check if fname and lname are not empty.. $sql = "DELETE FROM orders WHERE fname='" . $row["fname"] . "' AND lname='" . $row["lname"]."' LIMIT 1"; //delete row with fname and lname selected from the row $result = mysql_query($sql,$conn); //execute the query.. if($result){ echo "<p>Row with fname: " . $row['fname'] . " has been deleted!</p>"; //send info to user }else { echo "<p>Error has occured!</p>"; //otherwise print error.. } }else{ die('fname and lname must not be empty!'); } mysql_close($conn); ?> Link to comment https://forums.phpfreaks.com/topic/105229-deleting-an-entry-in-a-database-table/#findComment-538842 Share on other sites More sharing options...
vomitbomb Posted May 12, 2008 Author Share Posted May 12, 2008 I'll have to try that, but I need it in the form of a button, I don't want the orders being deleted everytime someone looks at them. Can I parse the variable $row from this script to another using a form? if so how do I do that? Basically I want to parse the result (using a button or link on this page) that came up into a document that instead of looking at it's contents, deletes the entry(row). I know how to parse a value from a form, but how about a value inside a variable thats already been parsed? ??? Link to comment https://forums.phpfreaks.com/topic/105229-deleting-an-entry-in-a-database-table/#findComment-538848 Share on other sites More sharing options...
PFMaBiSmAd Posted May 12, 2008 Share Posted May 12, 2008 In a real order processing application, you don't delete orders from the database when they are complete. You change a status column to indicate that they are complete. In this way you have a record of the order (who, what, when, where...), in case they want to return an item or you need to do something like detect credit card abuse... Link to comment https://forums.phpfreaks.com/topic/105229-deleting-an-entry-in-a-database-table/#findComment-538913 Share on other sites More sharing options...
vomitbomb Posted May 12, 2008 Author Share Posted May 12, 2008 Ok my new question is, How do I take the $row variable from that script to another? I've only used html forms to post values into variables. My search page opens up the code above, I then want to use the users details from that script in another script to update the records. Link to comment https://forums.phpfreaks.com/topic/105229-deleting-an-entry-in-a-database-table/#findComment-538935 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.