We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,301 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

delete from sql

Hi i am Trying to delete a page from my site cms

and something is not working .

the code is:

<?php
 $con = mysql_connect("localhost","matanc_cmd","123123");
 if (!$con)
   {
   die('Could not connect: ' . mysql_error());
   }

mysql_select_db("matanc_cms", $con);


$id = (int) $_POST['id'];

mysql_query("DELETE FROM content WHERE id='$id'");
mysql_close($con);


// if successfully updated.
if($result){

echo "Successful";

 echo "<BR>";
 echo "<a href='show.php'>View result</a>";
}



 ?> 

What is wrong ?
when i want to delete a page i go to the delete.php?id=XX (XX = ID of the page)

3
Contributors
5
Replies
16 Hours
Discussion Span
10 Months Ago
Last Updated
7
Views
matanc244
Newbie Poster
21 posts since Jul 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

Have PHP tell you what mysql doesn't like:

if($result) {
  // echo success info
}  else {
    echo mysql_errno($con) . ": " . mysql_error($con). "\n";
}
madCoder
Junior Poster
165 posts since Feb 2010
Reputation Points: 31
Solved Threads: 45
Skill Endorsements: 0

still dont work

matanc244
Newbie Poster
21 posts since Jul 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

OK. Try putting this test before the if($result)... test.

if (mysql_errno()) { 
   $error = "MySQL error ".mysql_errno().": ".mysql_error()."\n<br>When executing:<br>\n$query\n<br>";
}
madCoder
Junior Poster
165 posts since Feb 2010
Reputation Points: 31
Solved Threads: 45
Skill Endorsements: 0

still not worke

matanc244
Newbie Poster
21 posts since Jul 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

when i want to delete a page i go to the delete.php?id=XX (XX = ID of the page)
$id = (int) $_POST['id'];

This should be

$id = (int) $_GET['id'];
pritaeas
Posting Prodigy
Moderator
9,310 posts since Jul 2006
Reputation Points: 1,178
Solved Threads: 1,465
Skill Endorsements: 86

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0717 seconds using 2.68MB