0

I'm trying to delete a row in a table in my database, but it isn't working... The connection works. I've echoed the table row id to ensure it is working and still it won't delete...

Let me know if you need the connection code too.

code:

<table>
  <tr>
    <td>Recent Posts</td>
  </tr>
  <?php while($row = mysql_fetch_array($result)) : ?>
    <td><?php echo $row['id']; ?></td>
    <td><?php echo $row['name']; ?></td>
    <td><?php echo $row['phone number']; ?></td>
    <td><a href="delete2.php?id=<?php echo $row['id'];?>">Schedule</a></td>
  </tr>
  <?php endwhile; ?>
</table>

delete.php code:

  <?php
    $b=$_GET['id'];
    $sql='DELETE FROM on call WHERE id=$b';
//echoing just to make sure it is working correctly...
echo $b;
    ?>
    </br>
    </br>
    <a href='index2.php'>back to list</a>
4
  • 4
    Please, before you write any more SQL interfacing code, you must read up on proper SQL escaping to avoid severe SQL injection bugs. Also, mysql_query should not be used in new applications. It's a deprecated interface that's being removed from future versions of PHP. A modern replacement like PDO is not hard to learn. A guide like PHP The Right Way will help you avoid making mistakes like this. Commented Nov 22, 2013 at 16:56
  • 3
    What is your table called? If it's on call, you'll need to wrap it in backticks. (And I'd suggest renaming it so it doesn't have a space in the name). Commented Nov 22, 2013 at 16:57
  • What is your table???? Commented Nov 22, 2013 at 16:58
  • Always "on the ball" ;-) @andrewsi Commented Nov 22, 2013 at 17:03

3 Answers 3

3

You didn't execute your DELETE sql command using mysql_query

$sql = "DELETE FROM ...";
mysql_query($sql);

Please note that the mysql functions are now deprecated. Also, you should protect your code against SQL injections.

Sign up to request clarification or add additional context in comments.

12 Comments

I executed my sql and it still doesn't work... Is this because it is deprecated??
I can't help when someone just tells me "it doesn't work". what is the error message for example?
Sorry. I added the query to execute the DELETE sql command. I don't get any error messages though... You can try it yourself if you like: [link]andadietcoke.com/test/index2.php[/link] I'm also echoing the table row id number at the moment just to make sure the correct number is being passed to the delete.php... Thanks!
use this instead: $sql='DELETE FROM on call WHERE id=' . $b;
well actually it's impossible that your table is called "on call", there should be no white space (sorry, when I commented I copy/pasted and didn't see this detail).
|
0

I don't understand your sql syntax. if 'on call' is your table, please rename your table to on_call and so your sql should :

$sql = "DELETE FROM on_call WHERE id = '" . $b . "'";

Comments

0

You did not execute your sql. mysql_query($sql); use mysql function to prevent injection.

1 Comment

I added a query to execute the sql... I'm not getting any error messages and it still isn't working... Also, how do I prevent injection?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.