This is my first thread on sitepoint, so don’t be too rough
The thing is, i’m trying to figure out how i can delete a post from a shoutbox. I’ve manangede to put the submitters IP into my db, with the post and id.
This is how i’ve done (dosen’t work thou):
$ipadress = users ip
$ip = Ipadress storred in db
$id = auto_increment number on posts
the delete call is going to call a JavaScript function, not PHP. In order to do delete the message upon clicking the input you would either need to submit a form and call the PHP function than, pass a variable through a query string or have the delete JavaScript function do a AJAX request to call the server side script to delete the item.
You made that sound really easy oddz. So you are suggesting that instead of using a onclick, i give it a name, create a if(isset($_POST[‘name’])){ delete the post } ?
if($ipaddress == $ip){
$connect = mysql_connect($host,$username,$password) or die('
Unable to connect to the database server at this time.');
mysql_select_db($database,$connect) or die('
Unable to connect to the database at this time.');
if(isset($_POST['delete'])){
mysql_query("DELETE FROM shoutbox WHERE id='.$id.'");
}
?>
<input type="button" name="delete" value="Delete" />
<?php
Again, I’m no pro so please correct me if I’m mistaken
The problem you run into with inputs is that the value needs to be the label. So the solution is to use the id as the key.
<?php
if($ipaddress == $ip){
$connect = mysql_connect($host,$username,$password) or die('
Unable to connect to the database server at this time.');
mysql_select_db($database,$connect) or die('
Unable to connect to the database at this time.');
if(isset($_POST['delete']) && !empty($_POST['delete'])){
mysql_query('DELETE FROM shoutbox WHERE id='.mysql_real_escape_string(array_pop($_POST['delete'])));
}
?>
<input type="button" name="delete[<?php echo $id; ?>]" value="Delete" />