Jump to content

Recommended Posts

I have a set of checkboxes on a form that I pass to php using an array as the name such as:

<input name="class[]" type="checkbox" value="C-15" /> Flooring

I then loop through this array, and modify the database based on the selections and the date range.

Part 1 Problem: the first loop shows the value correctly as "C-15", but second loop and further only shows "C" and cuts off the "-15";

$user = $session->username;
if(isset($_POST['carrier'])){
$carrier = $_POST['carrier'];
$class[] = $_POST['class'][0][0];
$date1 = $_POST['date1'];
$date1 = date("Y-m-d 00:00:00", strtotime($date1));
$date2 = $_POST['date2'];
$date2 = date("Y-m-d 23:59:59", strtotime($date2));

foreach( $class as $key){
$query = "SELECT * FROM leads WHERE class1 = '$key' OR class2 = '$key' OR class3 = '$key' OR class4 = '$key' OR class5 = '$key' OR class6 = '$key' OR class7 = '$key' OR class8 = '$key' OR class9 = '$key' OR class10 = '$key' OR class11 = '$key' OR class12 = '$key' AND user = '' AND wccompcode = '$carrier' AND wcxdate BETWEEN '$date1' AND '$date2' LIMIT 100";
$sellead = mysql_query($query)or die(mysql_error());
echo $query;
while($leads = mysql_fetch_array($sellead)){
$rowid = $leads['ID'];
$update = mysql_query("UPDATE leads SET user = '$user' WHERE ID = '$rowid'")or die(mysql_error());

}
}
}

Problem 2: it is ignoring my between date and modifying rows with a wcxdate of anything.

 

Any ideas? This is my echo:

SELECT * FROM leads WHERE class1 = 'C-8' OR class2 = 'C-8' OR class3 = 'C-8' OR class4 = 'C-8' OR class5 = 'C-8' OR class6 = 'C-8' OR class7 = 'C-8' OR class8 = 'C-8' OR class9 = 'C-8' OR class10 = 'C-8' OR class11 = 'C-8' OR class12 = 'C-8' AND user = '' AND wccompcode = '25' AND wcxdate BETWEEN '2013-01-01 00:00:00' AND '2013-01-01 23:59:59' LIMIT 100SELECT * FROM leads WHERE class1 = 'C' OR class2 = 'C' OR class3 = 'C' OR class4 = 'C' OR class5 = 'C' OR class6 = 'C' OR class7 = 'C' OR class8 = 'C' OR class9 = 'C' OR class10 = 'C' OR class11 = 'C' OR class12 = 'C' AND user = '' AND wccompcode = '25' AND wcxdate BETWEEN '2013-01-01 00:00:00' AND '2013-01-01 23:59:59' LIMIT 100

Link to comment
https://forums.phpfreaks.com/topic/271487-2-part-problem/
Share on other sites

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.