phpretard Posted August 8, 2007 Share Posted August 8, 2007 I have a database where the rows are named "email" "instructional" "tball" "minor" "major" "prep" The value in these are either "yes" or they are empty. My objective is to send an email to the rows with a yes in them. Here is the code I have thus far: <?php <-----Line 1 $to ="email@email.com"; $subject =$_POST['subject']; $message = $_POST['body']; $username = 'sdfsdf'; $password = 'ertert'; $database = 'ertertert'; //connect to database $con=mysql_connect('host.net', $username,$password); @mysql_select_db($database) or die("<b>Unable to specified database</b>"); $where = ''; if (!empty($_POST['cb']) && count($_POST['cb'])) { $where = 'WHERE 'id' IN ('. implode(', ', $_POST['cb']).')'; } $query = "SELECT email FROM testemail . $where"; $result=mysql_query($query) or die(mysql_error()); mysql_close($con); Here is the form: <form> <input type=checkbox name="cb[instructional]" <input type=checkbox name="cb[tball]"> <input type=checkbox name="cb['rookie']"> <input type=checkbox name="cb['minor']"> <input type=checkbox name="cb['major']"> <input type=checkbox name="cb['prep']"> <input type=checkbox name="cb['mom']"> </form> Here is the eror: 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 'WHERE yes IN (on)' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/63837-check-the-box-if-you-can-help-me/ Share on other sites More sharing options...
teng84 Posted August 8, 2007 Share Posted August 8, 2007 is $_POST['cb'] an array ??? because you have this if (!empty($_POST['cb']) && count($_POST['cb'])) { count array and you expolde it by , are you realy entering comma from a form Quote Link to comment https://forums.phpfreaks.com/topic/63837-check-the-box-if-you-can-help-me/#findComment-318172 Share on other sites More sharing options...
phpretard Posted August 8, 2007 Author Share Posted August 8, 2007 $where = ''; if (!empty($_POST['cb']) && count($_POST['cb'])) { $where = 'WHERE yes IN ('. implode(', ', $_POST['cb']).')'; } I really need an explaination of this statement ----$where = 'WHERE yes IN ('. implode(', ', $_POST['cb']).')';---- Quote Link to comment https://forums.phpfreaks.com/topic/63837-check-the-box-if-you-can-help-me/#findComment-318179 Share on other sites More sharing options...
teng84 Posted August 8, 2007 Share Posted August 8, 2007 what should i explain OK $where = 'WHERE yes IN ('. implode(', ', $_POST['cb']).')' implode is use to put , (that is what you use) in the array sample if the valu of the array are teng and tengagain when you use implode array(" teng","tengaagin") it will be formated as teng,tengaagin as a string not array now $_POST['cb'] is this an array? next is the yes in the wher that is right if that is the field but if that a record then your buying drugs in the hardware hope that helps Quote Link to comment https://forums.phpfreaks.com/topic/63837-check-the-box-if-you-can-help-me/#findComment-318182 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.