kendris Posted April 9, 2013 Share Posted April 9, 2013 <html> <?php include "overallheader.php" ?> <div id ='container'> <div id ='content'> <div id='navBar'> <?php include "navbar.php"?> </div> <div id='userinfo'> <?php session_start(); if (isset($_SESSION["username"])) { $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("login", $con); mysql_close($con); } else die("You must be logged in <a href='index.php'>Back</a>"); ?> <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("login", $con); $result=mysql_query('SELECT eventname FROM event'); $result = mysql_query("SELECT * FROM event"); ?> </div> <div id ="eventform"> <?php $result = mysql_query("SELECT * FROM booking"); $result2 = mysql_query("SELECT bookingid FROM booking"); echo "<table border='1'> <tr> <th>Booking ID</th> <th>Event ID</th> <th> User ID</th> </tr>"; while($row = mysql_fetch_array($result)) { $eventid = $row["bookingid"]; echo "<tr>"; echo "<td>" . $row["bookingid"] . "</td>"; echo "<td>" . $row["eventid"] . "</td>"; ?> <td ><input type='text' name='eventid' id='eventid' value='<?php echo "$eventid" ; ?>' readonly='readonly' /> </td> <?php echo '<td> <INPUT TYPE="submit" VALUE="Delete"></td>'; echo "</tr>"; echo "</form>"; } echo "</table>"; if (isset($_POST["bookingid"], $_POST["eventid"], $_POST["userid"])) { $forename = $_POST["bookingid"]; $eventname = $_POST["eventid"]; $email = $_POST["userid"]; } $order = mysql_query("DELETE FROM booking WHERE bookingid ='$result2' LIMIT 1"); ?> </div> </div> </div> </html> I have been trying to set this so it will delete a row but for some reason it's not working. Quote Link to comment Share on other sites More sharing options...
runnerjp Posted April 9, 2013 Share Posted April 9, 2013 When you say it doesn't work. What's happening? Any errors? Quote Link to comment Share on other sites More sharing options...
kendris Posted April 9, 2013 Author Share Posted April 9, 2013 No errors, it's giving no fed back. Quote Link to comment Share on other sites More sharing options...
kendris Posted April 9, 2013 Author Share Posted April 9, 2013 <html> <?php include "overallheader.php" ?> <div id ='container'> <div id ='content'> <div id='navBar'> <?php include "navbar.php"?> </div> <div id='userinfo'> <?php session_start(); if (isset($_SESSION["username"])) { $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("login", $con); mysql_close($con); } else die("You must be logged in <a href='index.php'>Back</a>"); ?> <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("login", $con); $result=mysql_query('SELECT eventname FROM event'); $result = mysql_query("SELECT * FROM event"); ?> </div> <div id ="eventform"> <?php $result = mysql_query("SELECT * FROM booking"); $result2 = mysql_query("SELECT bookingid FROM booking"); echo "<table border='1'> <tr> <th>Booking ID</th> <th>Event ID</th> <th> User ID</th> <th> Delete</th> </tr>"; while($row = mysql_fetch_array($result)) { $eventid = $row["bookingid"]; "<form name='myForm' action ='' onsubmit='return validateForm()' method='POST'>"; echo "<tr>"; echo "<td>" . $row["bookingid"] . "</td>"; echo "<td>" . $row["eventid"] . "</td>"; ?> <td ><input type='text' name='eventid' id='eventid' value='<?php echo "$eventid" ; ?>' readonly='readonly' /> </td> <?php echo '<td> <INPUT TYPE="submit" VALUE="Delete"></td>'; echo "</tr>"; echo "</form>"; } echo "</table>"; if (isset($_POST["bookingid"], $_POST["eventid"], $_POST["userid"])) { $booking = $_POST["bookingid"]; $eventid = $_POST["eventid"]; $userid = $_POST["userid"]; } $order = mysql_query("DELETE FROM booking WHERE bookingid ='$eventid' LIMIT 1"); ?> </div> </div> </div> </html> I manage to get it to delete each row but it seems to do it each page refresh. Quote Link to comment Share on other sites More sharing options...
PaulRyan Posted April 9, 2013 Share Posted April 9, 2013 You have your select query, BEFORE your delete query. Do it the other way around. Quote Link to comment Share on other sites More sharing options...
kendris Posted April 9, 2013 Author Share Posted April 9, 2013 I attempted it a few different ways with more or less the same result Quote Link to comment Share on other sites More sharing options...
runnerjp Posted April 9, 2013 Share Posted April 9, 2013 Thats because you have no if statement to tell it otherwise. Each time the page loads it will just fire $order = mysql_query("DELETE FROM booking WHERE bookingid ='$eventid' LIMIT 1"); Unless you have a stament which says - if something then delete row e.g if ($delete = '1' ){ $order = mysql_query("DELETE FROM booking WHERE bookingid ='$eventid' LIMIT 1"); } Quote Link to comment Share on other sites More sharing options...
kendris Posted April 9, 2013 Author Share Posted April 9, 2013 <html> <?php include "overallheader.php" ?> <div id ='container'> <div id ='content'> <div id='navBar'> <?php include "navbar.php"?> </div> <div id='userinfo'> <?php session_start(); if (isset($_SESSION["username"])) { $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("login", $con); mysql_close($con); } else die("You must be logged in <a href='index.php'>Back</a>"); ?> <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("login", $con); ?> </div> <div id ="eventform"> <?php $result2 = mysql_query("SELECT bookingid FROM booking"); $result = mysql_query("SELECT * FROM booking"); echo "<table border='1'> <tr> <th>Booking ID</th> <th>Event ID</th> <th> User ID</th> <th> Delete</th> </tr>"; while($row = mysql_fetch_array($result)) { $eventid = $row["bookingid"]; $order = mysql_query("DELETE FROM booking WHERE bookingid ='$eventid' LIMIT 1"); "<form name='myForm' action ='' onsubmit='return validateForm()' method='POST'>"; echo "<tr>"; echo "<td>" . $row["bookingid"] . "</td>"; echo "<td>" . $row["eventid"] . "</td>"; ?> <td ><input type='text' name='eventid' id='eventid' value='<?php echo "$eventid" ; ?>' readonly='readonly' /> </td> <?php echo '<td> <INPUT TYPE="submit" VALUE="Delete"></td>'; echo "</tr>"; echo "</form>"; } echo "</table>"; if ($delete = '1' ){ $order = mysql_query("DELETE FROM booking WHERE bookingid ='$eventid' LIMIT 1"); } /* if (isset($_POST["bookingid"], $_POST["eventid"], $_POST["userid"])) { $booking = $_POST["bookingid"]; $eventid = $_POST["eventid"]; $userid = $_POST["userid"]; echo "Order has been deleted"; } */ ?> </div> </div> </div> </html> I tried like this but same thing. Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted April 9, 2013 Share Posted April 9, 2013 The delete sql statement does not execute according your code above: What you want to say whit that one? if ($delete = '1' ){ $order = mysql_query("DELETE FROM booking WHERE bookingid ='$eventid' LIMIT 1"); } Quote Link to comment Share on other sites More sharing options...
kendris Posted April 9, 2013 Author Share Posted April 9, 2013 (edited) The delete sql statement does not execute according your code above: What you want to say whit that one? if ($delete = '1' ){ $order = mysql_query("DELETE FROM booking WHERE bookingid ='$eventid' LIMIT 1"); } If the form is submitted delete selected row. Edited April 9, 2013 by kendris Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted April 9, 2013 Share Posted April 9, 2013 (edited) Can you show us the form, please? Maybe you have a hidden field with a value 1 somewhere in the form? Just in case the symbol "=" is an assignment not comparison "==" operator in php Edited April 9, 2013 by jazzman1 Quote Link to comment Share on other sites More sharing options...
kendris Posted April 9, 2013 Author Share Posted April 9, 2013 echo "<table border='1'> <tr> <th>Booking ID</th> <th>Event ID</th> <th> User ID</th> <th> Delete</th> </tr>"; while($row = mysql_fetch_array($result)) { $eventid = $row["bookingid"]; $order = mysql_query("DELETE FROM booking WHERE bookingid ='$eventid' LIMIT 1"); "<form name='myForm' action ='' onsubmit='return validateForm()' method='POST'>"; echo "<tr>"; echo "<td>" . $row["bookingid"] . "</td>"; echo "<td>" . $row["eventid"] . "</td>"; ?> <td ><input type='text' name='eventid' id='eventid' value='<?php echo "$eventid" ; ?>' readonly='readonly' /> </td> <?php echo '<td> <INPUT TYPE="submit" VALUE="Delete"></td>'; echo "</tr>"; echo "</form>"; } echo "</table>"; This is the form section Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted April 10, 2013 Share Posted April 10, 2013 Sorry, but your php code messed up, so if I try to help you, I have to rewrite almost everything from scratch. You need to take a step back learning more about good practices in php. Take a look at that web site. Quote Link to comment Share on other sites More sharing options...
kendris Posted April 10, 2013 Author Share Posted April 10, 2013 Right..... Quote Link to comment 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.