Jump to content

delete


kendris

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/276730-delete/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/276730-delete/#findComment-1423759
Share on other sites

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");

}

Link to comment
https://forums.phpfreaks.com/topic/276730-delete/#findComment-1423806
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/276730-delete/#findComment-1423817
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/276730-delete/#findComment-1423832
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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