Author Topic: Delet from a server using php  (Read 339 times)

Nicolai

  • Guest
Delet from a server using php
« on: June 15, 2012, 08:56:54 AM »
hey there im wanting to delete from my database using php im new to php and would like help
this is my 2 pages
remove_data.php:
Code: [Select]
Code: [Select]
<html>
<body>
<?php

include 'config.php';
include 
'navigator.php';
 
?>

<table width="50%" border="1">
    <tr>
        <td>Navn</td>
        <td>Placering</td>
<td>Type</td>
<td>Andet</td>
<td>ID</td>
    </tr>
<?php
$result 
mysql_query("select * from `ting` ORDER BY  `ting`.`id` ASC "); 

while (
$row mysql_fetch_array($result)) { 
  echo    
"<tr>\n";
  
echo "<td>"$row['navn']."</td>\n";
  
echo "<td>"$row['placering']."</td>\n";
  
echo "<td>"$row['type']."</td>\n";
  
echo "<td>"$row['andet']."</td>\n";
  
echo "<td>"$row['id']."</td>\n";
  echo    
"</tr>\n";
}
?>

<form action="remove.php" method="post">
Fjern Ting: <input type="int" name="id" />
<input type="submit" />
</body>
</html>

remove.php:
PHP Code: [Select]
<?php
include 'config.php';

$sql="DELETE FROM ting (id)
VALUES
('
$_POST[id]')";

if (!
mysql_query($sql,$con))
  {
  die(
'Error: ' mysql_error());
  }
echo 
"1 record deleted </br>";
echo 
"<a href=index.php>Hjem</a>";

mysql_close($con);
?>


thank you for your help

RaythXC

  • PHP Programmer & Web-Designer
  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 395
  • Karma: 10
  • Freelance PHP Programmer/Web-Designer
    • View Profile
    • Rayth.Info
Re: Delet from a server using php
« Reply #1 on: June 15, 2012, 09:51:27 AM »
your MySQL delete query is wrong. It should be in the following syntax:

DELETE FROM table WHERE field=value

In your case:

DELETE FROM ting WHERE id=$_POST['id']
RaythXC - My Home Site
Note: most answers I give come from the php manual located at PHP.Net

neobonde

  • New Member
  • *
  • Posts: 2
  • Karma: 0
    • View Profile
Re: Delet from a server using php + im OP
« Reply #2 on: June 15, 2012, 10:34:17 AM »
can you tell me how to put it into what i currently got, because i have no clue ;)

RaythXC

  • PHP Programmer & Web-Designer
  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 395
  • Karma: 10
  • Freelance PHP Programmer/Web-Designer
    • View Profile
    • Rayth.Info
Re: Delet from a server using php
« Reply #3 on: June 15, 2012, 11:32:56 AM »
In your second code you have $sql="DELETE..." just replace the bit in quotes with what I put.
RaythXC - My Home Site
Note: most answers I give come from the php manual located at PHP.Net

neobonde

  • New Member
  • *
  • Posts: 2
  • Karma: 0
    • View Profile
Re: Delet from a server using php
« Reply #4 on: June 15, 2012, 11:36:00 AM »
still not working this is the error
Quote
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/a9119823/public_html/remove.php on line 4
line 4 is where your code is

RaythXC

  • PHP Programmer & Web-Designer
  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 395
  • Karma: 10
  • Freelance PHP Programmer/Web-Designer
    • View Profile
    • Rayth.Info
Re: Delet from a server using php
« Reply #5 on: June 15, 2012, 12:31:39 PM »
what exactly is line 4. It looks like you've missed something in the switch
RaythXC - My Home Site
Note: most answers I give come from the php manual located at PHP.Net