Current location: Hot Scripts Forums » Programming Languages » PHP » [SOLVED] Php Loop :S


Php Loop :S

Closed Thread
  #1 (permalink)  
Old 11-16-09, 06:10 AM
smithygotlost smithygotlost is offline
Aspiring Coder
 
Join Date: Jul 2006
Location: United Kingdom
Posts: 412
Thanks: 12
Thanked 3 Times in 3 Posts
Php Loop :S

Heya guys

Ok this is probally simple but ive been awake for nearly 48 hours and cant think about it and google isnt helping much either, Im gonna be posting a list of id's to a script for now called example.php what i want to do is get everyone of these id, and update a database field with it, however the ammount submitted will never be the same. could be between 1 - 100 id's.

Its to mass delete the message's in a message center from check boxes.

so heres what i got

on the message page

PHP Code:

<input name="list" id="4775" value="4775" type="checkbox"
when submitted it runs this

PHP Code:



if($_POST["submit"] == "delete"){
    echo
" submitted";
$message_delete mysql_query("select * from `messages` where `toid`='$players_id' and `deleted`='0'")or die(mysql_error());
    while(
$row=mysql_fetch_array($message_delete)){
        
$messageid $row["messageid"];
        
$toname $row["toname"];
        
$deletedmessageid safe($_POST["list"]);
        echo
$deletedmessageid";
            
mysql_query("update `messages` set `deleted`='1' where `messageid`='$deletemessageid'")or die(mysql_error());
            
$sucess "Message id# $deletemessageid Deleted";
    }

Now its echo'in the same Message id and i cant work out why, The values in the check boxes on the previous page are all right but this script seems to just not wanna work.

Any ideas ?

Cheers
Mike
__________________
Make People Friendly Say " Thanks "
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
  #2 (permalink)  
Old 11-16-09, 07:08 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
HTML Code:
 <input name="list[]" id="4775" value="4775" type="checkbox">  
(Note the square brackets)

PHP Code:

/* .... */


$deletedmessageid array_map('intval', (array) $_POST['list']);
$deletedmessageid implode(', '$deletedmessageid);

if (
$deletedmessageid)
{
    
mysql_query("update `messages` set `deleted`='1' where `messageid` IN({$deletemessageid})")
        or die(
mysql_error());

    
$sucess "Message id# $deletemessageid Deleted";

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
  #3 (permalink)  
Old 11-16-09, 08:25 AM
smithygotlost smithygotlost is offline
Aspiring Coder
 
Join Date: Jul 2006
Location: United Kingdom
Posts: 412
Thanks: 12
Thanked 3 Times in 3 Posts
Thanks for that nico, But i get a syntax error :S weird

this is before

PHP Code:

echo"<input name=\"list[]\" id=\"$message_id\" value=\"$message_id\" type=\"checkbox\">"
then the bit you gave nico

PHP Code:

if($_POST["submit"] == "delete"){
$deletedmessageid array_map('intval', (array) $_POST['list']);
$deletedmessageid implode(', '$deletedmessageid);

if (
$deletedmessageid)
{
    
mysql_query("update `messages` set `deleted`='1' where `messageid` IN({$deletemessageid}) and `toid`='$player_id'")
        or die(
mysql_error());

    
$sucess "Message id# $deletemessageid Deleted";
}  

and i get this error

PHP Code:

You have an error in your SQL syntaxcheck the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1 

its really weird, have i missed something :S

Cheers
Mike
__________________
Make People Friendly Say " Thanks "
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
  #4 (permalink)  
Old 11-16-09, 08:40 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
What output does this give you:
PHP Code:

if($_POST["submit"] == "delete")

{
    
$deletedmessageid array_map('intval', (array) $_POST['list']);
    
$deletedmessageid implode(', '$deletedmessageid);
    
    echo 
print_r($_POST['list'], true), "<br />\n";
    echo 
$deletedmessageid;

...?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
The Following User Says Thank You to Nico For This Useful Post:
smithygotlost (11-16-09)
  #5 (permalink)  
Old 11-16-09, 08:42 AM
smithygotlost smithygotlost is offline
Aspiring Coder
 
Join Date: Jul 2006
Location: United Kingdom
Posts: 412
Thanks: 12
Thanked 3 Times in 3 Posts
PHP Code:

Array ( [0] => 12114 [1] => 12084 [2] => 12069 [3] => 11979 [4] => 11976 [5] => 11974 )
121141208412069119791197611974 
__________________
Make People Friendly Say " Thanks "
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
  #6 (permalink)  
Old 11-16-09, 10:02 AM
smithygotlost smithygotlost is offline
Aspiring Coder
 
Join Date: Jul 2006
Location: United Kingdom
Posts: 412
Thanks: 12
Thanked 3 Times in 3 Posts
Sorry forgot to add your help is appriciated nico
__________________
Make People Friendly Say " Thanks "
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
  #7 (permalink)  
Old 11-16-09, 03:07 PM
smithygotlost smithygotlost is offline
Aspiring Coder
 
Join Date: Jul 2006
Location: United Kingdom
Posts: 412
Thanks: 12
Thanked 3 Times in 3 Posts
Any more help nico ?
__________________
Make People Friendly Say " Thanks "
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
  #8 (permalink)  
Old 11-16-09, 04:53 PM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
In addition to all the other comments, I would add that technically an "id" can't begin with a number, so something like 'id="4775"' actually isn't legal. Most browsers will (might) handle it, but it's not valid HTML.

ID naming rules:

* Must begin with a letter A-Z or a-z
* Can be followed by: letters (A-Za-z), digits (0-9), hyphens ("-"), underscores ("_"), colons (":"), and periods (".")
* Values are case-sensitive
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
The Following User Says Thank You to End User For This Useful Post:
smithygotlost (11-16-09)
  #9 (permalink)  
Old 11-16-09, 05:37 PM
smithygotlost smithygotlost is offline
Aspiring Coder
 
Join Date: Jul 2006
Location: United Kingdom
Posts: 412
Thanks: 12
Thanked 3 Times in 3 Posts
Heya guys found the problem

PHP Code:

/* .... */

$deletedmessageid array_map('intval', (array) $_POST['list']);
$deletedmessageid implode(', '$deletedmessageid);

if (
$deletedmessageid)
{
    
mysql_query("update `messages` set `deleted`='1' where `messageid` IN({$deletemessageid})")
        or die(
mysql_error());

    
$sucess "Message id# $deletemessageid Deleted";

In the sql statement it needed to say $deleted rather than $delete

Thanks Both Of You Much Appriciated
__________________
Make People Friendly Say " Thanks "
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Closed Thread

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Sports Pick Em racingboy20 Script Requests 3 06-18-10 04:12 AM
PHP Search Feature Problem jilawatan PHP 2 08-13-09 09:21 AM
2 profitable script sites for sale cms-master.com General Advertisements 3 07-03-07 11:17 AM
how to use onclick in php coolcoder HTML/XHTML/XML 2 05-31-06 01:40 PM
Php Mysql Bug??? tranquilraven PHP 4 03-01-06 04:06 AM


All times are GMT -5. The time now is 08:01 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.