How to Remove a Database Entry when a Link is Clicked
<p>I wanted to expand my PHP skills so I read through a tutorial on tutorialzine. I understand the instructions presented in the tutorial. But when it comes to expanding on it I seem to be lacking a connection. My main goal was to simply delete a selected note when an a tag is clicked. However I don't know how to select the id assigned to the note to be able to pass it to my delete function.</p>

<p>Source: <a href="http://tutorialzine.com/2010/01/sticky-notes-ajax-php-jquery/" rel="nofollow">http://tutorialzine.com/2010/01/sticky-notes-ajax-php-jquery/</a></p>

<p>Thanks for the help. </p>

<pre><code>&lt;?php
error_reporting(E_ALL^E_NOTICE);
require 'connect.php';
mysql_query("DELETE FROM notes WHERE id&gt;3 AND dt&lt;SUBTIME(NOW(),'0 1:0:0')");
$query = mysql_query("SELECT * FROM notes ORDER BY id DESC");

$notes = '';
$left='';
$top='';
$zindex='';

while($row=mysql_fetch_assoc($query)){
    list($left,$top,$zindex) = explode('x',$row['xyz']);
    $notes.= '
        &lt;div class="note '.$row['color'].'" style="left:'.$left.'px;top:'.$top.'px;z-index:'.$zindex.'"&gt;
            '.htmlspecialchars($row['text']).'
            &lt;div class="author"&gt;'.htmlspecialchars($row['name']).'&lt;/div&gt;
            &lt;span class="data"&gt;'.$row['id'].'&lt;/span&gt;
            &lt;a id="remove_note" href="javascript:;" onclick="deleteNote('&lt;? echo $row['id']; ?&gt;');"&gt;&amp;nbsp;&lt;/a&gt;
        &lt;/div&gt;';
}
function deleteNote(id){
    $sql="DELETE FROM notes WHERE id='$rows['id']'";
    $result=mysql_query($sql) or die("Error when tryin to delete note.");
}
?&gt;
</code></pre>

<p><strong>Update:</strong> </p>

<p>I've been playing around with this and the answers that both Andrew and sachleen have provided. And ill plan to work on an AJAX alternative since you've mentioned the whole SQL Injection issue. But I am still having issues with passing the id to the remove.php file. I believe is has to do with  how $notes is creating the information from the DB. </p>

<p>I say this because I get: Parse error: syntax error, unexpected T_STRING in /home/avonamyd/public_html/projects_php/sticky_notes/demo.php on line 24 </p>

<p>And that is only when I include the code as is from sachleen. But when I update it to account for the single quotes I have the following code. The id is present and is passed to the remove.php file but I am still getting an error. This is when I use my code or what you've provided. </p>

<pre><code>        $notes.= '
        &lt;div class="note '.$row['color'].'" style="left:'.$left.'px;top:'.$top.'px;z-index:'.$zindex.'"&gt;
            '.htmlspecialchars($row['text']).'
            &lt;div class="author"&gt;'.htmlspecialchars($row['name']).'&lt;/div&gt;
            &lt;span class="data"&gt;'.$row['id'].'&lt;/span&gt;
            &lt;a id="remove_note" target="_blank" href="remove.php?id='.$row['id'].'"&gt;&amp;nbsp;&lt;/a&gt;
        &lt;/div&gt;';
</code></pre>

<p>Below is what I currently have in my remove.php file:</p>

<pre><code>&lt;?php
include 'connect.php';
$_GET['id'];
function deleteNote($id){
    $sql="DELETE FROM notes WHERE id='$id'";
}
    $result=mysql_query($sql) or die("Error when tryin to delete note.");
</code></pre>

<p>?> </p>

<p><strong>Update</strong></p>

<p>I've added in additional echo lines throughout the remove.php and this is what I am coming up with. </p>

<pre><code>&lt;?php
include 'connect.php';
$_GET['id'];
echo  $id; --doesnt show
function deleteNote($id){
    echo "hello"; --doesnt show
    $sql="SELECT FROM notes WHERE id='$id'";
}
echo  'hello2'; --shows
$result=mysql_query($sql) or die("Error when tryin to delete note.");
</code></pre>

<p>?></p>

<p><strong>Update:</strong> 
Thank you for everyone's help with this project I've finally gotten the concepts to click in my head after some tinkering around. I will post the functional code below for anyone else that stumbles upon this code. =D
Thx Everyone!</p>

<p><strong>demo.php</strong></p>

<pre><code>    error_reporting(E_ALL^E_NOTICE);
require 'connect.php';
mysql_query("DELETE FROM notes WHERE id&gt;3 AND dt&lt;SUBTIME(NOW(),'0 1:0:0')");
$query = mysql_query("SELECT * FROM notes ORDER BY id DESC");

$notes = '';
$left='';
$top='';
$zindex='';

while($row=mysql_fetch_assoc($query)){
    list($left,$top,$zindex) = explode('x',$row['xyz']);
    $id = $row['id'];
    $notes.= '
        &lt;div class="note '.$row['color'].'" style="left:'.$left.'px;top:'.$top.'px;z-index:'.$zindex.'"&gt;
            '.htmlspecialchars($row['text']).'
            &lt;div class="author"&gt;'.htmlspecialchars($row['name']).'&lt;/div&gt;
            &lt;span class="data"&gt;'.$row['id'].'&lt;/span&gt;
            &lt;a id="remove_note" target="_blank" href="remove.php?id='.$row['id'].'"&gt;&amp;nbsp;&lt;/a&gt;
        &lt;/div&gt;';
}
</code></pre>

<p><strong>remove.php</strong></p>

<pre><code>&lt;?php
include 'connect.php';
$id = intval($_GET['id']);
$sql="DELETE FROM notes WHERE id=$id";
$result = mysql_query($sql) or die("Unable to delete database entry.");
</code></pre>

<p>?></p>
