Jump to content

delete


kendris
 Share

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
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
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
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
Share on other sites

 

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 by kendris
Link to comment
Share on other sites

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 by jazzman1
Link to comment
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
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

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