This is my first month with php and my first day in here...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Jeune griot
Forum Newbie
Posts: 4
Joined: Fri Jun 27, 2008 1:10 pm

This is my first month with php and my first day in here...

Post by Jeune griot »

Sorry here is wut i did for the delete page....Me stupid..!
<?php
include "config.php";
include "functions.php";





if(isset($_GET['id'])){

$query = "SELECT * FROM photo WHERE id = '" . $_GET['id'] . "'";
//echo $query;
$result = mysql_query($query)or die("Could not SELECT DELETE ENTRY because" . mysql_error());

if(mysql_num_rows($result)>0){

$row = mysql_fetch_array($result);

}else{

header("Location: photos.php");
}
}

if(isset($_POST['submit'])){

$name = mysql_real_escape_string($_POST['name']);
$description = mysql_real_escape_string($_POST['comments']);


$query = "DELETE photo SET name='$name', comments='$description'
WHERE id ='" . $_POST['delete_id'] . "'";
//echo $query;
mysql_query($query)or die("Could not DELETE ENTRY:" . mysql_error());
header("Location: photos.php?status=DELETED");

}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link href="../css/styleb.css" rel="stylesheet" type="text/css" />
<title>_ BACKHAND pour gerer photos |</title>


</head>

<body>
<div id="wrapper">
<div id="inside">



<h2>Delete Entry</h2>

<table>
<tr>
<th>Name</th>
<th>Comments</th>
<th></th>
</tr>
<tr>
<form action="<?=$_SERVER['PHP_SELF']?>" method="GET">
<td>
<input type="hidden" name="delete_id" value="<?=$row['id']?>" />
<input type="submit" name="delete" value="DELETE ENTRY" />
</form>
<br/>
<form action="photos.php" method="POST">
<input type="submit" name="cancel" value="CANCEL" />
</td>
</form>
</tr>




<?=$table_rows?>



</table>
</div>

</body>
Last edited by Jeune griot on Fri Jun 27, 2008 2:11 pm, edited 4 times in total.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: This is my first month with php and my first day in here...

Post by onion2k »

You don't appear to have any delete code in that script. That would explain why it doesn't work.
Jeune griot
Forum Newbie
Posts: 4
Joined: Fri Jun 27, 2008 1:10 pm

Re: This is my first month with php and my first day in here...

Post by Jeune griot »

Well the page u r actually seeing is my edit page wich is working... I did exactly the same for the delete one but it doesnt work. Does anyone can help me with a right way to do a delete page
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: This is my first month with php and my first day in here...

Post by onion2k »

Did you actually look up the syntax for a DELETE in SQL? What you have there should be..

Code: Select all

$query = "DELETE FROM photo WHERE id ='" . $_POST['delete_id'] . "'";
Jeune griot
Forum Newbie
Posts: 4
Joined: Fri Jun 27, 2008 1:10 pm

Re: This is my first month with php and my first day in here...

Post by Jeune griot »

this is the result on the
http:// .........../delete.php?delete_id=197&delete=DELETE+ENTRY

but it doesnt delete anything. I dont understand.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: This is my first month with php and my first day in here...

Post by califdon »

Read what onion2k just showed you. If your SQL syntax is incorrect, it's not going to work. What's to understand?
Jeune griot
Forum Newbie
Posts: 4
Joined: Fri Jun 27, 2008 1:10 pm

Re: This is my first month with php and my first day in here...

Post by Jeune griot »

Well thank you for the try but even that syntax doesnt work. Thank you all anyway.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: This is my first month with php and my first day in here...

Post by onion2k »

The problem is with your form.. you're submitting the delete request as GET, but in the PHP you check "if(isset($_POST['submit'])){". $_POST won't be set if you use a GET request.

Read this - http://www.ibm.com/developerworks/library/os-debug/ - It's a really good guide to tracking down problems in your scripts. Just ignore the stuff about Eclipse if you don't use that.
Post Reply