0

please can any1 tell me what is the problem with this delete code??

<?php
$con = mysql_connect("localhost","username","pswd");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("dbname", $con);
$val=$_GET['teachers'];
mysql_query("DELETE FROM teacher WHERE title='$val'");
 
mysql_close($con);
?>
6
Contributors
13
Replies
14
Views
7 Years
Discussion Span
Last Post by Manuz
0

It seems that there is not problem in the query. what error or message u are getting?

To actually delete the record you must pass whole title into $_GET.

0

its displayin record deleted bt in the database its not deleting

0

Test1: (echo the result of $val)

$val=$_GET['teachers'];
[B]echo $val;[/B]

Test2:

DELETE FROM teacher WHERE title='maths'

Check the query directly in your phpadmin I mean your sql editor. If record is removed then problem is in php. If not then in sql query.

0

Post your code of where do you get the teachers from.

Your submit form should have the method="get" and should have the name "teacher" for your textbox or some element. and also you can check it in the url display have as ?teacher="radha" Post your code of html.

Edited by rajarajan07: n/a

0
<html>
<body>
<table>

<tr><td>;

<font color="white">Select Teacher's Name</font></td>

<td> <font color="white"><select name="teachers" >
  <option value="1">abc </option>
  <option value="2">pqr </option>
  <option value="3">xyz </option>
 
</select></font>';
</td></tr>
<tr>
<td>


<form  method = "POST" action = "deleteteacher.php">
<p>
<input type ="submit" value="Delete"  /> 
<br />
</p>
</form>
</td>
</tr>
</table>
</body>
</html>

Edited by maunica: n/a

0

according to your code your final query will be like

delete from teacher where title ='1'

As you option value is 1,2,3.

Are you sure your title columns holds numerice values or you have any other id field.

0

simple thing has to be changed:

<form  method = "POST" action = "deleteteacher.php">

instead

<form  method = "GET" action = "deleteteacher.php">

It will work.

0

Hey,

Do the change as said by Raja and one more thing to change.
Check out the html page.The form tag begins after the select tag.Place your form tag above your select element.

0

No please don't do that.
Just change: $val=$_GET['teachers']; to $val=$_POST['teachers']; Sending parts of a delete-query in the address-bar of your browser is not a good idea! What would happen if someone changed the _GET var in the address-bar to 1=1 ?? Your entire table-contents will be deleted.. Ever heard of sql-injection?

Edited by n_e: n/a

0

No please don't do that.
Just change: $val=$_GET['teachers']; to $val=$_POST['teachers']; Sending parts of a delete-query in the address-bar of your browser is not a good idea! What would happen if someone changed the _GET var in the address-bar to 1=1 ?? Your entire table-contents will be deleted.. Ever heard of sql-injection?

Ya... That is a gud move about $_post option...but do not forgot to place the form tag above the select element...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.