Jump to content

[SOLVED] Simple Delete Problem. What am i doing wrong?


dre

Recommended Posts

hey, i aint to sure where im going wrong with this so if any body can be kind enough to help i would gratly appriciate it!

 

i have a database of phones and i want the user to be able to delete the chosen model by entering the phone id.

 

 <form name="form3" method="post" action="">
    <input type="text" name="texto">
<?php

$db = mysql_connect("localhost", "project", "ramix"); 
mysql_select_db("phone",$db); 
if($_POST["d1"]=="delete")
$query= "DELETE FROM phone_details WHERE phone_id='$texto'";
$result = mysql_query( $query );

?>
<input type="submit" name="d1" value="delete">
  </form>

vulnerable to sql injection...

 

<form name="form3" method="post" action="">
    <input type="text" name="texto">
<?php

$db = mysql_connect("localhost", "project", "ramix"); 
mysql_select_db("phone",$db); 
if($_POST["d1"]=="delete")
$query= "DELETE FROM phone_details WHERE phone_id='{$_POST['texto']}'";
$result = mysql_query( $query );

?>
<input type="submit" name="d1" value="delete">
  </form>

That's some goofy code. There's no 'action' defined in your form. The php code should be either ahead of your HTML or in a separate file even, depending upon how you want the form to work. It can either submit to itself or submit to another page that parses the input.

 

You also need to declare your 'texto' variable like this:

 

$texto = $_POST['texto'];

 

just above your mysql info.

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.