Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting a form to delete a MySQL record

Status
Not open for further replies.

BadChough

Programmer
Dec 20, 2007
137
GB
I'm back again!
This time I have problems getting my form to delete records.
I'm trying to select the record to be deleted with the use of a Select List, and try as I have over the past few hours I cannot make it function.
It's time, I said to myself, to ask for help.
Here's some php code:

PHP:
<?php $writer = $_SESSION['MM_Username'];  //Variable set to select correct Record (below)

mysql_select_db($database_tormented3, $tormented3);
$query_rstAut = "SELECT * FROM authors WHERE username = '$writer'";
$rstAut = mysql_query($query_rstAut, $tormented3) or die(mysql_error());
$row_rstAut = mysql_fetch_assoc($rstAut);
$totalRows_rstAut = mysql_num_rows($rstAut);

mysql_select_db($database_tormented3, $tormented3);
$query_rstFeed = "SELECT * FROM authfeed WHERE username = '$writer' ORDER BY authfeed.pk";
$rstFeed = mysql_query($query_rstFeed, $tormented3) or die(mysql_error());
$row_rstFeed = mysql_fetch_assoc($rstFeed);
$totalRows_rstFeed = mysql_num_rows($rstFeed);


if ((isset($_POST['pk'])) && ($_POST['pk'] != "") && (isset($_POST['form1']))) {  //deletion sequence
  $deleteSQL = sprintf("DELETE FROM authfeed WHERE pk=%s",
                       GetSQLValueString($_POST['pk'], "int"));

  mysql_select_db($database_tormented3, $tormented3);
  $Result1 = mysql_query($deleteSQL, $tormented3) or die(mysql_error());

  $deleteGoTo = "list.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
    $deleteGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $deleteGoTo));
}
?>

And here's the form:

PHP:
  <form name="form1" method="POST">
            <p>&nbsp;</p>
		  <p>
		    <select name="pk" size="1" id="pk">
		      <?php
do {  
?>
		      <option value="<?php echo $row_rstFeed['pk']?>"<?php if (!(strcmp($row_rstFeed['pk'], $row_rstFeed['pk']))) {echo "SELECTED";} ?>><?php echo $row_rstFeed['pk']?></option>
		      <?php
} while ($row_rstFeed = mysql_fetch_assoc($rstFeed));
  $rows = mysql_num_rows($rstFeed);
  if($rows > 0) {
      mysql_data_seek($rstFeed, 0);
	  $row_rstFeed = mysql_fetch_assoc($rstFeed);
  }
?>
		      </select> 
		    <span class="red_text">First - </span> <span class="red_text">Select the number  of the comment to be deleted as given on the pubished page. (Please  check  carefully)</span></p>
		  <p class="red_text"> Next  - Click the Submit button  to permenantly delete the comment: </p>
		  <p>
              <input type="submit" name="Submit" value="Submit">
<input name="username" type="hidden" id="username" value="<?php echo "$writer";?>">
		      </form></p></td>

I wonder if you can tell me why clicking the button fails to delete the record for me.
Thanks for looking.
 
at first glance I cannot see a field with the name 'form1' in the form. and yet you are testing for that condition.

rather the building your own framework have you considered using something simple like wordpress?

 
Hello jpadie.
I haven't moved with the times, I know, and still use DreamweaverMX2004 to help me work with websites.
I suppose I enjoy the challenge, and certainly can't afford the latest Dreamweaver.
However, I only very occasionally make a website, so I won't be on your back like this very often, and appreciate your help from time to time when things just don't work as I think they should.

On this occasion I see 'form name="form1"' in the first line of the second tranche of code. Did you miss that, or are you referring to something else?
 
Yes. I saw that.
But only form controls are submitted by browsers.

The form itself is not a control.
 
Of course! Very stupid of me.
Many thanks. That's sorted it.
Because I so rarely deal with forms I forget the basics.
 
I haven't moved with the times, I know, and still use DreamweaverMX2004 to help me work with websites.
I suppose I enjoy the challenge, and certainly can't afford the latest Dreamweaver.

You don't need Dreamweaver (old or new) to work with WordPress/Joomla/Drupal/etc. Nor do you need to afford software. These are all free content management systems.

Building your own content management system is a good practical way to learn PHP. But if your primary goal is not a learning exercise, you might as well go with a CMS that is developed by thousands of developers.
 
Thanks for the tip, japadie.
I think for me, as a retired bloke, the challenge of getting php/html to do my bidding is an important part of the hobby.
I do learn a bit each time I create a new page, and I learn from people like yourself for whom these languages have become second nature.
I'm also learning Spanish, so I guess that for me there's a special appeal about learning new languages.
Best wishes.
 
bienvenido! but I think your comment might be aimed at Jim?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top