
April 23rd, 2004, 07:53 PM
|
|
Registered User
|
|
Join Date: Apr 2004
Posts: 4
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
PHP Select Form / Delete Help...
Greets,
I have this form, where it deletes via news_id. I use a select box modified with PHP, but I constantly get Parse errors. I need it to display all the data I query, and I want it so when it deletes, it deletes with the news_id of the News article selected. The code is:
PHP Code:
<HTML> <Body> <form action="http://cixio.com/corporate/testdelete.php"> <?php $dbh=mysql_pconnect ("localhost", "cliekid", "clienr70v") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("cliekid_admin"); $sql = "SELECT * FROM news"; $result = mysql_query($sql); $endselect = "</SELECT>"; $select = "<SELECT name=\"test\">"; echo ("".$select.""); $submit = "<BR><input type=\"submit\" value=\"Delete News\">"; while ($row = mysql_fetch_array($result)) { $option = "<option value=\"".$row[news_id]."\" />".$row[news_name]." - ".$row[news_date]." - By: ".$row[news_writer]." - News ID: ".$row[news_id].""; echo ("".$option.""); } echo ("".$endselect."".$submit.""); ?> </form> </Body> </HTML>
Adn now to my Delete problem. My delete code will be shown below this, but..it doesnt seem to well, want to delete even if it echoes that its done it! Heres the code:
PHP Code:
<?php $dbh=mysql_pconnect ("localhost", "cliekid", "clienr70v") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("cliekid_admin"); $deleteid ="SELECT news_id FROM news WHERE news_id = '$_POST[test]'"; $result = mysql_query($deleteid); $sql ="DELETE FROM news WHERE news_id = '$deleteid'"; $result = mysql_query($sql); if (!$result) { die('Invalid SQL!: ' . mysql_error()); } else { echo ("News Article Succesfully Deleted!"); } ?>
Any help for corrections would be great! Thanks!!
-Cliekid
Last edited by Cliekid : April 23rd, 2004 at 07:59 PM.
Reason: Updated Code
|