Jump to content

Recommended Posts

Hey guys, i'm trying to find out how to get this to work. You type in a name of a record in the database and it removes it.

In this case it's deleting the record that when you type in the name of the server it looks for it in the column "servername". You type in the servername and it will delete the whole record.

 

deletionform.html

<form method="POST" action="scrimdelete.php">
  <label>Type name of server you wish to delete: <br />
  <input name="textfield" type="text" id="textfield" size="40" />
  </label>
  <input type="button" value="Submit" />
</form>

 

scrimdelete.php

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

mysql_query("DELETE FROM **** WHERE servername='*****");

mysql_close($con);
?> 

 

Can anyone fix it up for me?

 

Jono

 

Link to comment
https://forums.phpfreaks.com/topic/73138-solved-mysql-delete-from-a-form/
Share on other sites

I have noticed a minor problem in it, but this may not make any difference at all.

try it anyway.

 

change this line:

<?php
mysql_query("DELETE FROM **** WHERE servername='*****");

 

to this:

<?php
mysql_query("DELETE FROM **** WHERE servername='*****'");

you missed out the second ' after servername.

 

see if that helps.

 

Regards ACE

Add the following.

 

Before all code at the top

error_reporting(E_ALL);

 

For all mysql queries, add the die(mysql_error()); at the end

mysql_query($sql) or die(mysql_error());

 

Your code looks like this (changed a bit, no more if/else :-D

 

<?php
error_reporting(E_ALL);
$con = mysql_connect("localhost","*****","******") or die('Could not connect: '.mysql_error());
mysql_select_db("******", $con);
mysql_query("DELETE FROM **** WHERE servername='*****") or die(mysql_error());
mysql_close($con);
?> 

Nope, that didn't do it.

It's from a form, so basically it looks like this:

<?php
error_reporting(E_ALL);
$con = mysql_connect("localhost","*****","******") or die('Could not connect: '.mysql_error());
mysql_select_db("******", $con);
mysql_query("DELETE FROM alpha_scrims WHERE servername='"$_POST["servername"]"") or die(mysql_error());
mysql_close($con);
?> 

Is the $_POST bit correct? The text field on the previous page is called servername.

Oh.. Now I see. It's your method of echoing the variables.

 

mysql_query("DELETE FROM alpha_scrims WHERE servername='"$_POST["servername"]"") or die(mysql_error());

 

Change this to:

mysql_query("DELETE FROM alpha_scrims WHERE servername='$_POST[servername]' ") or die(mysql_error());

 

 

Didn't work, but this time it came up with this:

I type in Jon into the box to delete the record that has servername Jon.

 

Unknown column 'Jon' in 'where clause'

 

i'm using this:

<?php
error_reporting(E_ALL);
$con = mysql_connect("localhost","**","**") or die('Could not connect: '.mysql_error());
mysql_select_db("**", $con);
mysql_query("DELETE FROM alpha_scrims WHERE servername=$_POST[servername]") or die(mysql_error());
mysql_close($con);
echo "<center>Record Deleted.";
echo "<center><a href=admin.php>Back</a>";
?>

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.