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>

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.