runnerjp Posted April 8, 2009 Share Posted April 8, 2009 im using implode for my check boxes but i get this error Warning: implode() [function.implode]: Invalid arguments passed in /home/runningp/public_html/members/include/delete.php on line 4 Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1 what do i seem to be doing wrong :S <?php $delete="DELETE FROM messages WHERE id in (".implode(',', $_POST['pms']).")"; mysql_query($delete) or die("Error: " . mysql_error()); //insert post?> i have only selected 1 check box to delete Quote Link to comment https://forums.phpfreaks.com/topic/153178-the-use-of-implode/ Share on other sites More sharing options...
Axeia Posted April 8, 2009 Share Posted April 8, 2009 I'm guessing $_POST['pms'] does not exist as it's having problems with the values you're feeding to implode. And the first one is always right. You could try wrapping it in a isset checker, like: <?php if( isset( $_POST['pms'] ) ) { $delete="DELETE FROM messages WHERE id in (".implode(',', $_POST['pms']).")"; mysql_query($delete) or die("Error: " . mysql_error()); //insert post } ?> If that doesn't help try echo'ing $_POST['pms'] to see what's actually in it. Quote Link to comment https://forums.phpfreaks.com/topic/153178-the-use-of-implode/#findComment-804677 Share on other sites More sharing options...
runnerjp Posted April 8, 2009 Author Share Posted April 8, 2009 humm i get nothing ...bu i should do here is my form <form name="Submit" method="post" action="index.php?page=delete"> </p> <table width="80%" class='forum'> <tr> <td><table width="100%" class='maintable'> <tr class='headline'> <td align="center"><b><u>Select</u></b></td> <td align="center">Status</td> <td align="center">Sender</td> <td align="center">Image</td> <td><b><u>Subject</u></b></td> <td>Sent On</td> </tr> <?php //Ok cool, now we stick it all into an array and we will dispaly it now while($inbox = mysql_fetch_array($sqlinbox)) { //These are the variables we have the id of the private message, we have the person who sent the message, we have the subject of the message, and yeah thats it $pm_id = $inbox['id']; $sender = $inbox['sender']; $subject = $inbox['subject']; $time = $inbox['time']; $new = $inbox['recieved']; //So lets show the subject and make that a link to the view message page, we will send the message id through the URL to that page so it can be displayed //And also let the person wee who sent it to them, if you want you can make that some sort of a link to view more stuff about the user, but Im not doing that here, I did it for my game though, pretty much same as the viewmsg.php page but a different page, and with the senders id //And finally the checkboxes that are all stuck into an array and if they are selected we stick the private message id into the array //I will only let my users have a maximum of 50 messages, remeber that ok? Because that's the value I will use later for things ?> <tr <?php if($important==1) { $class = "mainrow1"; } else { $class = "mainrow"; } ?> class="<? echo $class?>"> <td width="5%" height="18" align="center" valign="top"><input type="checkbox" name="selection[]" value="<?php echo $pm_id; ?>" /> <td width="6%" height="18" align="center" valign="top"><?php if ($new == 0 ){echo 'Unread';} else {echo 'Read';} ?> <td width="9%" align="center" valign="top"><p><a href="http://www.runningprofiles.com/members/<?php echo $sender; ?>"><?php echo $sender; ?></a></p> <p><a href="http://www.runningprofiles.com/members/<?php echo $sender; ?>"></a></p> <p> </p> <td width="9%" align="center" valign="top"><a href="http://www.runningprofiles.com/members/<?php echo $sender; ?>"> <?php $sender = $inbox['sender']; $getuser="SELECT * FROM users WHERE Username = '$sender' "; $getuser2=mysql_query($getuser) or die("Could not get user") ; while($getuser3=mysql_fetch_array($getuser2)){ $getuser3['image']=strip_tags($getuser3['image']); $image = $getuser3['image']; echo "<img src=\"http://www.runningprofiles.com/members/images/mini/$image\" border=\"1\" />"; }?> </a> <td width="37%" align="center" valign="top"><p align="left"><a href="index.php?page=viewmsg&msg_id=<?php echo $pm_id; ?>"><?php echo $subject; ?></a> </td> <td align="left" valign="top"><?php $time1 = date("F j Y, g:i a", $time); echo $time1; ?> <div align="left"></div></td> </tr> <? } ?> <tr <?php if($important==1) { $class = "mainrow1"; } else { $class = "mainrow"; } ?> class="<? echo $class?>"> <td height="19" colspan="6" align="center" valign="middle"><input type="submit" name="operation" value="Delete" /> <input type="submit" name="operation" value="Move" /> </form> ?> Quote Link to comment https://forums.phpfreaks.com/topic/153178-the-use-of-implode/#findComment-804689 Share on other sites More sharing options...
Maq Posted April 8, 2009 Share Posted April 8, 2009 Make sure the name of all your checkbox fields are "pms[]". Like Axeia mentioned, output what's actually in the array, print_r($_POST['pms']); You also need each value to be a string so make sure the final output of your query is similar to: fieldname IN ('US','UK','GB','CN'); Quote Link to comment https://forums.phpfreaks.com/topic/153178-the-use-of-implode/#findComment-804691 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.