Member Avatar for Spik31

Hi all, I'm new and I currently am developing a website on fishing fred's fishing. The site is an experiment for a portfolio ect. There is a feature, the guestbook. The Guestbook is managed by a MySQL database and the PHP is responsible for creating and echoing the data. I would like it if i could remove a comment by having a cookie and clicking an image to remove a comment much like a delete button. The code below shows what I have written:

//Connecting to the database
$connect = mysql_connect("localhost","***","***")or die("Error Connecting.");
mysql_select_db("150742")or die("Error Selecting.");//selecting the data
//query for everything
$queryget = mysql_query("SELECT * FROM Guestbook") or die ("Error with query");
//using $row as an array for all of the data
while($row = mysql_fetch_assoc($queryget))
{
if($admin=="Yes"){//checking the user administrator privilages
	$name =$row['name'];
	$message =$row['message'];
	$date =$row['date'];
	$time =$row['time'];
	$id =$row['id'];
	strip_tags($message);//variables to collect the data
	echo"<hr/><p id='date'>$date $time</p><img src='images/delbutton.jpg' onClick=function delete()/><p id='post'> $name<br/>".strip_tags($message)."</p>";//echos each message in the database
	}else{//normal nonadmin comments
$name =$row['name'];
	$message =$row['message'];
	$date =$row['date'];
	$time =$row['time'];
	$id =$row['id'];
	strip_tags($message);
	echo"<hr/><p id='date'>$date $time</p><p id='post'> $name<br/>".strip_tags($message)."</p>";//echos each message in the database
	};
};

Hi - Can you tell us what is happening when you run this script. It looks like it 'could' work, but I think we need to see the "delete" function you call.

Member Avatar for Spik31

Thanks for replying and it currently doesn't refer to any function(Doesn't Exist yet) I was wondering if the JavaScript event could access the MySQL Server query commands. The image here(apologies if this violates any conditions) < the script in action (Currently) and I need help with using a button or image to query the MySQL database.

I'm sure there is a way to do it with javascript, but In my opinion you should create a delete script like delete.php

delete from guestbook where id =$id

Like this;

//Connecting to the database
$connect = mysql_connect("localhost","***","***")or die("Error Connecting.");
mysql_select_db("150742")or die("Error Selecting.");//selecting the data
//query for everything
$queryget = mysql_query("SELECT * FROM Guestbook") or die ("Error with query");
//using $row as an array for all of the data
while($row = mysql_fetch_assoc($queryget))
{
if($admin=="Yes"){//checking the user administrator privilages
	$name =$row['name'];
	$message =$row['message'];
	$date =$row['date'];
	$time =$row['time'];
	$id =$row['id'];
	strip_tags($message);//variables to collect the data
	echo"<hr/><p id='date'>$date $time</p><a href='delete.php?id=$id'><img src='images/delbutton.jpg'></a>
<p id='post'> $name<br/>".strip_tags($message)."</p>";//echos each message in the database
	}else{//normal nonadmin comments
$name =$row['name'];
	$message =$row['message'];
	$date =$row['date'];
	$time =$row['time'];
	$id =$row['id'];
	strip_tags($message);
	echo"<hr/><p id='date'>$date $time</p><p id='post'> $name<br/>".strip_tags($message)."</p>";//echos each message in the database
	};
};

Notice line 16 where I set the link to delete.php around the image.
Hope this helps.

Member Avatar for Spik31

It works :D Thanks so much ! (Blonde moment over)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.