PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old April 23rd, 2004, 07:53 PM
Cliekid Cliekid is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 4 Cliekid User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #2  
Old April 24th, 2004, 03:19 PM
edwinbrains's Avatar
edwinbrains edwinbrains is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: UK
Posts: 160 edwinbrains User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 h 5 m 50 sec
Reputation Power: 5
moved...

What line are you getting the parse errors on?

Reply With Quote
  #3  
Old April 25th, 2004, 06:45 AM
fizker fizker is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: denmark
Posts: 42 fizker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 18 m 18 sec
Reputation Power: 5
Send a message via MSN to fizker
the error originates in the mysql_query that deletes. your WHERE part is not formulated correct, since the variable $deleteid is not a number, but an array. and since it is exactly the same number as you get from your post, i would recommend rewriting that entire block as:
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");
$sql ="DELETE FROM news WHERE news_id = '$_POST[test]'";
if (
mysql_affected_rows() < 1) {
// there was either 0 rows deleted or an error ('mysql_affected_rows() == -1' means error)
}
else if(
mysql_affected_rows() == 1)
{
// we only want to delete one row. who knows, something unforeseen might happen
echo ("News Article Succesfully Deleted!"); }
?>
__________________
Benjamin Horsleben
horsleben.com/benjamin
Don't blame malice for what stupidity can explain

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > PHP Select Form / Delete Help...


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Iron Speed




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway