×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Getting a form to delete a MySQL record

Getting a form to delete a MySQL record

Getting a form to delete a MySQL record

(OP)
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:

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:

CODE --> php

<form name="form1" method="POST">
            <p> </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.

RE: Getting a form to delete a MySQL record

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?

RE: Getting a form to delete a MySQL record

(OP)
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?

RE: Getting a form to delete a MySQL record

Yes. I saw that.
But only form controls are submitted by browsers.

The form itself is not a control.

RE: Getting a form to delete a MySQL record

(OP)
Of course! Very stupid of me.
Many thanks. That's sorted it.
Because I so rarely deal with forms I forget the basics.

RE: Getting a form to delete a MySQL record

Quote:

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.

RE: Getting a form to delete a MySQL record

(OP)
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.

RE: Getting a form to delete a MySQL record

bienvenido! but I think your comment might be aimed at Jim?

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close