Page 1 of 1

how to delete records in my database in mysql fo php

Posted: Tue Aug 30, 2011 8:40 am
by zhed
if (isset($_POST['submitted'])){
{
$nam = $_POST['search'];
mysql_connect("localhost","root","");
mysql_select_db("sample");
$qry = "delete from student where sNumber='$nam'";
$res = mysql_affected_rows(mysql_query); // If user name exists, this will return number of rows fetched.
if ($res = 0) // If 0, then username doesnot exist
{
echo " No id found";
}
else
{
$qry = "delete from student where sNumber='$nam'";
$res = mysql_query($qry);
if (@mysql_query($qry))
{ echo("<br/><br/>Record Removed!</p>"); }
else
{ echo("<br/><br/>Error deleteing: " . mysql_error() . "</p>"); }
}

}





here is my code....there is a problem here...can someone help me..plz...thanx for advnce...

Re: how to delete records in my database in mysql fo php

Posted: Tue Aug 30, 2011 9:11 am
by phphelpme
zhed wrote:

Code: Select all

$qry = "delete from student where sNumber='$nam'"; 

echo " No id found";

{ echo("<br/><br/>Record Removed!</p>"); }
else 
{ echo("<br/><br/>Error deleteing: " . mysql_error() . "</p>");
You are using a delete query when you connect to your database when checking a username etc

You echo without brackets in your first echo no id found but use brackets in your next two echos.

You need to tell us what errors are being displayed for you before we can truly fix the issue.

Best wishes

Re: how to delete records in my database in mysql fo php

Posted: Tue Aug 30, 2011 9:51 am
by daveshoope
zhed wrote: $qry = "delete from student where sNumber='$nam'";
$res = mysql_affected_rows(mysql_query); // If user name exists, this will return number of rows fetched.
if ($res = 0) // If 0, then username doesnot exist
try this out
$res = mysql_affected_rows(mysql_query($qry));

the query was not passed as a parameter to the mysql_query() function.

If thats the only problem fine, but if there are more, still speak :D

Re: how to delete records in my database in mysql fo php

Posted: Wed Aug 31, 2011 2:26 am
by zhed
sir daveshoope,....
i try your code and i met this error....what is the problem sir?;

Warning: mysql_affected_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\sample\delete.php on line 28

Record Removed!


sir...i want to delete record in my database in mysql and it will tells the user if the id is not in database and should not be deleting if that is the situation.....how can i do that with that code......