In PHP delete record in mysql database?
hi..m working away at a dreamweaver and also php implementing wamp host..in which will m setting up a simple undertaking for the learning purpose..
i have a databases and our web type in php..
i need to remove duplicate content the record of particular person by writing the proper name inside the textbox..
if your user writes the right name subsequently the record must be deleted associated with his/her..of course , if the end user writes completely wrong name the user will get and problem msg for instance “INVALID USERNAME” somethin..
but m becoming problem with this pls assistance me..here’s my signal through this i’d like to see to obtain what i would like..
————————————–
page1.php
—————————
<php
if(isset($_POST’submit’))
$nam = $_POST’t1′;
mysql_connect(“localhost”, “root”, “”);
mysql_select_db(“mytry”);
$qry = “delete by table1 where fname=’$nam'”;
$res = mysql_query($qry);
if(! mysql_query($qry))
echo “Error:”.mysql_error();
if($rows = mysql_fetch_array($res))
echo “Deleted”;
else
echo “Invalid Name”;
>
————————————–
pls an individual tell my family whats erroneous m undertaking here…as i need to remove the document of person only when the user writes the right name that may be already inside database..
your just about any help can be highly hugely appreciated by me..
thanks beforehand…
Try This particular:
$qry = “select * by table1 where fname=’$nam'”;
$res = mysql_affected_rows(mysql_query($qry)); // When user identify exists, this may return amount of rows fetched.
when ($res = 0) // Whenever 0, in that case username doesnot exist
echo ” BROKEN USER NAME”;
else
$qry = “delete by table1 where fname=’$nam'”;
$res = mysql_query($qry);
when (mysql_query($qry))
echo(“
Record Taken away!
“);
other than them
echo(“
Error deleteing:”.mysql_error().”
“);
Delete doesn’t return rows, so labelling mysql_fetch_array doesn’t work.
You should call mysql_affected_rows() to ascertain if the row appeared to be deleted.
View Example #1 throughout link down below.
I really don’t see just about any obvious blunders.
The best way to troubleshoot it’s to reveal $qry so that you can run it and test it around phpmyadmin.
You could possibly also need to verify your mysql_connect as well as mysql_select_db usually are fine simply by appending “or die(mysql_error($res))”.
MODIFY:The additional answerer’s suitable on that experts claim no row are certain to get returned.
I also planned to add until this script must not be made available online since it has really serious security imperfections.One may possibly easily eliminate your full database by using it.
Leave a Reply
You must be logged in to post a comment.