delete blog

Codes here !

Moderators: macek, egami, gesf

rida2
New php-forum User
New php-forum User
Posts: 3
Joined: Tue Aug 14, 2012 1:51 am

delete blog

Postby rida2 » Tue Aug 14, 2012 3:19 am

why this does not delete anything??
<?php
session_start();
if(!isset($_SESSION['usernamea']))
{
header("location:index.php");
}
else
{

$_SESSION['usernamea']=$_SESSION['usernamea'];

$a=$_SESSION['a'];
include("../dbconnection.php");
if(isset($_GET['id']))
{

$id=$_GET['id'];




$result=mysql_query("delete * from blogtable where blogid=$id")
$n=mysql_num_rows($result);
echo "nn".$result;
if($n>0)
{
header("location:blogmoderator.php?del=Y");
}
else
{
header("location:blogmoderator.php?del=N");
}

}
}
?>

johnj
php-forum Super User
php-forum Super User
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: delete blog

Postby johnj » Tue Aug 14, 2012 6:37 am

...delete * from blogtable where blogid=$id


are you sure that this sql is correct?

User avatar
freshnet
php-forum Active User
php-forum Active User
Posts: 285
Joined: Tue Feb 22, 2011 8:19 am
Location: Canada

Re: delete blog

Postby freshnet » Tue Aug 14, 2012 9:01 am

You're also missing the ; from the end of that line, so I'd expect you to get an error somewhere.

rida2
New php-forum User
New php-forum User
Posts: 3
Joined: Tue Aug 14, 2012 1:51 am

Re: delete blog

Postby rida2 » Wed Aug 15, 2012 4:58 am

Hey thanks for replying guys, but that ";" didn't make any difference. Also I am sure of "delete * from blogtable where blogid=$id

User avatar
freshnet
php-forum Active User
php-forum Active User
Posts: 285
Joined: Tue Feb 22, 2011 8:19 am
Location: Canada

Re: delete blog

Postby freshnet » Thu Aug 16, 2012 7:10 am

ok for a delete if you want the number of rows you will need to use $n=mysql_affected_rows($result); . For the query itself, try capturing the error (you can just echo mysql_error()). You also should be using mysqli/PDO instead of mysql. See http://php.net/manual/en/function.mysql-affected-rows.php For more information.


Return to “mySQL & php coding”

Who is online

Users browsing this forum: Yahoo [Bot] and 2 guests

cron