Jump to content
Larry Ullman's Book Forums

jemmm

Members
  • Posts

    8
  • Joined

  • Last visited

Everything posted by jemmm

  1. Thanks for your help. It worked but only when I realised I had closed off the main while loop before this section of code so it couldn't read the $info['checklist_timeframe_id'] so I moved the closing curly bracket to the end of the above section of code and it worked (I had it placed before the above section). A silly mistake on my part! thanks
  2. Hi there, I have an edit details page on my website (php with a mysql database). It contains text boxes which display the information which the user has submitted at an earlier date. If they edit the information in the textbox and click on the submit button, it will update in the database. These work fine without any problems. I now want to add a pulldown menu which will work in the same way by displaying the information that the user saved on a previous visit (but obviously they can choose other options and click submit to save). My problem is that I am only able to show either the first or the list item on the list when the page opens and not the item that the user has selected on the previous visit. Any help would be appreciated. echo '<tr><td>Change Timeframe</td><td> <select name="checklist_timeframe_id">'; //query that will display all the options that the user can select $cq = "SELECT * FROM checklist_timeframe"; $cr=mysqli_query($dbc,$cq) or die(mysqli_error($dbc)." Q=".$cq); //if the query runs successfully if ($cr) { while ($ca = mysqli_fetch_array($cr, MYSQLI_ASSOC)) { echo '<option value="' . $ca['checklist_timeframe_id']; if ($info['checklist_timeframe_id'] ==$ca['checklist_timeframe_id']) { echo '"selected="selected'; } echo '">' . $ca['checklist_timeframe'] . '</option>'; mysqli_free_result($cr);//free up resources } } else { echo '</select>We apologise there seems to be a problem with this data'; } //echo '</select>';
  3. Hi there, I am trying to allow users download a csv file from my website. This is the code I've been trying to use but it just opens a blank page and doesn't download anything. Any advice? <?php require_once (MYSQL); require_once ('mysqli_connect.php'); $q="SELECT * FROM table_name"; $r = @mysqli_query($dbc, $q); $html = "<table>"; $html .= "<tr><td>Song</td>"; $html .= "</tr>"; while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { $html .= "<tr><td>".$row['music_song']."</td>"; $html .= "</tr>"; } $html .= "</table>"; header("Content-Type: text/csv"); header("Content-Disposition: attachment;filename=yourfile.csv"); echo $html; ?>
  4. Hi all, I'm am wondering if anyone can give me any pointers in the right direction for my current issue. I have three search fields on a page, 'keyword', 'county' and 'supplier_type' with a submit button below. The keyword field is a text box and the other two fields are drop down menus which take the data from the mysql database. When searching users have the option to enter nothing, one field, two fields or three fields. Following this I have determined that there are 8 possible ways that users can search: 1). keyword only 2). county only 3). supplier_type only 4). keyword and county only 5). Keyword and supplier_type only 6). County and supplier_type only 7). All fields- Keyword, county and supplier_type 8). no data entered by user The code below displays the form on the page <h1>Search</h1> <form action="suppliersresults.php" method="post"> <fieldset> <p><b>Supplier Name Keyword Search:</b> <input type="text" name="keyword" size="20" maxlength="40" value="<?php if (isset($trimmed['keyword'])) {echo $trimmed['keyword'];} else {echo 'keyword';} ?>" /></p> <p><b>Supplier Location:</b></p> <select name="county" id="county" class="formtext"> <?php echo"<option value='all' selected='selected'>all</option>"; require_once('includes/config.inc.php'); $cq = "SELECT county FROM county_table ORDER BY county ASC"; $cr = @mysqli_query($dbc, $cq); if ($cr) { while ($ca = mysqli_fetch_array($cr, MYSQLI_ASSOC)) { echo '<option value="' . $ca['county'] . '">' . $ca['county'] . '</option>'; } mysqli_free_result($cr);//free up resources } else { echo '</select>We apologise there seems to be a problem with this data'; } ?> </select> <p><b>Supplier Type:</b></p> <select name="supplier_type_id" id="supplier_type_id" class="formtext"> <?php //the below code is for when the user selects all supplier types. Commenting out until get it to work first. //echo"<option value='all' selected='selected'>All</option>"; echo"<option value='all' selected='selected'>all</option>"; require_once('includes/config.inc.php'); $cq = "SELECT supplier_type_id, supplier_type_name FROM supplier_type ORDER BY supplier_type_name ASC"; $cr = @mysqli_query($dbc, $cq); if ($cr) { while ($ca = mysqli_fetch_array($cr, MYSQLI_ASSOC)) { echo '<option value="' . $ca['supplier_type_id'] . '">' . $ca['supplier_type_name'] . '</option>'; } mysqli_free_result($cr);//free up resources } else { echo '</select>We apologise there seems to be a problem with this data'; } ?> </select> </fieldset> <div align="center"><input type="submit" name="submit" value="Search" /></div> <input type="hidden" name="submitted" value="TRUE" /> </form> I have tested this and it correctly send the data through to suppliersresults.php but my problem is with the searching mechanism. Perhaps this is the wrong way of thinking but I have created if statements but they are not returning the correct data in all occasions. //set variables $county = $_POST['county']; $supplier_type_id = $_POST['supplier_type_id']; $keyword = $_POST['keyword']; ///////////////////////////////////////////////// //if the user doesnt' enter anything in any field on the search page except for a keyword - 1 if (isset ($_POST['supplier_type_id']) == 'all' && ($_POST['county']) == 'all' && ($_POST['keyword']) <> 'keyword') //search for a supplier name keyword search $q = "SELECT * FROM supplier_details WHERE supplier_name LIKE '$keyword%' ORDER BY registration_date ASC"; //if the user doesnt' enter anything in any field on the search page except for a county - 2 if (isset($_POST['supplier_type_id']) == 'all' && ($_POST['keyword']) == 'keyword' && ($_POST['county']) <> 'all') //search for a supplier name search $q = "SELECT * FROM supplier_details WHERE county='$county' ORDER BY registration_date ASC"; //if the user doesnt' enter anything in any field on the search page except for a supplier type - 3 if (isset ($_POST['keyword']) == 'keyword' && ($_POST['county']) == 'all' && ($_POST['supplier_type_id']) <> 'all') $q = "SELECT * FROM supplier_details WHERE supplier_type_id='$supplier_type_id' ORDER BY registration_date ASC "; //if the user enters a keyword and county AND NOT a supplier_type_id - 4 if (isset ($_POST['supplier_type_id']) == 'all' && ($_POST['county']) <> 'all' && ($_POST['keyword']) <> 'keyword') $q = "SELECT * FROM supplier_details WHERE county='$county' AND supplier_name LIKE '$keyword%' ORDER BY registration_date ASC"; //if the user enters a supplier_type_id AND a keyword AND NOT a county - 5 if (isset ($_POST['county']) == 'all' AND ($_POST['keyword']) <> 'keyword' AND ($_POST['supplier_type_id']) <> 'all' ) $q = "SELECT * FROM supplier_details WHERE supplier_type_id='$supplier_type_id' AND supplier_name LIKE '$keyword%' ORDER BY registration_date ASC"; //if the user enters a county AND a supplier_type_id AND NOT a keyword - 6 if(isset ($_POST['keyword']) == 'keyword' && ($_POST['supplier_type_id']) <> 'all' && ($_POST['county']) <> 'all') $q = "SELECT * FROM supplier_details where supplier_type_id='$supplier_type_id' AND county='$county' ORDER BY registration_date ASC"; //if the user enters a county AND a supplier_type_id AND a keyword - 7 if (isset($_POST['supplier_type_id']) <> 'all' && ($_POST['county']) <> 'all' && ($_POST['keyword']) <> 'keyword') $q = "SELECT * FROM supplier_details WHERE supplier_name LIKE '$keyword%' AND supplier_type_id='$supplier_type_id' AND county='$county' ORDER BY registration_date ASC"; //if the user doesn't enter anything - 8 if (isset($_POST['supplier_type_id']) == 'all' && ($_POST['county']) == 'all' && ($_POST['keyword']) == 'keyword') $q = "SELECT * FROM supplier_details ORDER BY registration_date ASC"; Could anyone give me some guidance on where I am going wrong? Many thanks!
  5. Thanks so much for sending that link. I had to play around with it to use it with my email provider but in the end..it worked!! It's made my week! Thanks again!! Your help is much appreciated!
  6. Hi there, I'm new to php and I was wondering if it is possible to send the account activation email referred to in chapter 16 of the book using localhost and if so if anyone has any information on how to go about doing this. I am using Wamp Server and Php MyAdmin. Many Thanks
×
×
  • Create New...