Jump to content

Why Delete Doesnt Work? Help please


princeofpersia

Recommended Posts

Hi, Im using a button to delete each entry from my database, however it doesnt. I have tried it with linking to a delete page and works fine with the same mysql query, but i need to hve the button to delete and not a URL.

 

Can someone please help me to see what is wrong?

 

thanks in advance guys

 

<?php

include ("../include/global.php");
include ("../include/function.php");

if (loggedin()==FALSE)
{
Header("Location: ../login.php");
exit();
}

$_SESSION['username']=='$username';
$username=$_SESSION['username'];

$getid=mysql_query("SELECT id FROM users WHERE username='$username'");
while($row=mysql_fetch_array($getid))
{
$usersid=$row['id'];
}


if (isset($_POST['add']) && $_POST['add'])
    {

$subject = addslashes(strip_tags($_POST['subject']));
$text = addslashes(strip_tags($_POST['text']));

$update=mysql_query("INSERT INTO users_notes (user_id, subject, note) VALUES ('$usersid','$subject','$text')");
}

if (isset($_POST['remove']) && $_POST['remove'])
    {

	$delete=mysql_query("DELETE FROM users_notes WHERE user_id='$usersid' AND  AND id='$id'");
}
?>

<html>
<head>
<script type="text/javascript" src="/js/jquery.js"></script>
<script type="text/javascript" src="/js/jquery.validate.js"></script>


<script type="text/javascript">
$(document).ready(function(){

		$("#form").validate();

		});
</script>
</head>
<body>

<p>You are logged in! <a href="logout.php">Log out</a>
  
</p>
<p> </p>
<p><td><? $getmsg=mysql_query("SELECT * FROM users_notes WHERE user_id='$usersid'");
while($row=mysql_fetch_array($getmsg))
{
$id=$row['id'];
$msgsubject=$row['subject'];
$msgnotes=$row['note'];

echo"<table width='800' border='1'>";
echo" <tr>

    <td width='50'>".$msgsubject."</td>
    <td width='50'>".$msgnotes."</td>

    <td width='40'><form id='form' method='post' action=''>

      <input type='submit' name='remove' value='remove' />

      </form></td>
  <td>
  
  </td>
  </tr>
  ";

}

echo "</table>";
?>
</td>
</p>
<p> </p>
<form action="" method="POST" id="form">
  <p>
  Subject: <br/>
    <input type="text" name="subject" class="required">
  </p>
  <p>
Your Note: <br/>
    <textarea name="text" id="text" cols="45" rows="15" class="required"></textarea>
  </p>
  <p>
    <input type="submit" name="add" value="Add" >
  </p>
</form>
</body>



Link to comment
https://forums.phpfreaks.com/topic/224862-why-delete-doesnt-work-help-please/
Share on other sites

I see 2 issues that stick out:

 

This will literally assign the string '$username' to sessions which ultimately is searched for in your query and it won't find anything.

$_SESSION['username']=='$username';

 

In your DELETE query you have:

AND  AND id='$id'");

which is incorrect syntax.

 

thats the id for msg note, its in the php inside the html

 

<p> </p>
<p><td><? $getmsg=mysql_query("SELECT * FROM users_notes WHERE user_id='$usersid'");
while($row=mysql_fetch_array($getmsg))
{
$id=$row['id'];
$msgsubject=$row['subject'];
$msgnotes=$row['note'];

echo"<table width='800' border='1'>";
echo" <tr>

    <td width='50'>".$msgsubject."</td>
    <td width='50'>".$msgnotes."</td>

    <td width='40'><form id='form' method='post' action=''>

      <input type='submit' name='remove' value='remove' />

      </form></td>
  <td>
  
  </td>
  </tr>
  ";



Did you fix this issue?

$_SESSION['username']=='$username';

 

1) You're using comparison, so you never assign that session variable to anything.

2) Even if you used assignment (=) you would be assigning the literal string '$username' and NOT the variable's value.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.