Jump to content

Recommended Posts

How do you do it?

I have this much so far:
[code]
<span class="txt-ast">*</span>Project Number:&nbsp;
<select name="project_number" class="txtbox">
  <option value="1" selected></option>
<?php
$result = mysql_query("SELECT * FROM projnum");
while($row = mysql_fetch_array($result))
{
    echo '<option value="' . $row['project_number'] . '"> ' . $row['project_number'] . "</option>\n  ";
}
mysql_query("DELETE FROM projnum WHERE project_number='$project_number'");
?>
</select>
[/code]

But it's not deleting it...
Link to comment
https://forums.phpfreaks.com/topic/29152-delete-row-via-php-form/
Share on other sites

[code]<?php
$result = mysql_query("SELECT * FROM projnum");
while($row = mysql_fetch_array($result))
{
    echo '<option value="' . $row['project_number'] . '"> ' . $row['project_number'] . "</option>\n  ";
}
mysql_query("DELETE FROM projnum WHERE project_number='$project_number'") or die(mysql_error());
?>[/code]

Check to make sure you're not getting an error there.
Can you post your <form> tags?  Does it post to the same page?  The delete query should be before the select query if it is posting to the same page.

Something like this should get you on the right track:

[code=php:0]<?php // Get Posted Variables (if submitted)
$project_number = $_POST['project_number'];
// Delete project if it exists
if($project_number){
mysql_query("DELETE FROM projnum WHERE project_number='$project_number'") or die(mysql_error());
}
?>

<form method="post" action="thisPage.php">
<span class="txt-ast">*</span>Project Number:&nbsp;
<select name="project_number" class="txtbox">
<option value="1" selected></option>
<?php
$result = mysql_query("SELECT * FROM projnum") or die(mysql_error());
while($row = mysql_fetch_array($result)){
  echo '<option value="' . $row['project_number'] . '"> ' . $row['project_number'] . "</option>\n  ";
} ?>
</select><br>
<input type="submit" value="DELETE PROJECT">
</form>[/code]
Ok, hee is the entire form:

[code]
<form action="/distribution/phorm.php" method="post" name="form">
<table width="800" border="0">
<tr>
<td colspan="2"><span class="txt-ast">*</span>Initiation Date:&nbsp;
<input name="date" type="text" class="txtbox" size="11" maxlength="11" value="<?php echo date('m-d-Y');?>">
</td>
</tr>
<tr>
<td width="273">
<span class="txt-ast">*</span>Project Number:&nbsp;
<select name="project_number" class="txtbox">
  <option value="1" selected></option>
<?php
$result = mysql_query("SELECT * FROM projnum");
while($row = mysql_fetch_array($result))
{
    echo '<option value="' . $row['project_number'] . '"> ' . $row['project_number'] . "</option>\n  ";
}
mysql_query("DELETE FROM projnum WHERE project_number = 'project_number'") or die(mysql_error());
?>
</select>
</td>
<td width="517"><span class="txt-ast">*</span>Responsible Individual:&nbsp;
<input name="resposible_individual" type="text" class="txtbox" size="3" maxlength="3"><font size="1"><span class="style1">&nbsp; ( max 3 characters )</span></font></td>
</tr>
<tr>
<td colspan="2"><span class="txt-ast">*</span>Project Description:&nbsp;<input name="project_description" type="text" class="txtbox" size="30" maxlength="30">
<font size="1"><span class="style1">&nbsp; ( max 30 characters )</span></font></td>
</tr>
<tr>
<td colspan="2"><span class="txt-ast">*</span>County:&nbsp;<input name="county" type="text" class="txtbox" size="30" maxlength="30"><font size="1"><span class="style1">&nbsp; ( max 30 characters )</span></font></td>
</tr>
<tr>
<td height="32" colspan="2">State, City, River Basin:&nbsp;
<input name="region" type="text" class="txtbox" size="30" maxlength="30"></td>
</tr>
<tr>
<td height="32" colspan="2"><span class="txt-ast">*</span>Client:&nbsp;<input name="client" type="text" class="txtbox" size="30" maxlength="30"><font size="1"><span class="style1">&nbsp; ( max 30 characters )</span></font></td>
</tr>
<tr>
<td colspan="2" align="left" valign="top">&nbsp;</td>
</tr>
<tr>
<td colspan="2">
<center>
<INPUT TYPE=HIDDEN NAME="PHORM_CONFIG" VALUE="pilconfig.php">
<input name="add" type="submit" id="add" value="Add New Project">
</center>
</td>
</tr>
<tr>
<td colspan="2">
<center>
<span class="txt-ast">* <font size="1">are field that MUST be completed.</font></span>
</center>
</td>
</tr>
</table>
</form>
[/code]
"delete query should be before the select query"

How do I delete the project number BEFORE they have chosen one?

They need to choose one first, then when the form is submited, the project number chosen gets deleted from the project list table...and the form is submited to the project database with the active project number.

I need it to work so that the same project number isn't chosen twice.

The inactive project numbers are listed in a table list called projnum.
But the form submition is to add a project to the project database.
The available numbers ar pulled from projnum, then submited to the project database. IE: two different tables.

Does my explaination make sense now? I'm not even sure if this is the correct way to go about this....I thought it was the simplist way to do it...
Im not sure where your getting your logic from here, but its way off base. Your form needs to submit to another page (could be done in one but easier to explain in two) where the DELETE statement will then run. Something like...

[code]
<?php
  if (isset($_POST['submit'])) {
    mysql_query("DELETE FROM projnum WHERE project_number = '{$_POST['project_number']}'") or die(mysql_error());
  }
?>
[/code]
Note the whole sentence

[quote]The delete query should be before the select query [color=red]if it is posting to the same page[/color][/quote]

You need to submit the form with the project ID selected before you can delete the row.  IE: Processed on the next page. PHP is a server side language so you need to send the query back to the server and process the response the server gives you.

What is the name of the page that this form is on?  Is it phorm.php as well?  If so, the delete query needs to go with the rest of the code that you use to process the form, it CANNOT go within the form. 

If you are still confused, post the form processing script as well and I will try and show you what I mean

Yeah, it's actually a really complicated form submittion as it is....

The form first submits the data to the project database, then gets forwarded to a cgi script to email the contents to two email addresses....So with also the delete step, this form will be submited 3 times total to different locations...argh...

I was hoping to simplify it....but looks like it'll have to be this way... heh.
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.