2

I am having the simple php code that shows columns in table test (delete.php & delete_ac.php), when click on delete button this suppose to delete the respective column. But it is displaying error occurred and the table HTML showing blank. Not sure which steps i was wrong. Any help are very appreciated.!

http://pastebin.com/9Zz217Bn

4
  • Couldn't paste your code here? Commented Jun 10, 2014 at 4:25
  • Are you passing id to your delete code as it expects? Commented Jun 10, 2014 at 4:26
  • hello, my code is in pastebin.com/9Zz217Bn thanks so much Commented Jun 10, 2014 at 4:27
  • echo $sql="delete from $table where id='$id'"; and run your query in phpmyadmin Commented Jun 10, 2014 at 4:32

5 Answers 5

1

I suggest using

echo mysqli_error();

to see what the error is.

Also you don't seem to be setting $id.

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

2 Comments

Hello, i having following error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'id']; ?>'' at line 1 mysql version is 5.6.12
you probably put a single or double quote in the wrong place - please send the whole line that ends 'id']; ?>
0

From your responses it seems that you have an error in the sql. The error might be from the way you are sending your data to the script. Tangentially you are encountering an error because you have not in any way checked the input which could be anything and are trusting that it is valid data. It helps to assume that all users are mean and want to cause damage.

So I would recommend at least an if and a test for the data being numeric. Then you could see if you were passing bad data. This might help you troubleshoot and will make your code more robust against attack, user error and things like that. You would not want someone manually typing the URL and putting id=>-1 as that would delete everything.

Like the one you commented:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'id']; ?>'' at line 1 mysql version is 5.6.12

However what you might need to do (as others have pointed out) is echo the sql and paste it into something like phpmyAdmin or some MySQL GUI and see what it you get back. The (more than likely) error may help you identify the cause of your problems. It looks like you might have ended up with the php code in the query string.

If you have short tags off then the short php you have use will not work and will end up in the link which it does seem to have done. Try:

<?php echo $rows['id']; ?>

Which I think will work for you much better.

If in doubt go back to the earlier suggestion (not just from me) to echo out the generated sql which I would expect will not look right.

While you are at it can I recommend you consider using "LIMIT 1" at the end of your SQL once you have it working? Then if anything goes wrong you only dropped the one row.

One last thing it makes folks here much happier if you just paste the code into the question.

I hope I helped you.

1 Comment

Thanks a lots, You are exactly right. i have missing php in <? echo $rows['id']; ?>. After input the php line, it is works like a charm :)
0

The problem lies in your Querystring of delete button use fuller

Comments

0

Thanks a lots for all answers, i am really appreciated your helpful tips. i have checked the syntax :

<td bgcolor="#FFFFFF"><a href="delete_ac.php?id=<? echo $rows['id']; ?>">delete</a></td>

which is missing php line, after filled php line, the code working well:

<td bgcolor="#FFFFFF"><a href="delete_ac.php?id=<?php echo $rows['id']; ?>">delete</a></td>

Comments

0

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'id']; ?>'' at line 1 mysql version is 5.6.12

Comments

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.