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...
how to delete records in my database in mysql fo php
Moderator: General Moderators
Re: how to delete records in my database in mysql fo php
You are using a delete query when you connect to your database when checking a username etczhed 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 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
-
daveshoope
- Forum Newbie
- Posts: 8
- Joined: Thu Aug 06, 2009 10:28 am
Re: how to delete records in my database in mysql fo php
try this outzhed 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
$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
Re: how to delete records in my database in mysql fo php
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......
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......