Page 1 of 1

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

Posted: Fri Jun 27, 2008 1:19 pm
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>

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

Posted: Fri Jun 27, 2008 1:56 pm
by onion2k
You don't appear to have any delete code in that script. That would explain why it doesn't work.

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

Posted: Fri Jun 27, 2008 2:09 pm
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

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

Posted: Fri Jun 27, 2008 2:29 pm
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'] . "'";

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

Posted: Fri Jun 27, 2008 2:52 pm
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.

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

Posted: Fri Jun 27, 2008 7:27 pm
by califdon
Read what onion2k just showed you. If your SQL syntax is incorrect, it's not going to work. What's to understand?

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

Posted: Sat Jun 28, 2008 4:10 pm
by Jeune griot
Well thank you for the try but even that syntax doesnt work. Thank you all anyway.

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

Posted: Sun Jun 29, 2008 3:34 am
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.