NoDoze Posted December 1, 2006 Share Posted December 1, 2006 How do you do it?I have this much so far:[code]<span class="txt-ast">*</span>Project Number: <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... Quote Link to comment https://forums.phpfreaks.com/topic/29152-delete-row-via-php-form/ Share on other sites More sharing options...
Philip Posted December 1, 2006 Share Posted December 1, 2006 [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. Quote Link to comment https://forums.phpfreaks.com/topic/29152-delete-row-via-php-form/#findComment-133697 Share on other sites More sharing options...
NoDoze Posted December 1, 2006 Author Share Posted December 1, 2006 No error....But still not deleteing the row... Quote Link to comment https://forums.phpfreaks.com/topic/29152-delete-row-via-php-form/#findComment-133716 Share on other sites More sharing options...
NoDoze Posted December 4, 2006 Author Share Posted December 4, 2006 bump. Quote Link to comment https://forums.phpfreaks.com/topic/29152-delete-row-via-php-form/#findComment-135112 Share on other sites More sharing options...
sanfly Posted December 4, 2006 Share Posted December 4, 2006 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: <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] Quote Link to comment https://forums.phpfreaks.com/topic/29152-delete-row-via-php-form/#findComment-135140 Share on other sites More sharing options...
NoDoze Posted December 4, 2006 Author Share Posted December 4, 2006 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: <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: <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: <input name="resposible_individual" type="text" class="txtbox" size="3" maxlength="3"><font size="1"><span class="style1"> ( max 3 characters )</span></font></td></tr><tr><td colspan="2"><span class="txt-ast">*</span>Project Description: <input name="project_description" type="text" class="txtbox" size="30" maxlength="30"><font size="1"><span class="style1"> ( max 30 characters )</span></font></td></tr><tr><td colspan="2"><span class="txt-ast">*</span>County: <input name="county" type="text" class="txtbox" size="30" maxlength="30"><font size="1"><span class="style1"> ( max 30 characters )</span></font></td></tr><tr><td height="32" colspan="2">State, City, River Basin: <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: <input name="client" type="text" class="txtbox" size="30" maxlength="30"><font size="1"><span class="style1"> ( max 30 characters )</span></font></td></tr><tr><td colspan="2" align="left" valign="top"> </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] Quote Link to comment https://forums.phpfreaks.com/topic/29152-delete-row-via-php-form/#findComment-135192 Share on other sites More sharing options...
NoDoze Posted December 5, 2006 Author Share Posted December 5, 2006 "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... Quote Link to comment https://forums.phpfreaks.com/topic/29152-delete-row-via-php-form/#findComment-135199 Share on other sites More sharing options...
trq Posted December 5, 2006 Share Posted December 5, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/29152-delete-row-via-php-form/#findComment-135203 Share on other sites More sharing options...
sanfly Posted December 5, 2006 Share Posted December 5, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/29152-delete-row-via-php-form/#findComment-135211 Share on other sites More sharing options...
NoDoze Posted December 5, 2006 Author Share Posted December 5, 2006 Ahhhh.....okie dokie....I think I get it now....It makes sense...I was just hoping it could be done from within the same page...I'm going to fiddle with it, and see if I could get it to work...I'll let ya know how it goes.... Quote Link to comment https://forums.phpfreaks.com/topic/29152-delete-row-via-php-form/#findComment-135218 Share on other sites More sharing options...
NoDoze Posted December 5, 2006 Author Share Posted December 5, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/29152-delete-row-via-php-form/#findComment-135222 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.