PHP - Multiple Select Options In A Multiple Page Form
This seems to be a bit of a challenge but I am creating a multiple page form and on one of the pages I have a select field. I would like the user to have the ability to select multiple options but I am using some functions to move the data in hidden fields from page to page. I don't think my functions are jiving with my my foreach loop cause I keep getting an invalid argument error.
Thanks in advance for any help. Here is my function: function setSelected($fieldName, $fieldValue) { if(isset($_POST[$fieldName]) && $_POST[$fieldName] == $fieldValue) { echo 'selected="selected"'; } } And here is my loop: $selections = ""; if(isset($_POST["selections"])) { foreach ($_POST["selections"] as $selection) { $selections .= $selection . ", "; } } Similar TutorialsI'm doing a site for a used vehicles company. I have a "searchbar" with the following select options: the first one is to search per vehicle manufacturer (ex. BMW). The second one is for a price range (ex. any - $1 000 000). the third is per mileage (ex. any - 150 000). and the last one is per model (ex. 320). All of them are structured as drop-down selectors except for the last one "model" which is has a input type text. Here is what I struggle with... When I choose a manufacturer and click search then I get the desired results. But as-soon as I choose a value from the price or mileage or model I get all the values from the manufacturer, but it doesn't filter what I have chosen. Can you please help me.... Thank you Here is the code for the searchbar.php: Code: [Select] <?php ?> <form name="searchForm" action="showroom.php" method="GET" class="search"> <table cellpadding="0" cellspacing="0"> <tr class="search_bar"> <td><b>Search</b></td> <td><select name="make"> <?php do { ?><option value="<?php echo $row_make['Make']?>"<?php if (!(strcmp($row_make['Make'], $row_make['Make']))) {echo "selected=\"selected\"";} ?>> <?php echo $row_make['Make']?></option> <?php } while ($row_make = mysql_fetch_assoc($make)); $rows = mysql_num_rows($make); if($rows > 0) { mysql_data_seek($make, 0); $row_make = mysql_fetch_assoc($make); } ?> </select> </td> <td><select style="height:20px;" name="price"> <option>Price</option> <option value="">Any</option> <option value="5000">R5,000 </option> <option value="10000">R10,000 </option> <option value="15000">R15,000 </option> <option value="20000">R20,000 </option> <option value="25000">R25,000 </option> <option value="30000">R30,000 </option> <option value="35000">R35,000 </option> <option value="40000">R40,000 </option> <option value="45000">R45,000 </option> <option value="50000">R50,000 </option> <option value="55000">R55,000 </option> <option value="60000">R60,000 </option> <option value="65000">R65,000 </option> <option value="70000">R70,000 </option> <option value="75000">R75,000 </option> <option value="80000">R80,000 </option> <option value="85000">R85,000 </option> <option value="90000">R90,000 </option> <option value="95000">R95,000 </option> <option value="100000">R100,000 </option> <option value="125000">R125,000 </option> <option value="150000">R150,000 </option> <option value="175000">R175,000 </option> <option value="200000">R200,000 </option> <option value="225000">R225,000 </option> <option value="250000">R250,000 </option> <option value="275000">R275,000 </option> <option value="300000">R300,000 </option> <option value="325000">R325,000 </option> <option value="350000">R350,000 </option> <option value="375000">R375,000 </option> <option value="400000">R400,000 </option> <option value="425000">R425,000 </option> <option value="450000">R450,000 </option> <option value="475000">R475,000 </option> <option value="500000">R500,000 </option> <option value="600000">R600,000 </option> <option value="700000">R700,000 </option> <option value="800000">R800,000 </option> <option value="900000">R900,000 </option> <option value="1000000">R1,000,000 </option> </select> </td> <td><select style="height:20px;" name="mileage"> <option>Mileage</option> <option value="0_10000">0-10 000 km</option> <option value="10001_20000">10 001-20 000 km</option> <option value="20001_30000">20 001-30 000 km</option> <option value="30001_40000">30 001-40 000 km</option> <option value="40001_50000">40 001-50 000 km</option> <option value="50001_60000">50 001-60 000 km</option> <option value="60001_70000">60 001-70 000 km</option> <option value="70001_80000">70 001-80 000 km</option> <option value="80001_90000">80 001-90 000 km</option> <option value="90001_100000">90 001-100 000 km</option> <option value="100001_110000">100 001-110 000 km</option> <option value="110001_120000">110 001-120 000 km</option> <option value="120001">120 000km and above</option> </select></td> <td align="right"><b>Model:</b></td> <td><input type="text" name="model" /></td> <td><input type="submit" value="Search" /></td> </tr> </table> </form> Hi i would like to submit the following code to my database as a mutiple selection box. when i submit i just get the last selected value for example if i hold ctrl and press 1 2 3 4 i am only receiving 4 on my database. any ideas? thanks in advance for any help! Code: [Select] Hours Of Availability:<br> <select name="availability" multiple="multiple" size="9"> <option value="Monday - Period 1">Monday - Period 1</option> <option value="Monday - Period 2">Monday - Period 2</option> <option value="Monday - Period 3">Monday - Period 3</option> <option value="Monday - Period 4">Monday - Period 4</option> <option value="Monday - Period 5">Monday - Period 5</option> <option value="Monday - Period 6">Monday - Period 6</option> <option value="Monday - Period 7">Monday - Period 7</option> <option value="Monday - Period 8">Monday - Period 8</option> <option value="Monday - Period 9">Monday - Period 9</option> </select> <select name="availability" multiple="multiple" size="9"> <option value="Tuesday - Period 1">Tuesday - Period 1</option> <option value="Tuesday - Period 2">Tuesday - Period 2</option> <option value="Tuesday - Period 3">Tuesday - Period 3</option> <option value="Tuesday - Period 4">Tuesday - Period 4</option> <option value="Tuesday - Period 5">Tuesday - Period 5</option> <option value="Tuesday - Period 6">Tuesday - Period 6</option> <option value="Tuesday - Period 7">Tuesday - Period 7</option> <option value="Tuesday - Period 8">Tuesday - Period 8</option> <option value="Tuesday - Period 9">Tuesday - Period 9</option> </select> <select name="availability" multiple="multiple" size="9"> <option value="Wednesday - Period 1">Wednesday - Period 1</option> <option value="Wednesday - Period 2">Wednesday - Period 2</option> <option value="Wednesday - Period 3">Wednesday - Period 3</option> <option value="Wednesday - Period 4">Wednesday - Period 4</option> <option value="Wednesday - Period 5">Wednesday - Period 5</option> <option value="Wednesday - Period 6">Wednesday - Period 6</option> <option value="Wednesday - Period 7">Wednesday - Period 7</option> <option value="Wednesday - Period 8">Wednesday - Period 8</option> <option value="Wednesday - Period 9">Wednesday - Period 9</option> </select> <select name="availability" multiple="multiple" size="9"> <option value="Thursday - Period 1">Thursday - Period 1</option> <option value="Thursday - Period 2">Thursday - Period 2</option> <option value="Thursday - Period 3">Thursday - Period 3</option> <option value="Thursday - Period 4">Thursday - Period 4</option> <option value="Thursday - Period 5">Thursday - Period 5</option> <option value="Thursday - Period 6">Thursday - Period 6</option> <option value="Thursday - Period 7">Thursday - Period 7</option> <option value="Thursday - Period 8">Thursday - Period 8</option> <option value="Thursday - Period 9">Thursday - Period 9</option> </select> <select name="availability" multiple="multiple" size="9"> <option value="Friday - Period 1">Friday - Period 1</option> <option value="Friday - Period 2">Friday - Period 2</option> <option value="Friday - Period 3">Friday - Period 3</option> <option value="Friday - Period 4">Friday - Period 4</option> <option value="Friday - Period 5">Friday - Period 5</option> <option value="Friday - Period 6">Friday - Period 6</option> <option value="Friday - Period 7">Friday - Period 7</option> <option value="Friday - Period 8">Friday - Period 8</option> <option value="Friday - Period 9">Friday - Period 9</option> </select> <select name="availability" multiple="multiple" size="9"> <option value="Saturday - Period 1">Saturday - Period 1</option> <option value="Saturday - Period 2">Saturday - Period 2</option> <option value="Saturday - Period 3">Saturday - Period 3</option> <option value="Saturday - Period 4">Saturday - Period 4</option> <option value="Saturday - Period 5">Saturday - Period 5</option> <option value="Saturday - Period 6">Saturday - Period 6</option> <option value="Saturday - Period 7">Saturday - Period 7</option> <option value="Saturday - Period 8">Saturday - Period 8</option> <option value="Saturday - Period 9">Saturday - Period 9</option> </select> <br>Press + Hold Ctrl For Multiple</p> Okay so I'm trying to come up with as many alternative methods to accomplish something. So I'm just seeking input from anyone who is willing to supply some. After the user clicks on a match type it'll know HOW MANY sides to the match there are so say for a singles match it'd have 2 sides (1 vs. 1) for a Triple Threat Match it'd have 3 sides (1 vs. 1 vs. 1) and so on. All matches have a stored field in the database of how many sides they have. So I'm thinking that I could have it create 3 divs (or something) down in the competitors area of how many sides there are in the match (separated by a VS. text block) and when the user selects a character from the dropdown and adds a character the user can maybe drag and drop the character's name to whatever side they choose. Its one idea. If you think of an EASIER more EFFICIENT way to do something like this and have an idea say something please or even if you can't let me know that you think it's a worth while idea. Code: [Select] <label for="matchtypedrop<?php echo $i+1 ?>">Match Type:</label> <select class="dropdown" name="matchtypedrop<?php echo $i+1 ?>" id="matchtypedrop<?php echo $i+1 ?>" title="Match Type <?php echo $i+1 ?>"> <option value="0">- Select -</option> <?php $query = 'SELECT id, matchtype FROM matchtypes'; $result = mysqli_query ( $dbc, $query ); // Run The Query while ( $row = mysqli_fetch_array ( $result, MYSQL_ASSOC ) ) { print "<option value=\"".$row['id']."\">".$row['matchtype']."</option>\r"; } ?> </select> <label for="competitors<?php echo $i+1 ?>">Competitors:</label><ul id="competitors<?php echo $i+1 ?>" style="list-style: none; margin-left: 195px;"></ul> <select class="dropdown" name="charactersdrop<?php echo $i+1 ?>" id="charactersdrop<?php echo $i+1 ?>" title="Characters Dropdown <?php echo $i+1 ?>" style="margin-left: 195px;"> <option value="0">- Select -</option> <?php $query = 'SELECT id, `character` FROM characters ORDER BY `character`'; $result = mysqli_query ( $dbc, $query ); // Run The Query while ( $row = mysqli_fetch_array ( $result, MYSQL_ASSOC ) ) { print "<option value=\"".$row['id']."\">".$row['character']."</option>\r"; } ?> </select> <input type="button" value="Add Character" class="" onclick="Competitors(<?php echo $i+1 ?>)"/> Is it possible to submit two upload input types on a form. Ex. I'm using a basic form input file upload, and would like to use a php_self to upload since its just one small file. But I also need a second set of files up to 10 files to be upload via a flash upload script. how can i set the form action to process itself (the php coding up top) then process the upload.php file? would if work if i just stuck and execute for the upload.php at the bottom of the php coding for the first upload process? The user uploads a csv file then is required to upload the supporting files. the csv gets inserted to the db and all the files to the temp folder. the upload.php script processes each file separately so sticking the upload process for the csv in the upload.php file would make it import multiple times everytimes till all the supporting files have been uploaded. i'm trying to avoid that. Code: [Select] <?php if(isset($_POST['submit'])) { // check .csv file has been uploaded... and on the server proceed if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], '../temp/files/')) { $filename = file_get_contents($_FILES['uploadedfile']['name']); $handle = fopen("$filename", "r"); while (($data = fgetcsv($handle, 100000, ",")) !== FALSE) { if(file_exists('/temp/files/'. $data[0] .'.docx')) { rename('/temp/files/'. $data[0] .'.docx', '/docx_files/'. $data[0] .'.docx'); $import="INSERT into kmmb_member1(docx_id,no_ahli,no_pin,nama,no_ic_baru,no_ic_lama) values('$data[0]','$data[1]','$data[2]','$data[3]','$data[4]')"; mysql_query($import) or die(mysql_error()); } } fclose($handle); print "Import done"; } else { echo "There was an error uploading the *.csv file, please try again!"; } } else { ?> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title></title> <script type="text/javascript"> var swfu; SWFUpload.onload = function () { var settings = { flash_url : "swf_up/swfupload/swfupload.swf", flash9_url : "swf_up/swfupload/swfupload_fp9.swf", upload_url: "swf_up/upload.php", post_params: { "PHPSESSID" : "NONE", }, file_size_limit : "100 MB", file_types : "*.wav", file_types_description : "Wave Files", file_upload_limit : 100, file_queue_limit : 0, custom_settings : { progressTarget : "fsUploadProgress", cancelButtonId : "btnCancel" }, }; swfu = new SWFUpload(settings); } </script> </head> <body> <div id="content"> <h2>Upload</h2> <form id="form1" action="index.php" method="post" enctype="multipart/form-data"> <div id="divSWFUploadUI" style="margin-top: 20px;"> <span>Select .csv file: <input name='uploadedfile' type='file' /><br /> </span> <div class="fieldset flash" id="fsUploadProgress"> <span class="legend">Upload Queue</span> </div> <p id="divStatus">0 Files Uploaded</p> <p> <span id="spanButtonPlaceholder"></span> <input id="btnCancel" type="button" value="Cancel All Uploads" disabled="disabled" style="margin-left: 2px; height: 22px; font-size: 8pt;" /> <br /> </p> </div> </form> </div> </body> </html> <?php } ?> I am creating a user inbox system. I am retrieving all the unread messages. Each message row contains a "reply" form. So say I have 10 messages showing on a single page. That's 10 forms. What I would like to know is how can I submit any one of the 10 forms and not have it affect the remaining 9 forms? Here is the basic code. if(isset($_POST['submit'])) { $post_message = trim($_POST['message']); $errors = array(); $db->beginTransaction(); if(empty($post_message)) { $errors[] = 'The message field can not be empty!'; } if(empty($errors)) { $db->commit(); echo 'success'; } else { $db->rollBack(); } } <form action="" method="post"> <fieldset> <textarea name="message" maxlength="10000" placeholder="What would you like to say?"></textarea> </fieldset> <fieldset> <input type="submit" name="submit" value="Submit" /> </fieldset> </form>
hirealimo.com.au/code1.php this works as i want it: Quote SELECT * FROM price INNER JOIN vehicle USING (vehicleID) WHERE vehicle.passengers >= 1 AND price.townID = 1 AND price.eventID = 1 but apparelty selecting * is not a good thing???? but if I do this: Quote SELECT priceID, price FROM price INNER JOIN vehicle....etc it works but i lose the info from the vehicle table. but how do i make this work: Quote SELECT priceID, price, type, description, passengers FROM price INNER JOIN vehicle....etc so that i am specifiying which colums from which tables to query?? thanks I have a column in my db called 'Sold' which is set to Binary. I need a dropdown in my form, that converst the binary into 'True', 'False' for the options, and also selects the one that is set in the db. This is for an edit form, so will then need to adapt it for a add form. This is my code, which doesnt seem to be working <?php $id = $_GET["id"]; $sqlSold = "SELECT Sold FROM Products WHERE idProducts = $id;"; $products = [ 'True' => true, 'False' => false ]; ?> <select name="Sold"> <option selected="selected">Choose one</option> <?php foreach($products as $item){ echo "<option value='strtolower($item)'>$item</option>"; } ?> </select>
I have some code that selects one column from mysql table. However when I try to add more it doesn't work.
First the working code....
$query = "SELECT `profile_privacy` FROM `users` WHERE `user_username` = '$username'"; $result = mysql_query($query) or die($query."<br/><br/>".mysql_error()); $profile_privacy = mysql_result($result, 0);And here is where I have added another column.... $query = "SELECT `profile_privacy`, `profile_pictures` FROM `users` WHERE `user_username` = '$username'"; $result = mysql_query($query) or die($query."<br/><br/>".mysql_error()); $profile_privacy = mysql_result($result, 0); $profile_pictures = mysql_result($result, 1);What have I done wrong? Many thanks, Hi all: I start an application in PHP and SQL Server for a company car and I need some recommendations. The application tracked him to the maintenance of the cars. On one side are the car brands (Ford, Chevrolet, etc.) with the relevant goods and associated services. A relationship many-to-many. On the other hand, the executives (stage 1) enter the customer associated with their cars and the corresponding products and services. The customer goes to the mechanic who performs the action (step 2) and finally counter that the collection (step 3). My main problem is how to link Client - Automobile - Services in the first form. Enter the name and telephone number after a multi-select will select the brand and asynchronously checkbox must be loaded in all services and check the corresponding to that mark. I find it difficult to incorporate all the links on the form. Appreciate design recommendations database (customer table) and how to assemble the form. Maybe some of you made any similar application or know a reference. Finally thank you in advance for the time can provide for review this post. I'm having a hard time grasping how to select data from several tables. Here's the code Code: [Select] <?php require_once "config.php"; $gamedate = $_SESSION['date']; echo "These umpires are not currently scheduled on this date, and have not asked for the day off:<br />"; $umpirelist = Array('umpire 1 name', 'umpire 2 name', 'umpire 3 name'); $dbc = mysql_pconnect($host, $username, $password); mysql_select_db($db,$dbc); foreach($umpirelist as $data) { //now get stuff from a table $sql = "SELECT calendar.date, calendar.ump1, calendar.ump2, calendar.ump3, calendar.ump4, calendar.ump5, vacation.date, vacation.umpire FROM umps, calendar, vacation WHERE umps.full_name = $data AND $gamedate = `calendar.date` AND $gamedate = `vacation.date` AND $data NOT IN ('calendar.ump1', 'calendar.ump2', 'calendar.ump3', 'calendar.ump4', 'calendar.ump5') AND $data NOT IN ('vacation.umpire') order by umps.full_name asc"; $rs = mysql_query($sql,$dbc); $matches = 0; while ($row = mysql_fetch_assoc($rs)) { $matches++; echo "$row[$data]<br />"; } } ?> The table CALENDAR holds the date of the game, who is playing, and what umpires are schedule for that game. it does have a unique "row_number" column as well, but didn't think I'd need it in this select. The table VACATION has the date, and umpire's name that is on vacation. The table UMPS contains the umpires name (same names as the array in the code) and email addresses and login info. I'm getting this error: Quote Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource on line 152 This is line 152 Quote while ($row = mysql_fetch_assoc($rs)) { Can someone please point me in the right direction as to where I'm going wrong? Thanks! Hello, I'm using PHP and I have a list box where I should be able to select multiple values, that I then submit to run multiple reports. However, when I select two values I only get results for the last selected value instead of both value a & value b. Can anyone help me with my problem? Code: [Select] <td style="text-align: right">Job Type:</td> <td> <select name="job_type" multiple="multiple" size="4"> <option value="0" selected>ALL</option> {section name=jt loop=$job_type_list} <option value="{$job_type_list[jt][0]}">{$job_type_list[jt][1]}</option> {/section} </select> </td> I've read that I can change name="job_type" to name="job_type[]", but I'm not getting any luck with that... I'm trying to select multiple peoples ID's where different values in different databases tables match. For instance, I want to make sure the person is a different gender than what the person logging in is, which would be set as 1(male) 2(female) in a Genders Column in the Membership_Profile table, while I am also checking to make sure that they are not blocked inside the Membership table and making sure they have a profile image in a user_profilepic table. How would I do this? This all needs to sort by the Date they were added inside the Membership Table and Limit it to 5 results. When I use the below code tho, it pulls up both Male and Females, but seems to look at the Membership correctly. Code: [Select] $sql2 = "SELECT Gender FROM Membership_Profile where UserID = '$user_ID'"; $sql_result2 = mysql_query($sql2); $login_row2 = mysql_fetch_assoc($sql_result2); $user_gender = $login_row2['Gender']; $true_query = mysql_query("SELECT Membership.ID, Membership_Profile.ID, user_profilepic.UserID FROM Membership, Membership_Profile, user_profilepic WHERE Membership_Profile.Gender != '$user_gender' AND Membership.ID = user_profilepic.UserID AND Membership.IsApproved='1' AND Membership.IsLockedOut = '0' AND Membership.UserLevel = '1' AND user_profilepic.Profile_Pic = '1' ORDER BY Membership.CreateDate DESC LIMIT 5;"); $is_odd_row = 1; while ($true_row = mysql_fetch_assoc($true_query)) { $right_user = $true_row['UserID']; $right_user2 = $true_row['ID']; $sql = "SELECT * FROM Users where ID = '$right_user' AND ID = '$right_user2'"; $sql_result = mysql_query($sql); $login_row = mysql_fetch_assoc($sql_result); $right_user_ID = $login_row['ID']; $rightGUID = $login_row['UserId']; $right_name = $login_row['UserName']; $sql = "SELECT DOB, City, State FROM Membership_Profile where ID = '$right_user' AND ID = '$right_user2'"; $sql_result = mysql_query($sql); $login_row = mysql_fetch_assoc($sql_result); $user_dob = $login_row['DOB']; $City = $login_row['City']; $State = $login_row['State']; if ($is_odd_row) { echo "<tr style=\"background-color: #e1ebf8\">\n"; $is_odd_row = 0; } else { echo "<tr style=\"background-color: #f3f7fc\">\n"; $is_odd_row = 1; } echo " <td align=\"left\"> <img width=\"85px\" style=\"margin-right:10px\" src=\"profilepics/$rightGUID/profile/$right_user_ID.jpg\"><br /> <span style=\"font-size:13px; font-weight:900; color:#ffae00;\">$right_name </span><br /> Location:<br /><b>$City, $State</b><br /> Age:<b>";echo CalculateAge("$user_dob"); echo "</b></td></tr>"; } hi im trying to echo out all the possibilities from one column in 2 different tables, both with the same structure. if that makes sense this is what i have $query = mysql_query("SELECT * FROM stanjamesprem,centrebetprem GROUP BY eventname ORDER BY eventtime "); while($row = mysql_fetch_assoc($query)) { echo $row[eventname]; } if i take one of the tables out it works fine but if i have 2 table names it doenst work please help me cheers matt any questions please ask away I'm trying to select multiple peoples ID's where different values in different databases tables match. For instance, I want to make sure the person is a different gender than what the person logging in is, which would be set as 1(male) 2(female) in a Genders Column in the Membership_Profile table, while I am also checking to make sure that they are not blocked inside the Membership table and making sure they have a profile image in a user_profilepic table. How would I do this? This all needs to sort by the Date they were added inside the Membership Table and Limit it to 5 results. When I use the below code tho, it pulls up both Male and Females, but seems to look at the Membership correctly. Code: [Select] $sql2 = "SELECT Gender FROM Membership_Profile where UserID = '$user_ID'"; $sql_result2 = mysql_query($sql2); $login_row2 = mysql_fetch_assoc($sql_result2); $user_gender = $login_row2['Gender']; $true_query = mysql_query("SELECT Membership.ID, Membership_Profile.ID, user_profilepic.UserID FROM Membership, Membership_Profile, user_profilepic WHERE Membership_Profile.Gender != '$user_gender' AND Membership.ID = user_profilepic.UserID AND Membership.IsApproved='1' AND Membership.IsLockedOut = '0' AND Membership.UserLevel = '1' AND user_profilepic.Profile_Pic = '1' ORDER BY Membership.CreateDate DESC LIMIT 5;"); $is_odd_row = 1; while ($true_row = mysql_fetch_assoc($true_query)) { $right_user = $true_row['UserID']; $right_user2 = $true_row['ID']; $sql = "SELECT * FROM Users where ID = '$right_user' AND ID = '$right_user2'"; $sql_result = mysql_query($sql); $login_row = mysql_fetch_assoc($sql_result); $right_user_ID = $login_row['ID']; $rightGUID = $login_row['UserId']; $right_name = $login_row['UserName']; $sql = "SELECT DOB, City, State FROM Membership_Profile where ID = '$right_user' AND ID = '$right_user2'"; $sql_result = mysql_query($sql); $login_row = mysql_fetch_assoc($sql_result); $user_dob = $login_row['DOB']; $City = $login_row['City']; $State = $login_row['State']; if ($is_odd_row) { echo "<tr style=\"background-color: #e1ebf8\">\n"; $is_odd_row = 0; } else { echo "<tr style=\"background-color: #f3f7fc\">\n"; $is_odd_row = 1; } echo " <td align=\"left\"> <img width=\"85px\" style=\"margin-right:10px\" src=\"profilepics/$rightGUID/profile/$right_user_ID.jpg\"><br /> <span style=\"font-size:13px; font-weight:900; color:#ffae00;\">$right_name </span><br /> Location:<br /><b>$City, $State</b><br /> Age:<b>";echo CalculateAge("$user_dob"); echo "</b></td></tr>"; } Code: [Select] if($keyword == ""){}else{ $get = mysql_query("SELECT * FROM domains, domains_keywords, keywords WHERE domains_keywords_domain=domains_id AND domains_keywords_keyword=keywords_id AND keywords_keyword='$keyword'"); } so i have a textbox at the mo that you can put one keyword in and get results based on this one keyword. how can I change this to a textarea and if say someone enters two keywords.. it will find results based on them having both keywords. thanks in advance Hi I want to read multiple .txt files and then if an action requires select one. Quote <? // /home/person-mike.txt // /home/person-sarah.txt // /home/person-paul.txt while ($row = sqlite_fetch_array($result)) { $name = $row['name']; $filename = "/home/person-$name.txt"; $handle = fopen($filename, "r"); $sendrequest = fread($handle, filesize($filename)); fclose($handle); } ?> <? if ( $client == "sarah" ) { echo "$sendrequest[sarah]"; ?> How do I do the last bit to have a variable like $sendrequest[sarah] Hi, I'm a little bit new to php and i'm having a small problem. Let me explain with the script : Code: [Select] <?php //connect to mysql $data = mysql_query("SELECT * FROM forum_topic WHERE topic_id='$topic'") or die(mysql_error()); while($info = mysql_fetch_array( $data )) $dete = mysql_query("SELECT * FROM forum_topic WHERE login='$info['username']'") or die(mysql_error()); while($info2 = mysql_fetch_array( $dete )) { echo "......"; } ?> So I have the first SELECT command that will get the data from table forum_topic and array the data and after that I have a second SELECT that will get the data from table_members but this time time the WHERE clause equals to some data "arrayed" in the first SELECT command...And the end I need to output the data from both tables.... Here's the error I get : Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/content/m/a/z/mazemontana/html/login/forum_viewtopic.php on line 73 ...I know that my syntax is probably not good but can't figure out how to do it..... Any help will be greatly appreciated! Thanx Hi I am trying to have the following as an example: Code: [Select] <select name="test[]" multiple="multiple">options here</select> <select name="test[]" multiple="multiple">options here</select> Then using $_POST['test'] to grab the boxes in the array. I want to then loop over each box so for example: Code: [Select] $boxes = $_POST['test']; foreach ( $boxes as $box ) // now here i would of expected $box to be an array of the options, } but it's not working like this, all the options from all submitted select boxes come in one array so I cannot distinguish which select box in the array they relate to, is there a way to do this?? This has been bugging me for quite a while and I've tried so many different things and just run into all kinds of problems... What I'm doing or trying at least is pulling data from a table displaying it into a multiple select box allowing the user the oppertunity to remove one or more options. As the code stands now I'm getting no value at all in the post variable, by taking the [] brackets out of the inputs name i was able to get the first selected option but the php code was then unable to remove that value from the database. I hope I'm explaining this well enough but the code follows I'd really appreciate some help or direction on this one. The FORM Code: [Select] <FORM action='' method='post'> <select size='8' multiple name='remove_player[]'> <?php foreach ($members as $key => $mem) { if ($mem != "") { $mem = str_replace("-", " ", $mem); $mem = ucwords($mem); echo ("<option value='" . $mem . "'>" . $mem . "</option>"); } } ?> </select> and then the handler code: Code: [Select] $to_remove = $_POST['remove_player']; $as_team = str_replace(" ", "-", $teamname); $as_team = strtolower($as_team); $for_remove = "SELECT * FROM teams WHERE name = '$as_team'"; $for_query = (mysql_query($for_remove)); foreach ($to_remove as $y => $z) { $z = str_replace(" ", "-", $z); $z = strtolower($z); } while($arr_remove = mysql_fetch_array($for_query)) { foreach ($arr_remove as $a => $b) { foreach ($to_remove as $c => $d) { if ($b == $d) { unset($arr_remove[$a]); } } } foreach ($arr_remove as $e => $f) { $add_replace = (mysql_result($for_query, 0, 'members')); $replace = ($add_replace . "\r\n" . $f . "\r\n"); $replace_mem = "UPDATE teams SET members = '$replace'"; $replace_q = (mysql_query($replace_mem)); } } echo "Member List successfully updated.<br>"; foreach ($to_remove as $h => $g) { echo ($g . " removed from the team.<br>"); } Also any time i try to print any part of the array/s I get no values but the database is being updated with 2 line breaks and a "3" at the end of the table which has me a bit confused as well. Thanks! I want to select the user from super_administrators, administrators, teachers and students, and give the user permission based from what table he "came". But is giving the "Query failed" error... Code: [Select] <?php //Start session session_start(); //Include database connection details require_once('../config/config.php'); //Array to store validation errors $errmsg_arr = array(); //Validation error flag $errflag = false; //Connect to mysql server $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } //Function to sanitize values received from the form. Prevents SQL injection function clean($str) { $str = @trim($str); if(get_magic_quotes_gpc()) { $str = stripslashes($str); } return mysql_real_escape_string($str); } //Sanitize the POST values $email = clean($_POST['email']); $password = clean($_POST['password']); //Input Validations if($email == '') { $errmsg_arr[] = 'O campo Email nao foi preenchido.'; $errflag = true; } if($password == '') { $errmsg_arr[] = 'O campo Senha nao foi preenchido.'; $errflag = true; } //If there are input validations, redirect back to the login form if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; session_write_close(); header("location: ../index.php"); exit(); } //Create query $qry = "SELECT * FROM super_administrators,administrators,teachers,students WHERE email = '$email' AND passwd = '".md5($_POST['password'])."'"; $result = mysql_query($qry); $member = mysql_fetch_assoc($result); $table = mysql_field_table('$result', '0'); //Check whether the query was successful or not if($result) { if(mysql_num_rows($result) == 1) { if($table == 'super_administrators') { session_regenerate_id(); $_SESSION['SESS_ID'] = $member['id']; $_SESSION['SESS_NAME'] = $member['name']; $_SESSION['SESS_EMAIL'] = $member['email']; session_write_close(); header("location: ../users/sadmin/index.php"); exit(); } if($table == 'administrators') { session_regenerate_id(); $_SESSION['SESS_ID'] = $member['id']; $_SESSION['SESS_SCHOOL_ID'] = $member['school_id']; $_SESSION['SESS_NAME'] = $member['name']; $_SESSION['SESS_EMAIL'] = $member['email']; session_write_close(); header("location: ../users/admin/index.php"); exit(); } if($table == 'teachers') { session_regenerate_id(); $_SESSION['SESS_ID'] = $member['id']; $_SESSION['SESS_SCHOOL_ID'] = $member['school_id']; $_SESSION['SESS_NAME'] = $member['name']; $_SESSION['SESS_EMAIL'] = $member['email']; session_write_close(); header("location: ../users/prof/index.php"); exit(); } if($table == 'students') { session_regenerate_id(); $_SESSION['SESS_ID'] = $member['id']; $_SESSION['SESS_SCHOOL_ID'] = $member['school_id']; $_SESSION['SESS_CLASS_ID'] = $member['class_id']; $_SESSION['SESS_NAME'] = $member['name']; $_SESSION['SESS_REGISTRATION'] = $member['registration']; $_SESSION['SESS_EMAIL'] = $member['email']; session_write_close(); header("location: ../users/aluno/index.php"); exit(); } } else { $errmsg_arr[] = 'Suas informacoes de login estao incorreta. Por favor, tente novamente.'; $errflag = true; $_SESSION['ERRMSG_ARR'] = $errmsg_arr; session_write_close(); header("location: ../index.php"); exit(); } } else { die("Query failed"); } ?> |