PHP - Php & Mysql... Checkboxes To Submit Queries...
Hey all...
I'm running into a problem here. If you take a look at the code for this, you'll see it's to enter "horses" into a "class." It's all fine and dandy except I'm trying to get the way the horses are selected to have a different option. Right now they exist as a drop down/select option where you have to choose one at a time and enter submit. My goal is to have checkboxes that users can toggle and submit them all at once (with the rest of the eligibility checks etc still applicable). I've looked it up and the problem is, each user has a different amount of horses, so I can't account for all of them manually. Could someone help me out? On DaniWeb a user was trying to help me with an implode option, but I have zero idea how to work with that. I will literally need my hand to be held through this one. Thank you in advance - I have been trying to do this myself for a good chunk of the day, but my PHP skills are quite limited. Code: [Select] <?php session_start(); // Maintain session state header("Cache-control: private"); // Fixes IE6's back button problem. $page_title = "Class Information"; include('header.php'); $class_id = $_GET['id']; $enter = $_POST['enter_horse']; $enter_check = $_POST['check']; $horse_id = $_POST['horse_id']; //general show information $result = @mysql_query("SELECT s.show_id, s.player_id, s.type, s.name, DATEDIFF(s.run_date, NOW()) AS datedif, c.class_id, s.entry_fee FROM classes c, shows s WHERE c.class_id='$class_id' AND c.show_id=s.show_id LIMIT 1")or die("Cannot find class! " . mysql_error()); $row = @mysql_fetch_array($result); $show_id = $row['show_id']; $show_name = $row['name']; $runs_in = $row['datedif']; $species = $row['species']; $type = $row['type']; $owner_id = $row['player_id']; if(!$row['class_id']){myError("Invalid class!");include('footer.php');} $entry_fee = $row['entry_fee']; $num_entries = @mysql_num_rows(@mysql_query("SELECT horse_id FROM horses_entered WHERE class_id='$class_id'")); $runs_in = "$runs_in day[s]"; if($enter){ //ensure horse is eligible to enter $good = @mysql_num_rows(@mysql_query("SELECT horse_id FROM horses WHERE horse_id='$horse_id' AND player_id='$player_id' AND age>=2 AND age<=20")); $exists = @mysql_num_rows(@mysql_query("SELECT horse_id FROM horses_entered WHERE horse_id='$horse_id' AND class_id='$class_id' LIMIT 1")); if($my_money < $entry_fee){myError("You cannot afford the entry fee.", 1);} if(!$good){myError("Are you sure you own the horse and it is between 3 and 20 years of age?"); }elseif($exists){myError("That horse is already entered in this class!"); }else{ @mysql_query("INSERT INTO horses_entered(horse_id, class_id) VALUES('$horse_id', '$class_id')")or die("Cannot create entry!"); if($type == 1 AND $entry_fee){@mysql_query("UPDATE players SET money=money+'$entry_fee' WHERE player_id='$owner_id' LIMIT 1")or die("Cannot update player money!"); $points=1; }elseif($type == 2 AND $entry_fee){@mysql_query("UPDATE clubs SET money=money+'$entry_fee' WHERE president='$owner_id' LIMIT 1")or die("Cannot update player money2!"); $points=2;} @mysql_query("UPDATE players SET money=money-'$entry_fee', points=points+'$points' WHERE player_id='$player_id' LIMIT 1")or die("Cannot update player money3! " . @mysql_error()); @mysql_query("UPDATE horses SET points=points+'$points' WHERE horse_id='$horse_id' LIMIT 1")or die("Cannot update horse points!"); myError("Class entered!"); } } //display the show information echo "<table> <tr><td><b>Class:</td><td>#$class_id</td></tr> <tr><td><b>Show:</td><td><a href='shows.php?id=$show_id'>$show_name (#$show_id)</a></td></tr> <tr><td><b>Runs:</td><td>$runs_in</td></tr> <tr><td><b>Entry Fee:</td><td>$$entry_fee</td></tr> <tr><td><b>Total Entrants:</td><td>$num_entries</td></tr> <tr><td valign=top><b>Your Horses:</td><td> <form action='classes.php?id=$class_id' method=POST> <select name='horse_id'> "; $result = @mysql_query("SELECT horse_name, breed, horse_id FROM horses WHERE player_id='$player_id' AND age>2 AND age<=20 ORDER BY horse_name ASC")or die("Cannot find horses! " . mysql_error()); while($row = @mysql_fetch_array($result)): $horse_id = $row['horse_id']; $horse_name = stripslashes($row['horse_name']); $breed = $row['breed']; echo "<option value='$horse_id'>$horse_name (#$horse_id), $breed</option>\n"; $prev_species = $species; endwhile; if(!$horse_id){echo "<option value=0>No eligible horses!";} echo " </select> <input type=submit name='enter_horse' value='Enter Horse!'></td></tr></form> <tr><td valign=top><b>Entrants:</td><td> "; $query = "SELECT h.horse_name, h.horse_id, h.breed FROM horses_entered he LEFT JOIN horses h ON he.horse_id=h.horse_id WHERE he.class_id='$class_id' ORDER BY h.horse_name ASC"; $result = @mysql_query($query)or die(mysql_error()); while($row = @mysql_fetch_array($result)): $name = $row['horse_name']; $aid = $row['horse_id']; $breed = $row['breed']; $page = "horses.php"; echo "<a href='$page?id=$aid'>$name (#$aid)</a>, $breed<br>\n"; endwhile; if(!$aid){echo "<i>No entrants.";} echo "</td></tr> </table>"; include('footer.php'); ?> Similar TutorialsHello, in short, here is my problem: There are 2 tables: a table called postcodes, which contains UK postcodes and a table called wp_bp_xprofile_data (i want to integrate this search with the Buddypress plugin's tables) which contains the user data. I tried searching this, but to be honest, i didn't quite know how to go about it.. Here is what i have: $query1 = "SELECT value, user_id, (SQRT(POW((b.x - a.x), 2) + POW((b.y - a.y), 2))/1000) * 0.621 AS distance FROM postcodes a, postcodes b, wp_bp_xprofile_data WHERE a.outcode = '"$postcode"' AND b.outcode = wp_bp_xprofile_data.value HAVING (distance < '"$area"') ORDER BY distance asc "; $result1=mysql_query($query1) or die(mysql_error()); echo "<p style=\"font-size:10px;line-height:14px;color:#888;\">Straight line distances shown.<br>"; echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\" ><tr>"; // display results while ($list = mysql_fetch_array($result1)) { $user_postcode = $list['value']; $distance = $list['distance']; $distance = round($distance); echo "<td align=\"right\">$distance miles away</td></tr>"; echo "<tr><td colspan=\"3\" align=\"left\" width=\"130px\">$user_postcode </td>"; echo "<td align=\"right\"><a href=\"blahblah\">Directions using Google Maps</a></td>"; echo "<tr><td align=\"left\"> </td><tr>"; echo "</tr>"; } echo "</table>"; Code: ("wp_bp_xprofile_data") [Select] id field_id user_id value 1 1 1 admin 8 3 3 NW10 6 1 3 Test User 1 9 4 3 IT, Web Development 11 1 4 Test User 2 12 3 4 HA5 13 4 4 Test, It, Some Work Code: ("postcodes") [Select] outcode x y latitude longitude B10 392900 804900 57 -2 AB11 394500 805300 57 -2 AB12 393300 801100 57 -2 AB13 385600 801900 57 -2 AB14 383600 801100 57 -2 Here is an example of what i need: field_id "3" corresponds to a postcode. My script so far, can search a postcode and return results with the postcodes sorted by distance. What i'm trying to do, is also get the username on the result (i.e the 'value' column again..). in short, im trying to search a postcode, find it on wp_bp_xprofile_data, associate it with the correspondent user, and return both. Someone told me i need to INNER JOIN, but im lost.. The end result im looking for is if i type the search: "NW9 1AA" It returns: Test User 1 NW10 Test User 2 HA5 (the code sorts them by distance. So far i can get it to return the postcode, but cannot associate the relevant name. Can anyone help me with this? I hope this is in the right forum. Thanks for your attention. // Check for this userID if exsist in cp_credits $sql = "SELECT * FROM `cp_credits` WHERE account_id = $userid"; // Execute Query $r = mysqli_query($dbc, $sql); // If there are result in $r if($r){ // Print a message indicating success or not: while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)){ $user_balance = $row['balance']; $user_last_donation_date = $row['last_donation_date']; } } else{ $user_balance = "nothing"; $user_last_donation_date = "nothing"; } but either of my else statement does not work. Whats wrong with this? I'm trying to figure out how to combine these queries, to decrease server load and load time, but I'm not so good with MySQL queries. Does anyone have any ideas, any help is greatly appreciated, I've been tinkering with this for days now.
$Actv = 0; $ActvCount = -1; $ActvUpgrade = 0; $ActvRenewal = 0; $ActvVehicleAdds = 0; $result2 = mysql_query("SELECT * FROM tblOperators WHERE OperatorLocale = 'USA' and OperatorStatus = 'ACTIVE' and Team = 'RENEWALS'"); while($row2 = mysql_fetch_array($result2)) { $operID = $row2['OperatorID']; $result = mysql_query("SELECT * FROM tblUserPayments WHERE OperatorID = '$operID' AND PaymentStatus='OK' AND PaymentDate LIKE '$currentDate%'"); while($row = mysql_fetch_array($result)) { if($row['PaymentReason'] == 'ACTIVATION'){ ++$ActvCount; //if($row['PaymentMethod'] == 'CREDITCARD'){ $ActvUpgrade += $row['ChargeAmount']; //} } elseif($row['PaymentReason'] == 'UPGRADE'){ $userid = $row['UserID']; $paymentdate = $row['PaymentDate']; $result1 = mysql_query("SELECT * FROM tblRenewalInvoices WHERE UserID='$userid' AND ('$paymentdate' >= DATE_SUB(DueDate, INTERVAL 90 DAY) AND '$paymentdate' < DATE_ADD(DueDate, INTERVAL 15 DAY)) AND ParentInvoiceID IS NULL ORDER BY InvoiceNum DESC LIMIT 1"); if( $row1 = mysql_fetch_array($result1)) { $packageid = $row['PackageID']; $pack = mysql_query("SELECT * FROM tblUserPackages WHERE PackageID='$packageid';"); if($pack1 = mysql_fetch_array($pack)){ $expDate = $pack1['ExpirationDate']; $dueDate = $row1['DueDate']; $days = mysql_fetch_row(mysql_query("SELECT TO_DAYS('$expDate')-TO_DAYS('$dueDate');")); $months = (int)( ((int)$days + 14) / 30.4); $years = (int) ( ((int)$days + 182) / 365); $Intervals = 0; if($years > 0){ $Intervals = $years; } if(($pack1['Package'] or 'GPS-SVL') or ($pack1['Package'] == 'GPS-1') or ($pack1['Package'] == 'GPS-1PLUS')){ if($Intervals > 1){ //if($row['PaymentMethod'] == 'CREDITCARD'){ $Actv += $row['ChargeAmount']; //} } else{ //if($row['PaymentMethod'] == 'CREDITCARD'){ $ActvRenewal += $row['ChargeAmount']; //} } } else{ $Actv += $row['ChargeAmount']; } } else{ } } else{ //if($row['PaymentMethod'] == 'CREDITCARD') $ActvUpgrade += $row['ChargeAmount']; } } elseif($row['PaymentReason'] == 'ADDVEHICLE'){ //if($row['PaymentMethod'] == 'CREDITCARD') $ActvVehicleAdds += $row['ChargeAmount']; } } $result = mysql_query("SELECT * FROM tblRenewalCalls WHERE OperatorID = '$operID' AND PayStatus='OK' AND DateSubmitted LIKE '$currentDate%'"); while( $row = mysql_fetch_array($result) ) { if($row['Charged']){ if ((int)$row['RenewYears'] > 1) { $Actv += $row['RenewTotal']; } else{ $ActvRenewal += $row['RenewTotal']; } } } } $total = $Actv+$ActvRenewal+$ActvUpgrade+$ActvVehicleAdds; $ActvRenewal = $total - ($ActvVehicleAdds + $ActvUpgrade); $upgradeEarned = $ActvUpgrade; $renewalEarned = $ActvRenewal; I was wondering if it is possible to perform the following query. Say I have a list of names each with an id number ranging from 1 to 10. Is it possible to perform a query where you list all of these records while repeating one records. For example could I do a query that lists record number 6 then 10, 9, 8, 7, 6 etc. Or another example would be listing record number 10, then 10, 9, 8, 7, 6 etc? Thanks for any help. Hi, I would appreciate any help with this at all that you guys can give me. I am trying to get a list of unique users from a mysql table, then get the records for each of those user. I am then converting to a .csv and sending it through an email. I have the following code and I always only get the same record. The file name changes to the correct user but the data in the .csv is always only the first user. Thanks in advance. Code: [Select] echo "getusers"; $server = "localhost"; $link = mysql_connect("$server", "$user", "$password"); mysql_select_db("$database"); $getusers = "select distinct(`User`) from realtordata"; $result1 = mysql_query($getusers); $numusers = mysql_num_rows($result1); $userarray[$numusers]; // $s = 0; $userarray[$numusers]; $uservar = $userarray[$s]; echo "<table width = 5% border = '2'"; while ($row = mysql_fetch_array($result1)) { $userarray[$s] = $row['User']; // echo $userarray[$s]; $csv_file_name = "$uservar.csv"; echo "<tr><td>$userarray[$s] </td></tr>"; // $s++; $mySQL_query = "SELECT * FROM `realtordata` where `User` = '$uservar' order by `Status`"; $result = mysql_query($mySQL_query); $numrecs = mysql_num_rows($getdata); echo "<table border = '1'"; echo "<th> User </th><th>Date Added</th><th>First Name</th><th>Last Name </th><th> Status</th><th> Loan Timeframe</th><th>Need Purchase Realtor</th> <th> Real Estate Agent Name</th><th>Real Estate Agent Phone</th><th>Need Selling Realtor</th><th>Agent Company or Broker</th> <th> Agent Email</th><th>Agent City</th><th>Agent State</th>"; while($row = mysql_fetch_array($result)) { $s++; echo "$uservar"; $userarray[$s] = $row['User']; $user = $userarray[$s]; $date = $row['Date Added']; $fname = $row['First Name']; $lname = $row['Last Name']; $timeframe = $row['Loan Timeframe']; $needpurchaserealtor = $row['Need Purchase Realtor']; $agentname = $row['Real Estate Agent Name']; $agentphone = $row['Real Estate Agent Phone']; $needsellingrealtor = $row['Need Selling Realtor']; $agentcompanyorbroker = $row['Real Estate Agent Company or Broker']; $agentemail = $row['Real Estate Agent Email']; $agentcity = $row['Real Estate Agent City']; $agentstate = $row['Real Estate Agent State']; echo "<tr><td> $user </td>"; echo "<td> $date </td>"; echo "<td> $fname </td>"; echo "<td> $lname </td>"; echo "<td> $timeframe </td>"; echo "<td> $needpurchaserealtor </td>"; echo "<td> $agentname </td>"; echo "<td> $agentphone </td>"; echo "<td> $needsellingrealtor </td>"; echo "<td> $agentcompanyorbroker </td>"; echo "<td> $agentemail </td>"; echo "<td> $agentcity </td>"; echo "<td> $agentstate </td></tr>"; // Reuseable CSV file variables $csv_contain = '"'; $csv_separate = ","; $csv_end_row = "\n"; /* // run the MySQL query and check to see if results were returned*/ $result = mysql_query($mySQL_query); if (!$result) { die("ERROR: Invalid query \n MySQL error: " . mysql_error() . "\n Your query: " . $query); } echo "Step 3: MySQL query ran successfully. \n\n"; // store the number of columns from the results $columns = mysql_num_fields($result); // Build a header row using the mysql field names $header_row = ''; for ($i = 0; $i < $columns; $i++) { $column_title = $csv_contain . stripslashes(mysql_field_name($result, $i)) . $csv_contain . $csv_separate; $header_row .= $column_title; } $csv_file .= $header_row . $csv_end_row; // add header row to CSV file // Build the data rows by walking through the results array one row at a time $data_rows = ''; while ($row = mysql_fetch_array($result)) { for ($i = 0; $i < $columns; $i++) { // clean up the data; strip slashes; replace double quotes with two single quotes $data_rows .= $csv_contain . preg_replace('/"/', '\'\'', stripslashes($row[$i])) . $csv_contain . $csv_separate; } $data_rows .= $csv_end_row; // add data row to CSV file } $csv_file .= $data_rows; // add the data rows to CSV file echo "Step 4: CSV file built. \n\n"; /* -------------------------------------- SEND EMAIL WITH ATTACHMENT This requires the use of complex variable parsing {curly braces surrounding variable} For more information see: "PHP: Complex Variables in Strings" at Tinsology.net http://tinsology.net/2009/06/php-complex-variables-in-strings/ */ // start setting up the email header $headers = "From: ".$email_from; // create boundary string // boundary string must be unique using MD5 to generate a pseudo random hash $random_hash = md5(date('r', time())); $mime_boundary = "==Multipart_Boundary_x{$random_hash}x"; // set email header as a multipart/mixed message // this allows the sending of an attachment combined with the HTML message $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; // multipart boundary for the HTML message $email_message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type:text/html; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $email_html_msg . "\n\n"; // encode CSV file with MIME base64 // required for sending it as an email attachment $data = chunk_split(base64_encode($csv_file)); // multipart boundary for the email attachment $email_message .= "--{$mime_boundary}\n" . "Content-Type: application/octet-stream;\n" . " name=\"{$csv_file_name}\"\n" . "Content-Disposition: attachment;\n" . " filename=\"{$csv_file_name}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n"; // end the multipart message $email_message .= "--{$mime_boundary}--\n"; // try to send the email and verify the results $sendit = @mail($email_to, $email_subject, $email_message, $headers); if(!$sendit) { die("ERROR: The Email could not be sent."); } echo "Step 5: Email sent with attachment. \n\n"; } } Hello Everyone, I think this might be a bit of a challenge but its always worth getting some input for solutions. I'm using jqplot to create graphs from data held in a database. And im having trouble thinking of a way to lay the data out in an acceptable way. To plot a line the javascript takes a statement in this form: line1 = [['x-axis1'],y-axis1],['x-axis2',y-axis2] I'm running this query to get the data: <?php $query2 = "SELECT * FROM tracker WHERE username = '" . mysql_real_escape_string($usera) . "'"; $result = mysql_query($query2) or die('Error, query failed : ' . mysql_error()); while($row = mysql_fetch_assoc($result)) { $data[] = $row; } ?> This returns things like this: $data[0]['date'], $data[0]['reps'] $data[1]['date'], $data[1]['reps'] etc... Values are likely to be added or removed so I need to construct a loop of some kind to format it like this, line1 = [['{$data[0]['date']}',{$data[0]['reps']}],['{$data[1]['date']}',{$data[1]['reps']}],['{$data[2]['date']}'],{$data[2]['reps']}]]; Can someone point me in the right direction? Thanks in Advanced can I do this mysql_query("INSERT INTO directory (field, field, field, field,field,field, field,field,field, fieldfield,field, field,field,field,) VALUES ('field','field','field', 'field','field','field', 'field','field','field', 'field','field','field' ,'field','field','field',)"); please ignore any syntax errors and stuff its just the concept of breaking it into different lines? thanks I have a script to write out the number of hits each of my websites got each day of the week since I don't trust Google Analytics spying on my websites. The problem is that I have to query each day individually and count how many instances there are with that domain. Since I setup my database give me the time, location, demographics, etc. on each line I'm not sure how to optimize this further. Help would be greatly appreciated. Code: [Select] echo '<table><tr><td>Domain</td>'; foreach($timearray as $t){ echo '<td>'.$t.'</td>'; } echo '</tr>'; $i = 0; foreach($urlarray as $u){ $today = date("Y-m-d"); $yesterday = date("Y-m-d", mktime(0,0,0,date("m") , date("d")-1, date("Y"))); $lastmonth = date("Y-m-d", mktime(0,0,0,date("m")-1 , date("d")-1, date("Y"))); $twoweeks = date("Y-m-d", mktime(0,0,0,date("m") , date("d")-15, date("Y"))); $result3 = mysql_query("SELECT refer,Count(*) as count FROM `approved` WHERE time>'$lastmonth 23:59:59' AND time<'$today' AND refer LIKE '%$u%'"); $row3 = mysql_fetch_array($result3); $result4 = mysql_query("SELECT refer,Count(*) as count FROM `approved` WHERE time>'$twoweeks 23:59:59' AND time<'$today' AND refer LIKE '%$u%'"); $row4 = mysql_fetch_array($result4); if($row3['count']==0){echo "<tr style='background:red'>";}elseif($row4['count']>0){echo "<tr style='background:green'>";}elseif($i % 2){echo "<tr style='background:#CCC'>";}else{echo "<tr style='background:#FFF'>";} echo '<td>'.$u.' '.$row3['count'].' '.$row4['count'].'</td>'; foreach($timearray as $t){ $result = ''; $result = mysql_query("SELECT COUNT(*) AS count FROM `approved` WHERE time LIKE '$t%' AND refer LIKE '%$u%'"); while($row = mysql_fetch_array($result)){ echo '<td>'.$row['count'].'</td>'; } } echo '</tr>'; $i++; } echo '</tr></table>'; So I'm trying to basically trying to make an "advanced search" function in PHP/mysql that will allow users to search by a number of different options like search by zipcode, username, gender, etc. Now my question is how do I vary my mysql query so that it searches for all these things based on whatever the user inputs? For example, the user might need to search zipcode and username but not gender, but in another case, might need to search username and gender, but not zipcode. Obviously I could just do some if/else statements, but that would be increasingly more difficult as there are more fields. What can I do? I have an auctions website and I want to create a feature that is similar to ebay in which users will receive an email if one of the auctions they are watching will end in less than 3 hours. I will be using a cron job to call up this page every 15 minutes. When the cron job executes, I would like it to send 1 email per auction to every user that has that auction on their watchlist if the auction will be ending in 3 hours. I don't know whether it needs to be a separate email for each user or one mass email where their emails are hidden. The 4 tables in my database we are concerned about are "auctions, "users, "watchlists" and "products." I am trying to use the script phpMailer to execute the code because I heard it was the best one. Anways here is what I have so far. I am missing alot because I had no clue what to do. <?php require("class.phpmailer.php"); $holder = mysql_connect("localhost", "user", "password"); mysql_select_db("database", $holder); // NEED TO FIX THIS // Need to get ALL of the auction id's where the end time is less than 3 hours and the notification hasn't already been sent // $auctionid = mysql_query("SELECT id FROM auctions WHERE DATE_ADD(NOW(), INTERVAL 3 HOUR) <= end_time AND notification = 0", $holder); // get the auction title of EACH of the auctions selected above which is not stored in the auctions table but in the products table..will be used for body of email /// AGAIN, NEED THIS TO GET ME ALL OF THE NAMES OF AUCTIONS THAT ARE ENDING IN 3 HOURS// $auctiontitle = mysql_query("SELECT name FROM products LEFT JOIN auctions ON auctions.product_id=products.id WHERE auctions.id = $auctionid", $holder); // PROBABLY NEED TO FIX THIS // Need to get ALL of the email addresses who have ANY of the above auction ids on their watchlist // $email = mysql_query("SELECT email FROM users LEFT JOIN watchlists ON users.id=watchlists.user_id WHERE watchlists.auction_id = $auctionid", $holder); // Update the auctions table. Turn notification to 1 so the notification for that auction can't be sent again // AGAIN NEED THIS FOR ALL OF THE AUCTIONS ENDING IN 3 HOURS // $query1="UPDATE auctions SET notification = '1' WHERE id = '$auctionid'"; mysql_query($query1) or die(mysql_error()); $mail = new PHPMailer(); $mail->From = "no-reply@domain.com"; $mail->FromName = "Site Name"; // Getting and error message for the foreach but I saw a similar example and this is what I was told to do // NEED THIS TO ADD EACH OF THE EMAIL ADDRESSES INDIVIDUALLY // foreach ( $email as $recipients ) { $mail->AddAddress ($recipients); } $mail->WordWrap = 50; // set word wrap to 50 characters $mail->IsHTML(true); // set email format to HTML $mail->Subject = "Your Watched Auction is Ending Soon"; // Sample Body // WANT TO DISPLAY THE TITLE OF THE AUCTION (NAME OF PRODUCT) FOR THE AUCTION ID USING $auctiontile FROM ABOVE // $mail->Body = "Your auction titled $auctiontile is ending soon"; // Same as above // $mail->AltBody = Your auction titled $auctiontile is ending soon"; if(!$mail->Send()) { echo "Message could not be sent."; echo "Mailer Error: " . $mail->ErrorInfo; exit; } echo "Message has been sent"; ?> having a small issue setting up a search, trying to use check boxes, here is my form code <form action="workorder_index.php" method="POST"> <input type="checkbox" name="wos_0" <? if($wos_0 != NULL) { echo "checked"; }?>>0 - Active <input type="checkbox" name="wos_1" <? if($wos_1 != NULL) { echo "checked"; }?>>1 - Completed awaiting pickup <input type="checkbox" name="wos_2" <? if($wos_2 != NULL) { echo "checked"; }?>>2 - Completed and out the door <input type="checkbox" name="wos_3" <? if($wos_3 != NULL) { echo "checked"; }?>>3 - Waiting call back <input type="checkbox" name="wos_4" <? if($wos_4 != NULL) { echo "checked"; }?>>4 - Waiting for parts<br> <input type="checkbox" name="wos_5" <? if($wos_5 != NULL) { echo "checked"; }?>>5 - Parts in waiting for completion <input type="checkbox" name="wos_6" <? if($wos_6 != NULL) { echo "checked"; }?>>6 - not used <input type="checkbox" name="wos_7" <? if($wos_7 != NULL) { echo "checked"; }?>>7 - Overdue for pickup <input type="checkbox" name="wos_8" <? if($wos_8 != NULL) { echo "checked"; }?>>8 - Scrapped per customer <input type="checkbox" name="wos_9" <? if($wos_9 != NULL) { echo "checked"; }?>>9 - Scrapped by overdue<br><br> <input type="hidden" value="1" name="customsearch"> <input type="Submit" value="Update"> </form> here is my handling code $wos_0=$_POST[wos_0]; $wos_1=$_POST[wos_1]; $wos_2=$_POST[wos_2]; $wos_3=$_POST[wos_3]; $wos_4=$_POST[wos_4]; $wos_5=$_POST[wos_5]; $wos_6=$_POST[wos_6]; $wos_7=$_POST[wos_7]; $wos_8=$_POST[wos_8]; $wos_9=$_POST[wos_9]; if(isset($_POST['customsearch'])) { $str=''; if($wos_0 != NULL) { $str.= "'0'"; } if($wos_1 != NULL) { $str.= ",'1'"; } if($wos_2 != NULL) { $str.= ",'2'"; } if($wos_3 != NULL) { $str.= ",'3'"; } if($wos_4 != NULL) { $str.= ",'4'"; } if($wos_5 != NULL) { $str.= ",'5'"; } if($wos_6 != NULL) { $str.= ",'6'"; } if($wos_7 != NULL) { $str.= ",'7'"; } if($wos_8 != NULL) { $str.= ",'8'"; } if($wos_9 != NULL) { $str.= ",'9'"; } $query="SELECT * FROM workorders a INNER JOIN customers b ON a.customer_id = b.customer_id WHERE a.workorder_status IN (".$str.") ORDER BY a.workorder_id"; } everything works as intended as long as the first check box remains checked, the others can be checked or not, if the first box gets unchecked I get this error Quote SELECT * FROM workorders a INNER JOIN customers b ON a.customer_id = b.customer_id WHERE a.workorder_status IN (,'1','2','3','4','5','6','7','8','9') ORDER BY a.workorder_id Warning: mysql_numrows() expects parameter 1 to be resource, boolean given in workorder_index.php on line 84 basically I can't get the commas right, ...? any help is much appreciated I was fiddling around with php and concerning data in a mysql database. All I was wanting to understand was being able to remove values with cheking multiple items in outputted html list. One that reads a set of values from a database, then displays a check box allowing the user to delete such values, that's it basically, here is my script I used to do it: Code: [Select] <?php function deleteRow($value) { $sql = "DELETE FROM checkbox WHERE value LIKE '$value'"; $result = mysql_query($sql); } if(array_key_exists('delete', $_POST)){ if(isset($_POST['value'])) { $count = count($_POST['value']); $connect = mysql_connect('localhost', 'jeremy', 's56pj989'); if($connect) { $select_db = mysql_select_db('test'); if($select_db) { for($i=0; $i<$count; $i++){ // print 'This is item = '.$_POST['value'][$i]; // outputs fine if(strlen($_POST['value'][$i]) > 0) { deleteRow($_POST['value'][$i]); } } } } } } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html lang="en"> <head> <title></title> </head> <body> <form id="myform" name="myform" action="<?=$_SERVER['PHP_SELF']; ?>" method="post"> <?php if($_SERVER['REMOTE_ADDR'] == '192.168.0.2') { // printf("<p>Yes you have connected to this script successfully!</p>"); $connect = mysql_connect('localhost', 'mydbuser', 'mydatabasepassword'); if($connect) { // printf("<p>You have now connected to the database, well done!</p>"); $select_db = mysql_select_db('test'); if($select_db) { // printf("<p>Selected database now</p>"); $sql = 'SELECT * FROM checkbox'; $result = mysql_query($sql); if($result) { if(mysql_num_rows($result)>0){ while($row = mysql_fetch_assoc($result)) { printf("%s <input type=\"checkbox\" name=\"value[]\" value=\"%s\">\n<br />\n", $row['value'], $row['value']); } } else { printf("<p>No rows in system!</p>"); } } } } } ?> <input type="submit" id="delete" name="delete" value="Delete" /> </form> </body> </html> There must be a better way shouldn't there? I am not too concerned with error checking, ie if result of removing the values doesnt work, since I will just use this as an example of how to do this. Going on from that, how would I allow it to update a set of say changed values, just purely out of interest, pretty happy since it works though this script. But I was also wondering if there's some easy way of updating a set of values perhaps? Hmm good though and I look forward to any replies, Jeremy. Hey everyone. [= I don't have much time to read through all of the forums, because I'm on a time crunch and I'll be putting this certain project behind a couple others while I wait for some answers. This project is confusing me a bit, because I haven't worked much with arrays and the good ol' checkbox, so I need some help getting this to work. This project requires me to set-up a checkbox next to each order that was pulled off a database. You are allowed to select as many checkboxes as you'd like, and then click on the "process receipts" for all of the orders that were selected. I need to be able to have the form send me straight to a new page that pulls a loop of receipts one after another. I have the receipts built, and I can access a receipt one at a time based off the ID of a certain order, and I can easily build a loop that presents the receipts. I'm just having a problem pulling the information off the database based from the checkbox array. If you can give me some ideas on where to start with this, I'd greatly appreciate it. Note: Example is inside a hidden administrative page. Can't really give you something to play with, sorry! QQ Thanks! Alex D.A. Designing In querying my database, I'm Selecting nameFirst and nameLast, and it produces a name like Joe Smith. I'm trying to match a photo with the name. Right now I'm uploading photos into a folder naming the file (e.g. SmithJoe.jpg). For reasons that involve writers being able to upload and access photos, I'm trying to use an image plugin. When uploading photos, it strips capital letters, so SmithJoe,jpg goes in as smithjoe.jpg, and it's not matching my database query. Here is the code I'm working with that works quite well with this one exception: $query = 'SELECT * FROM wp_playerRank'; $results = mysql_query($query); while($line = mysql_fetch_assoc($results)) { if ($line['wpID'] == $wp_tagID) { echo '<div class="player">'; // Here is the code that produces the image. I need to get rid of capital letters for ease of use echo '<div><img src="/wp-content/uploads/' . $line['nameLast'] . $line['nameFirst'] . '.jpg"></div>'; echo '<div class="playerData">' . $line['height'] . ' '; if ($line['position'] == 'PG') {echo 'Point Guard';} elseif ($line['position'] == 'SG') {echo 'Shooting Guard';} elseif ($line['position'] == 'SF') {echo 'Small Forward';} elseif ($line['position'] == 'PF') {echo 'Power Forward';} elseif ($line['position'] == 'C') {echo 'Center';} echo '</div>'; echo '<div class="playerData">' . $line['hschool'] . '</div>'; echo '<div class="playerData">' . $line['summer'] . '</div>'; echo '<div class="playerData">Class of ' .$line['year'] . '</div>'; if ($line['committed'] == 'y') { echo '<div> <br>Committed to <strong>'. $line['college'] . '</strong></div> ';} } } I built a series of insertion forms to put entries into a mysql database. Everything is working fine, except that I just now realized my checkboxes don't put any entry in. It's just leaving it's respective smallint field as a default "0". Being new, I've must've overlooked how to handle these. The form's checkboxes have a bit of code in the value that remembers what users chose in case they have to backtrack and redo their form. How would I solve the problem and keep this code? Here's what all the checkboxes are written like: Code: [Select] <input type="checkbox" name="green_leaf" value="<?php if(isset($_POST['1'])) echo $_POST['1']; ?>" > green I currently have a page where I have each row in my table listed using: Code: [Select] $getinfo="SELECT * FROM tablename WHERE Closed='n'"; $result=mysql_query($getinfo); while ($row=mysql_fetch_array($result)){ ... // list of user information } That successfully displays my content. What I am trying to do is have a checkbox next to each user (row) that when I check them and hit submit at the bottom, it will change the value of each row on the 'Closed' column to 'y' so it will not be displayed when the page is refreshed. I want to be able to select multiple items to "close". And I would like it to come back to this page. I think I can use this page as the form action and have the code above my while loop to change the Closed column so it then would not be displayed when the while loop is called... is that right? How do I set this up? Not sure where to start the form tag and where to end it, and not sure how to...well...do any of it. I have a table in a mysql database with 5 columns, id, Name, Wifi, Bluetooth, GPS, with rows that are for example 1, Galaxy S2, yes, yes, yes. So basically i want to build a form that has check boxes (3 checkboxes for wifi bluetooth and GPS respectively) that once selected will query the database depending on which check boxes are selected. I have made the form but need to know what to put in the filter.php to make the results be displayed accordingly. Ideally if anyone knows how i would want it so the results were shown on the same page which i believe u need to use ajax to happen but any help on how to show the results will be greatful. the code for the form i have made is as follows: Code: [Select] <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>test</title> </head> <body> <form action="filter.php" method="post"> <INPUT TYPE=CHECKBOX NAME="option[]" VALUE="Wifi" id="r1">Wifi <INPUT TYPE=CHECKBOX NAME="option[]" VALUE="Bluetooth" id="b1">Bluetooth <INPUT TYPE=CHECKBOX NAME="option[]" VALUE="GPS" id="g1">GPS <input type="submit" name="formSubmit" value="Submit" /> </form> </body> </html> im not sure on how to make the filter.php page but i do have this code for displaying the all the data but i want to kno how to make it only display the data from the choices on the checkboxes Code: [Select] <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>pls work</title> </head> <body> <?php function h($s) { echo htmlspecialchars($s); } mysql_connect("localhost", "root", "") or die (mysql_error()); mysql_select_db("project") or die (mysql_error()); $result= mysql_query('SELECT * FROM test') or die('Error, query failed'); ?> <?php if (mysql_num_rows($result)==0) { ?> Database is empty <br/> <?php } else { ?> <table> <tr> <th></th> <th>Name</th> <th>Wifi</th> <th>Bluetooth</th> <th>GPS</th> </tr> <?php while ($row= mysql_fetch_assoc($result)) { ?> <tr> <td> <a href="uploaded-images/<?php h($row['Name']); ?>.jpg"> <img src="uploaded-images/<?php h($row['Name']); ?>.jpg" alt="test"/> </a> </td> <td><a href="textonly.html"><?php h($row['Name']); ?></a></td> <td><?php h($row['Wifi']); ?></td> <td><?php h($row['Bluetooth']); ?></td> <td><?php h($row['GPS']); ?></td> </tr> <?php } ?> </table> <?php } ?> </body> </html> Hi people. I have a form which inputs into a database. Here is the code that inserts a yes no option... Code: [Select] <select name = "consent"> <option value = "Yes" <?php if ($_POST['consent'] == 'Yes') { echo 'selected="selected"'; } ?>>Yes</option> <option value = "No" <?php if ($_POST['consent'] == 'No') { echo 'selected="selected"'; } ?>>No</option> </select> However, I have been asked if I can make it a yes or no checkbox instead. Please can you tell me how I need to code it so that the "yes" or "no" is recorded in the DB. At the moment I just have this Code: [Select] <input name="consent" type="checkbox" value="Yes" />Yes<br /> <input name="consent" type="checkbox" value="No" />No<br /> Thanks in advance VinceG I have figured out far enough to loop through my table and return a list of check boxes that will be matched to a product. My issue now, is i cannot figure out the proper way to loop through them after they are selected and return them as checked/unchecked for the given product. Thought there is some MySQL involved, that part isn't the problem, I know how to insert into a database or update...when the product is selected from a drop down, I need to be able to populate the checkboxes. Here is the code i am using to initially display all of the categories to choose from... <ul class="categories"> <?php $query = "SELECT * FROM products"; $result = mysql_query($query) or die(mysql_error()); while ($row = mysql_fetch_assoc($result)) { $category = $row['category']; $catId = $row['id']; echo "<li><input class='catCheck' type='checkbox' name='p_cat[]' value='$catId' /> $category</li>"; } ?> </ul> Thanks guys.... |