Jump to content

cyberRobot

Moderators
  • Posts

    3,145
  • Joined

  • Last visited

  • Days Won

    37

Everything posted by cyberRobot

  1. Your calling mysql_fetch_array() twice. The first one processes the row leaving the second one with no results. Remove the first function call. $sql="SELECT * FROM users WHERE username='$myusername' and password='$mypassword'"; $result= mysql_query($sql) or die(mysql_error()); $row= mysql_fetch_array($result); //<-- REMOVE THIS // If result matched $myusername and $mypassword, table row must be 1 row if($row = mysql_fetch_array($result)) { header("Location: welcome.php"); exit; } Also, remember to add the call to "exit" after the header() function.
  2. Is the session being started before you use the session variable?
  3. You'll also get an undefined variable message if you don't use session_start().
  4. Also note that you could skip the mysql_num_rows() function altogether. The mysql_fetch_array() function returns false when there are no rows. Otherwise, it returns a value which will equate to true. // If result matched $myusername and $mypassword, table row must be 1 row if($row = mysql_fetch_array($result)) { header('Location: welcome.php'); exit; }
  5. By "highlight the fields", do you mean that you don't those fields (the ones which haven't been completed) included in the email? If so, you can use isset(): <?php //... $body = " From: $title_field\n\n Your_first_name: $your_first_name_field"; if(isset($your_second_name_field)) { $body .= "\n\n Your_second_name: $your_second_name_field"; } $body .= "\n\n Your_home_address: $your_home_address_field\n\n Post_code: $post_code_field\n\n Email: $email_field\n\n $landline_number\n\n Mobile_phone: $mobile_phone_field\n\n Subject_required: $subject_required_field\n\n Level_of_study: $level_of_study_field\n\n Name_of_school: $name_of_school_field\n\n Nature_of_help: $nature_of_help_required_field\n\Able_to_travel: n $able_to_travel_field\n\n "; ?> Also, when posting code to the forum in the future, please surround the code with tags. It makes the code and your post easier to follow.
  6. Did the code get cut off? Or are you just wondering about the errors caused by the missing closing brackets? <?php if ($_POST ['formsubmit'] == 'submit') { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "xxxxxxxxxxxx"; $email_subject = "Enquiry Form"; function died($error) { } } ?>
  7. You could use something like FPDF: http://www.fpdf.org/
  8. The echo statement needs to be inside the quotes here: <td><img src="<?php echo $picture;?>" height="100" width="100"></td> Also note that I added the end ">" for the image tag.
  9. You could use a hidden field to run the function. For example: <?php function doThis() { echo "Do this Function"; } if(isset($_POST['runFunction'])) { doThis(); } ?> <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" > <input type="text" name="regName" value=""> <input type="hidden" name="runFunction" value="1"> <input type="submit"> </form>
  10. JavaScript/jQuery can be used to filter the information passed through a form. One scenario where this could be useful is with registration forms. For example, the form may have a Yes/No question on whether the registrant is planning to attend the meals. If they check no, you probably don't need any of the follow-up responses. If the registrant isn't going to the meals, it's unlikely that we'll need to know if they're bringing someone to those meals. Note that I typically use PHP to handle this type of filter, but it can also be accomplished with JavaScript/jQuery.
  11. Moving to PHP Coding Help forum.
  12. You could use JavaScript to populate the second dropdown based on the selection from the first. Perhaps you could find something here: https://www.google.com/search?q=javascript+populate+dropdown+based+on+another+dropdown
  13. You could also consider using opendir() to get all the CSV file names: http://www.php.net/manual/en/function.opendir.php From there you can loop through the files to find the most recent version.
  14. Is there another PHP script which creates the CSV file? If so, you could save the file names to a database. Then you would just need to query the database to get the most recent file.
  15. Instead of using carriage returns, did you try the break tag (<br>)? <div><a href="#a">A</a><br /><a href="#b">B</a></div> Or better yet, you could use a unordered list and use CSS to remove the bullets. <style type="text/css"> .letterLinks { list-style:none; margin:0; padding:0; } </style> <ul class="letterLinks"> <li><a href="#a">A</a></li> <li><a href="#b">B</a></li> </ul>
  16. I personally would store all the tables in an array and then use array_chunk() to break them into groups of three. For example, you could try something like the following: <?php // Connect to the MySQL database include "storescripts/connect_to_mysql.php"; // This block grabs the whole list for viewing //INITIALIZE VARIABLES $tableArray = array(); //LOOP THROUGH PRODUCT INFORMATION $sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC"); while($row = mysql_fetch_array($sql)) { $tableArray[] = '<table width="20%" border="1" cellspacing="0" cellpadding="4"> <tr> <td><a href="product.php?id='.$row['id'].'"><img src="inventory_images/'.$row['id'].'.jpg" width="243" border="1" height="240" alt="$dynamicTitle" /></a></td> </tr> <tr> <td> ' .$row['product_name'] . '</br> <hr> $ ' .$row['price'] . '</br> <hr> <a href="product.php?id='.$row['id'].'">View Product Details</a></td> </tr> </table>'; } mysql_close(); //IF PRODUCTS WERE FOUND, DISPLAY THEM if(!empty($tableArray)) { $tableArray = array_chunk($tableArray, 3); foreach($tableArray as $tableGroup) { echo '<table border="0" cellpadding="4">'; echo '<tr>'; foreach($tableGroup as $currTable) { echo "<td>$currTable</td>"; } echo '</tr>'; echo '</table>'; } //ELSE...NO PRODUCTS } else { echo 'We have no products listed in our store yet'; } ?> Note that I got rid of some extra variables. Instead of using $id, for example, I just used the $row['id'] variable. It requires fewer lines of code and requires less overhead since PHP doesn't need to maintain duplicate variables.
  17. For what it's worth, the original form (with the radio buttons) works fine for me. Well, except for the $about variable being enclosed in single quotes. <textarea name='about' value='about'><?php echo '$about'; ?></textarea><br /> You either need to use double quotes or they could be left off altogether. <textarea name='about' value='about'><?php echo $about; ?></textarea><br /> Perhaps there was a MySQL error, did you try using mysql_error()? More information and examples can be found here: http://www.php.net/mysql_error Did you try seeing what the variables contained? For example, the following would have told you if your location variables actually contained any data: $location = mysql_real_escape_string($_POST['location']); var_dump($_POST['location']); var_dump($location);
  18. You could also consider Authorize.Net: http://www.authorize.net/
  19. Perhaps it's a case issue? You could trying using strtolower() on the $ext variable. http://www.php.net/strtolower
  20. Since it sounds like you're processing the $constructors array in groups of two, have you considered using array_chunk()? http://www.php.net/manual/en/function.array-chunk.php
  21. The following line of code will eventually store all the IDs processed by the while loop? $ID[] = $row["ID"]; Is there a reason you're storing the IDs? If not, you could just use the $row['ID'] variable. For example: $sql2="SELECT * FROM tblRates_balance where depratecat='{$row['ID']}' ORDER BY suborder";
  22. You could store the value as a class property: http://www.php.net/manual/en/language.oop5.properties.php
  23. No problem; glad to help! For what it's worth, you could simplify the code a bit by changing the quotes around your strings. Instead of using double quotes around the <form> tag, for example, you could use single quotes. That way you don't need to escape the double quotes within the double-quoted string. echo '<form action="post.php" method="post" />'; For more information about displaying strings, see the following manual page: http://www.php.net/manual/en/language.types.string.php
  24. If you want to use the POST method, you need to remove the space from the method attribute: echo "<form action=\"post.php\" method=\"post\" />";
  25. In your foreach loop below, try adding another echo statement: foreach($post['files'] as $file){ echo "<div>$file_folder$file</div>"; //<-- ADD THIS $zip->addFile($file_folder.$file); // Adding files into zip } Does it display the correct path for the files? Also note the following quote from the manual (http://www.php.net/manual/en/function.header.php): Having the echo statements to see what the path contains will mess up your header() calls later on. For those interested, here is FourPart's code broken up. Of course, it may not be exact. <?php $error = ""; //error holder if(isset($_POST['createpdf'])){ $post = $_POST; $file_folder = $_SERVER['DOCUMENT_ROOT'].'/members/content/summer2014/downloads/files'; // folder to load files echo "$file_folder"; // I just put this in to keep tabs on the value of $file_folder if(extension_loaded('zip')){ // Checking ZIP extension is available if(isset($post['files']) and count($post['files']) > 0){ // Checking files are selected $zip = new ZipArchive(); // Load zip library $zip_name = time().".zip"; // Zip name if($zip->open($zip_name, ZIPARCHIVE::CREATE)!==TRUE){ // Opening zip file to load files $error .= "* Sorry ZIP creation failed at this time"; } foreach($post['files'] as $file){ print "<div>$file_folder$file</div>"; $zip->addFile($file_folder.$file); // Adding files into zip } $zip->close(); if(file_exists($zip_name)){ // push to download the zip header('Content-type: application/zip'); header('Content-Disposition: attachment; filename="'.$zip_name.'"'); readfile($zip_name); // remove zip file is exists in temp path unlink($zip_name); } } else $error .= "* Please select file to zip"; }else $error .= "* You dont have ZIP extension"; } ?> . . . <?php if(!empty($error)) { echo $error; } ?>
×
×
  • 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.