Jump to content

Recommended Posts

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

 

 

Link to comment
https://forums.phpfreaks.com/topic/63837-check-the-box-if-you-can-help-me/
Share on other sites

$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']).')';----

 

 

 

 

 

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.