fourthe Posted February 25, 2009 Share Posted February 25, 2009 I'm new to PHP and I'm having trouble figuring this out. I think i have my if statement messed up, if someone could help me that would be great. Thank you After filling out the form, it should submit to the code below 1. Inserts the "ordered" item into the database 2. Shows a list of all items that have been ordered 3. Provides a link to delete/remove any item from the cart If the delete link is clicked, it should delete the corresponding item and return to the shopping cart page <?php $cmd = "delete"; //This will set the $cmd variable to allow the delete function to run $con = mysql_connect('localhost', 'root', 'kellogg'); $db=mysql_select_db('welshch3', $con); $check1 = $_REQUEST['check1']; $check2 = $_REQUEST['check2']; $check1 = 0; $check2 = 0; foreach($var as $c) { if($c == "c1") { $check1 = 1; } elseif($c =="c2") { $check2 = 1; } } $insert = "INSERT INTO cart (text1, text2, button, check1, check2, comment) VALUES ('" . $_REQUEST['text1'] . "', '" . $_REQUEST['text2'] . "', '" . $_REQUEST['button'] ."'," . $check1 . "," . $check2 .", '" . $_REQUEST['special'] . "')"; if(!isset($cmd)){ mysql_query($insert); $select = "SELECT * FROM cart"; $result = mysql_query($select); $id=$row["id"]; while ($row = mysql_fetch_array($result)) { echo "First Line: " . $row['text1'] . "\n"; echo "Second Line: " . $row['text2'] . "\n"; echo "Color: " . $row['button'] . "\n"; echo "Extra: " . $row['check1'] . "\n"; echo "Special: " . $row['comment'] . "\n"; echo "<a href='cart.php?del_id=id'>delete</a><br>"; } } if($cmd=="delete") { $sql = "DELETE FROM cart WHERE id=$id"; $result = mysql_query($sql); echo "Row deleted!"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/146902-deleting-rows-from-database/ Share on other sites More sharing options...
sasa Posted February 25, 2009 Share Posted February 25, 2009 1st change echo "<a href='cart.php?del_id=id'>delete</a><br>"; to echo "<a href='cart.php?del_id=$id'>delete</a><br>";[/code]and if($cmd=="delete") { $sql = "DELETE FROM cart WHERE id=$id"; $result = mysql_query($sql); echo "Row deleted!"; } to if(isset($_GET['del_id'])) { $id=$_GET['del_id']; $sql = "DELETE FROM cart WHERE id=$id"; $result = mysql_query($sql); echo "Row deleted!"; } Quote Link to comment https://forums.phpfreaks.com/topic/146902-deleting-rows-from-database/#findComment-771267 Share on other sites More sharing options...
fourthe Posted February 26, 2009 Author Share Posted February 26, 2009 I don't think that worked, I just get a blank page when i try to run it Quote Link to comment https://forums.phpfreaks.com/topic/146902-deleting-rows-from-database/#findComment-771505 Share on other sites More sharing options...
fry2010 Posted February 26, 2009 Share Posted February 26, 2009 Go into your php ini file and find this: error_reporting = E_ALL | E_NOTICE | E_STRICT or rather your error reporting part, and add that to the line. Then you will see what the problems are, I know its not pretty but it deffinatly helps finding errors out faster. It basically tells you where to look. Remember when you change this to retart apache. Quote Link to comment https://forums.phpfreaks.com/topic/146902-deleting-rows-from-database/#findComment-771511 Share on other sites More sharing options...
fourthe Posted February 26, 2009 Author Share Posted February 26, 2009 I'm not able to edit that because this is for my class. There is something wrong with my if statements where its not deleting the rows and i dont understand why Quote Link to comment https://forums.phpfreaks.com/topic/146902-deleting-rows-from-database/#findComment-771988 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.