Problem in the following code

someone can help me to get out from that problem.
given below code deletes from the mysql database if r is true also and if r is not true also
please see code and what is error please reply me
also i have included necessary files for mysql connection

<?php require_once(“…/…/includes/connection.php”); ?>
<?php require_once(“…/includes/functions.php”); ?>
if($_REQUEST[‘id’] != “”)
$articleid = $_REQUEST[‘id’];

		&lt;script language="javascript"&gt;
			var r=confirm("Are you sure you want to delete ?");
			if (r==true)
			 	document.write('&lt;? $query="SELECT * from procedures WHERE Id=$articleid"; ?&gt;'); 					 
				document.write("&lt;? $result1 = mysql_query($query); ?&gt;"); 
				document.write("&lt;? $row=mysql_fetch_array($result1); ?&gt;"); 
				document.write("&lt;? $pic=$row[picture];	?&gt;"); 				
				document.write("&lt;? unlink('pimages/'.$pic); ?&gt;"); 
				document.write('&lt;? $sql = "delete from procedures where Id=$articleid"; ?&gt;'); 
				document.write("&lt;? mysql_query($sql); ?&gt;"); 						                 
			    alert("Record has been deleted !");
			    window.location = "procedure.php";
			  alert("Deletion has been cancelled !");
			  window.location = "procedure.php";				  

hi rajug,
thanks for your code. finally a got to your code and how i wanted to delete, i was able to do that. full credit to to you, rajug.

Yes wherever it has been written in the page, if the script is in the PHP tag that will be executed. :slight_smile:

Ah yes, that’s true. The PHP commands in the write statements would be executed by the PHP parser before the page is sent to the client.

hello everybody,
how can i post a new post one. i have read other asking about the same question but i can’t find any new thread icon any where nor in thread nor in other places.

i want to post that i am having problem in fckeditor.

when i stored the text of fckeditor in mysql database. all the tags also will be stored. now what the problem is that i want to display only certain characters of fckeditor like 400 characters.

$query1=“select * from welcome order by id desc limit 1”;
echo mysql_error();

the above code gives the almost output what i want. but i am not getting 100% accurate answer. i want display 400 character excluding font tags like <p>, </p> and so on. but at displaying 400 characters, i want exzct format what is at original format such that original bold characters should be displayed as it is.

so please help me to do what i wanted to.

No Guido, the script deletes the record because the script says that If the ID is set in $_REQEST array then the following code everything will be executed in either case.

In your code, it will NEVER delete from the database, because javascript can’t delete anything from a server side database.
If your code does delete, then it isn’t the code you posted here.

i need to display alert message saying that “are you sure you want to delete ?”
if a user press OK then it should commit other if a user press cancel then it should not delete from the database.

but in my code, whatever the user press ie OK of Cancel, it would delete from the database.

why this is happened.

please reply me

Hi Kiran,

Welcome to the Sitepoint forums!

Seeing the code you have written, you seem to be very beginner in PHP. The way you have followed to delete a record in the database is wrong. It seems you are trying to delete a record with JavaScript.

I hope you can understand from the following code:

Your main listing file should look like this:
FIle 1 : list.php


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="" xml:lang="en" lang="en">
	<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
	<meta name="author" content="Raju Gautam" />
    <script type="text/javascript">
    function confirmDelete(){
        if(confirm('Are you sure you want to delete'))
            return true;
            return false;
        echo $_SESSION['msg'];
    <a onclick="return confirmDelete();" href="delete.php?id=2">Click to delete</a>

File 2 : delete.php



if(isset($_GET['id']) && !empty($_GET['id'])){
    $articleid = mysql_real_escape_string($_GET['id']);
    $result = mysql_query("SELECT picture FROM procedures WHERE Id=" . $articleid) or die(mysql_error());
    $row = mysql_fetch_array($result);
    $pic = $row['picture'];
    unlink('pimages/' . $pic);
    mysql_query("DELETE FROM procedures WHERE Id=" . $articleid) or die(mysql_error());
    $_SESSION['message'] = 'The record is deleted successfully.';
    header("Location: list.php");
    die('Invalid access');

Hope this will teach you a lot.

You can’t do it like that. PHP is executed server side (BEFORE the page is shown by the browser). Javascript is executed client side.
The PHP instructions written by your javascript will not be executed. You could use AJAX for that.

Common Kiran, did you try to see the code above I have given? The code I have written for you does what you exactly want.