Jump to content

rocky48

Members
  • Posts

    261
  • Joined

  • Last visited

Everything posted by rocky48

  1. I feel a right twit! Such a basic mistake. I didn't put the php tags around the class file. The fact that the contents of the class file where printed out above the error should have made realise that it was not being parsed.
  2. I did wonder about that, so I tried it with the 'r' on the end. Still gave an error! I assumed that it should have been SessionManager, as that was the name that was declared as the class. These are the lines in login that call the class file: include('includes/SessionManage.php'); SessionManager::sessionStart('login');
  3. I am trying to get to grips with secure sessions on a login page I am writting. Doing some research on Google I found an article called 'How to Create Bulletproof Sessions. The first thing the article was to write a class called SessionManager, which I called SessionManage.php I include this file like so: 'include('includes/SessionManage.php');' The class file: class SessionManager { static function sessionStart($name, $limit = 0, $path = '/', $domain = null, $secure = null) { // Set the cookie name before we start. session_name($name . '_Session'); // Set the domain to default to the current domain. $domain = isset($domain) ? $domain : isset($_SERVER['SERVER_NAME']); // Set the default secure value to whether the site is being accessed with SSL $https = isset($secure) ? $secure : isset($_SERVER['HTTPS']); // Set the cookie settings and start the session session_set_cookie_params($limit, $path, $domain, $secure, true); session_start(); } } The article says to use this in your code you type one of the following: I just used login as the installation name. When I now run the code I get the following Fatal Error: Above the error information the complete code for the class file is printed. I am obviously have not got the syntax correct, but searching the internet has not helped. Can anybody point out where I am going wrong?
  4. Sorry solved it! Put the logout.php in the wrong folder. Should not have been in the includes folder.
  5. I am coding some pages for a club website, where I want to restrict access to a members area. I have got the logging in all working, but I have just introduced logout.php to logout of the restricted area. When I run this file I get the following error: This is wierd, as the file is certainly there, as I use this file in each header file. Here is the logout.php file: <?php # Script 16.9 - logout.php // This is the logout page for the site. require_once ('includes/config.inc.php'); $page_title = 'Logout'; include ('includes/header1.html'); // If no first_name session variable exists, redirect the user: if (!isset($_SESSION['first_name'])) { $url = BASE_URL . 'index.php'; // Define the URL. ob_end_clean(); // Delete the buffer. header("Location: $url"); exit(); // Quit the script. } else { // Log out the user. $_SESSION = array(); // Destroy the variables. session_destroy(); // Destroy the session itself. setcookie (session_name(), '', time()-300); // Destroy the cookie. } // Print a customized message: echo '<h3>You are now logged out.</h3>'; include ('includes/footer1.html'); ?> I'm wondering if it's anything to do with my session? The seesion starts when the user logs in. How do you maintain the session on all of the pages that I may add in the members area, until they logout? Any advice would be appreciated!
  6. Membership number is as shown in the example. I.e. A123456 One letter (A to Z) and a 6 digit number. However, could it be set to accept either upper-case letter and if the user left a space between the letter and the number. By the way the /P.P/ thing according to the information on the web it matches a single character. It's a pity that the PHP reference does not show the valid syntax for the preg_match command.
  7. I am trying to use preg_match to check whether a membership number has been entered in the form 'A123456'. I have found a site on the web that shows the types of string syntax that can be used to check a string, so I have come up with the following: preg_match ('/P.P/ \d{6}', $trimmed['BMFA_No']) However when run I get the following error: An error occurred in script D:\wamp\www\MFC1066\Reg1.php on line 19: preg_match(): Unknown modifier '\' Obviously I have the syntax wrong, but as I have never used this command before I am unsure where this is wrong. I am sure that someone out there is much more experienced that me and can solve this easily.
  8. I have admitted defeat and taken the easier option: Changed: require_once('MYSQL'); to require_once('includes/Connect_login.php');
  9. Little confused! What script are you refering to? config.inc.php? Require INSTEAD of Define?
  10. Right Tried this, but still the same error: Without the second slash it errors on line 50. This was pointed out to me on another forum. Am I right in assuming that htdocs is equivalent to www in WAMP?
  11. A copying error! The one I ran only had 2 slashes!
  12. I am trying to use some code which has com from the Larry Ullman book 'PHP 6 and MYSQL 5'. I think I have got the path wrong. Here is the error that has printed: Here is the Config.inc.php file that includes the file: <?php # Script 16.3 - config.inc.php /* This script: * - define constants and settings * - dictates how errors are handled * - defines useful functions */ // Document who created this site, when, why, etc. // ********************************** // // ************ SETTINGS ************ // // Flag variable for site status: define('LIVE', FALSE); // Admin contact address: define('EMAIL', 't.e.hudson@btinternet.com'); // Site URL (base for all redirections): define ('BASE_URL', 'http://localhost/'); // Location of the MySQL connection script: define ('MYSQL', 'D:\wamp\www\\'); // Adjust the time zone for PHP 5.1 and greater: date_default_timezone_set("Europe/London"); // ************ SETTINGS ************ // // ********************************** // // ****************************************** // // ************ ERROR MANAGEMENT ************ // // Create the error handler: function my_error_handler ($e_number, $e_message, $e_file, $e_line, $e_vars) { // Build the error message. $message = "<p>An error occurred in script $e_file on line $e_line: $e_message\n<br />"; // Add the date and time: $message .= "Date/Time: " . date("j-n-Y H:i:s") . "\n<br />"; // Append $e_vars to the $message: $message .= "<pre>" . print_r ($e_vars, 1) . "</pre>\n</p>"; if (!LIVE) { // Development (print the error). echo '<div class ="error">' . $message . '</div><br />'; } else { // Do not show the error: // Send an email to the admin: mail(EMAIL, 'Site Error!', $message, 'From: email@example.com'); // Only print an error message if the error isn't a notice: if ($e_number != E_NOTICE) { echo '<div class="error">A system error occurred. We apologize for the inconvenience.</div><br />'; } } // End of !LIVE IF. } // End of my_error_handler() definition. // Use my error handler. set_error_handler ('my_error_handler'); // ************ ERROR MANAGEMENT ************ // // ****************************************** // ?> Is it the way I have written the path? Should it be relative to the root folder? I am using WAMP. In the book I am using it says that it should be in the same folder as htdocs, but does this equate to the www folder on WAMP? It is not opening the MySQL database. I have run the connection script and it does connect to the database. Here is the registration script: <?php # Script 16.6 - register.php // This is the registration page for the site. require_once ('includes/config.inc.php'); $page_title = 'Register'; include ('includes/header.html'); if (isset($_POST['submitted'])) { // Handle the form. require_once('MYSQL'); // Trim all the incoming data: $trimmed = array_map('trim', $_POST); // Assume invalid values: $fn = $ln = $e = $p = FALSE; // Check for a first name: if (preg_match ('/^[A-Z \'.-]{2,20}$/i', $trimmed['first_name'])) { $fn = mysqli_real_escape_string ($dbc, $trimmed['first_name']); } else { echo '<p class="error">Please enter your first name!</p>'; } // Check for a last name: if (preg_match ('/^[A-Z \'.-]{2,40}$/i', $trimmed['last_name'])) { $ln = mysqli_real_escape_string ($dbc, $trimmed['last_name']); } else { echo '<p class="error">Please enter your last name!</p>'; } // Check for an email address: if (preg_match ('/^[\w.-]+@[\w.-]+\.[A-Za-z]{2,6}$/', $trimmed['email'])) { $e = mysqli_real_escape_string ($dbc, $trimmed['email']); } else { echo '<p class="error">Please enter a valid email address!</p>'; } // Check for a password and match against the confirmed password: if (preg_match ('/^\w{4,20}$/', $trimmed['password1']) ) { if ($trimmed['password1'] == $trimmed['password2']) { $p = mysqli_real_escape_string ($dbc, $trimmed['password1']); } else { echo '<p class="error">Your password did not match the confirmed password!</p>'; } } else { echo '<p class="error">Please enter a valid password!</p>'; } if ($fn && $ln && $e && $p) { // If everything's OK... // Make sure the email address is available: $q = "SELECT user_id FROM users WHERE email='$e'"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); if (mysqli_num_rows($r) == 0) { // Available. // Create the activation code: $a = md5(uniqid(rand(), true)); // Add the user to the database: $q = "INSERT INTO users (email, pass, first_name, last_name, active, registration_date) VALUES ('$e', SHA1('$p'), '$fn', '$ln', '$a', NOW() )"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); if (mysqli_affected_rows($dbc) == 1) { // If it ran OK. // Send the email: $body = "Thank you for registering at <whatever site>. To activate your account, please click on this link:\n\n"; $body .= BASE_URL . 'activate.php?x=' . urlencode($e) . "&y=$a"; mail($trimmed['email'], 'Registration Confirmation', $body, 'From: admin@sitename.com'); // Finish the page: echo '<h3>Thank you for registering! A confirmation email has been sent to your address. Please click on the link in that email in order to activate your account.</h3>'; include ('includes/footer.html'); // Include the HTML footer. exit(); // Stop the page. } else { // If it did not run OK. echo '<p class="error">You could not be registered due to a system error. We apologize for any inconvenience.</p>'; } } else { // The email address is not available. echo '<p class="error">That email address has already been registered. If you have forgotten your password, use the link at right to have your password sent to you.</p>'; } } else { // If one of the data tests failed. echo '<p class="error">Please re-enter your passwords and try again.</p>'; } mysqli_close($dbc); } // End of the main Submit conditional. ?> <h1>Register</h1> <form action="register.php" method="post"> <fieldset> <p><b>First Name:</b> <input type="text" name="first_name" size="20" maxlength="20" value="<?php if (isset($trimmed['first_name'])) echo $trimmed['first_name']; ?>" /></p> <p><b>Last Name:</b> <input type="text" name="last_name" size="20" maxlength="40" value="<?php if (isset($trimmed['last_name'])) echo $trimmed['last_name']; ?>" /></p> <p><b>Email Address:</b> <input type="text" name="email" size="30" maxlength="80" value="<?php if (isset($trimmed['email'])) echo $trimmed['email']; ?>" /> </p> <p><b>Password:</b> <input type="password" name="password1" size="20" maxlength="20" /> <small>Use only letters, numbers, and the underscore. Must be between 4 and 20 characters long.</small></p> <p><b>Confirm Password:</b> <input type="password" name="password2" size="20" maxlength="20" /></p> </fieldset> <div align="center"><input type="submit" name="submit" value="Register" /></div> <input type="hidden" name="submitted" value="TRUE" /> </form> <?php // Include the HTML footer. include ('includes/footer.html'); ?> Your help would be appreciated!
  13. I did not know until now, how useful view source can be for debuging scripts. I could see how the script had generated the html select code and then after reading maxxd's post, it dawned on me why the following script was not producing any results. I was assuming that the Form Name was as I had defined it, but seeing the source code revealed to me that the function was already generating that as event and mood and posting these values. So the script on post #37 is the one that was pretty much as the final script.
  14. I know what what the script is supposed to be doing and the previous version of the script works OK, but I wanted the selection lists to: (a) to show a value from the list and not a blank line. (b) To be able to choose what value in the list is shown as default [as an html select list can do] © be able to post the user selection for use in the following script. I am not sure if it is me not understanding you or you not understandin me! The buildseleletoptions dropdown list is supposed to replace an html selection options list, but generated from a DBase. As I explained above if I put the options tags around the php code I loose the list. If you run the following you will see the result: www.1066cards4u.co.uk/alt_inputform6.php If you want to see the way the live site is running at present, just select the Verses tab, then the Verse Printing Utility button and make some choices to follow the program thro.
  15. Right! I changed as you suggested and guess what the dropdown lists were shown with defaults selected. Great I thought But Now when I click on an Event and a Mood nothing is posted to the following script. Ahh! i thought, somehow during the multiple postings it was suggested that I remove the option tags, so I modified the script. Now no lists at all. So i seemed to have gone around in circles and landed up where I started. How can I get the value that the user selects from the list to be posted for the next script? Do you add another parameter to the function? I'm afraid I am a little out of my depth to modify this so I will leave it to you experts to suggest a solution.
  16. Firstly regarding the connection script - I do have two! The one shown is for the localhost with the correct values to connect to my local MYSQL. The best way of showing you the actual errors is to send a screen dump, which is attached. I have tested copies of the previous script and that works OK with the same connection file. I am sure the answer lies within the script. Here it is again: <?php include ("connect_Verses4Cards_LOCAL.php"); $conn = get_db_conn_verse(); //Function to build select options based on passed array function buildSelectOptions($name, array $options, $current=null){ $htmlString = "<select name='{$name}' id='{$name}'>\n"; foreach($options as $value=>$option){ $htmlString .= "\t<option value='{$value}'"; if($value == $current){ $htmlString .= " selected"; } $htmlString .= ">{$option}</option>\n"; } $htmlString .= "</select>\n"; return $htmlString; } function getEvents($conn){ $qry = "SELECT id ,Event_Type FROM events ORDER BY id"; $sql = mysqli_query($conn, $qry)or die(mysqli_error($conn)); if(mysqli_num_rows($sql) < 1){ return array(); } while($res1 = mysqli_fetch_array($sql)){ $ret1[$res1['id']] = $res1['Event_Type']; } return $ret1; } function getMoods($conn){ $qry = "SELECT id ,Event_Sub_Type FROM Event_Sub ORDER BY id"; $sql = mysqli_query($conn, $qry)or die(mysqli_error($conn)); if(mysqli_num_rows($sql) < 1){ return array(); } while($res2 = mysqli_fetch_array($sql)){ $ret2[$res2['id']] = $res2['Event_Sub_Type']; } return $ret2; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <!--Design by Free CSS Templates http://www.freecsstemplates.org Released for free under a Creative Commons Attribution 2.5 License Name : Yosemite Description: A two-column, fixed-width design with dark color scheme. Version : 1.0 Released : 20091106--> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta name="keywords" content="" /> <meta name="description" content="Input form for getting Verse output" /> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>1066 Cards 4U - Verse Input Form</title> <link href="style.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body> <div id="wrapper"> <div id="menu"> <ul> <?php include ("connect_menu_LOCAL.php"); $conn = get_db_conn_Menu(); $menu_items['Url']=""; $menu_sql = "SELECT Url FROM dtop"; $menu_res = mysqli_query($conn, $menu_sql) or die(mysqli_error($conn)); if (mysqli_num_rows($menu_res) === false) { echo "<p>".mysqli_error($menu_res)."</p>"; } else { while($menu_items = mysqli_fetch_array($menu_res)){ $item=$menu_items['Url']; echo $item; } } //free results mysqli_free_result($menu_res); //close connection to MySQL mysqli_close($conn); ?> </ul> </div><!-- end #menu --> <div id="header"> <div id="logo"> <h1><a href="http://www.1066cards4u.co.uk">1066 Cards 4U</a></h1> </div><!-- end #wrapper --> </div><!-- end #header --> <div id="page"> <div id="page-bgtop"> <div id="page-bgbtm"> <div id="content"> <h1>Verse Choices Form</h1> <p> <br></br> <br></br> You can filter the database, by selecting one of the items in each drop down menu and clicking the submit button.<br></br> This will list all greetings of the chosen type of Event and Mood.<br></br> If you do not make a choice the default selections will be used.</p> <br></br> <h3>BASIC VERSION</h3> <br></br> <!-- Start of FORM --> <form action="VerseQuery.php" method="post"> <?php echo buildSelectOptions('event', getEvents($conn), 1); echo buildSelectOptions('mood', getMoods($conn), 27); ?> <input type="submit" value="submit"/> </form> </form><!-- End of FORM --> <br></br> <h3>ADVANCED VERSION</h3> <p>If you wish to change the Font color to any color, use the following button</p> <br></br> <!-- Start of FORM --> <form action="AltVerseQuery1.php" method="post"> <?php echo buildSelectOptions('event', getEvents($conn),1); echo buildSelectOptions('mood', getMoods($conn),27); ?> <input type="submit" value="submit"/> </form><!-- End of FORM --> <br></br><br></br> <form method="post" action="Verse_Menu.php"> <input type="submit" value="Return To Verse Menu"/> </form> </div><!-- end #content --> <div id="sidebar"> <div id="search" > <form method="get" action="http://1066cards4u.co.uk"> <div> <input type="text" name="s" id="search-text" value="" /> <input type="submit" id="search-submit" value="GO" /> </div> </form> </div> <div style="clear: both;"> </div> <h2>Useful Links</h2> <ul.a> <li><p><a href="Articles/Instructions for Using Verse Database-V2.12.pdf" target="_blank">Insructions for using Verse Printing UtilityPrintable PDF Version</a></p></li> <li><p><a href="Articles/Nominal Settings.PDF" target="_blank">Nominal Settings and Cutting List for Verse Database PDF Version</a></p></li> <li><p><a href="Articles/How to use the Color Chooser_rasterized.PDF" target="_blank">How to use the Color Picker</a></p></li> </ul.a> </div><!-- end #sidebar --> <div style="clear: both;"> </div> </div><!-- end #page-bgtop --> </div><!-- end #page-bgbtm --> </div><!-- end #page --> </div> <div id="footer"> <p>Copyright (c) 2008 Sitename.com. All rights reserved. Design by <a href="http://www.freecsstemplates.org/" rel="nofollow">FreeCSSTemplates.org</a>.</p> </div><!-- end #footer --> </body> </html> This problem is driving me crazy!! I hope you can spot something amiss!
  17. Hi The included connection file is on post #17 The main code is as post #24, with the exception that the echo buildselectoption lines have been up date to the last suggestion.
  18. No! This is the form used to select the event and the mood. I have been trying to eliminate the present situation on my website where the dropdown menus default to a blank line i.e. no selection option shown. However I can't test this code until I resolve the error I am now getting in the function(see previous post. Can you spot what is causing the error?
  19. I have been delayed in replying as I have been having problems with my localhost. Before I get onto your suggestion Barand, I have a problem running the code on the localhost. When I run this I get a Warning: Warning: mysqli_query(): Couldn't fetch mysqli in... The error is in line 22 and 114. But this line of code is working in other scripts and it can't be the Included code also for the same reason? The stack calls line 114 first, so the only common variable is the $conn! So why is $conn causing the error? So the only conclusion I can make that it is to do with the function code, but I can't see where! Incidently, I have also tried this script (see post#24) on the remote server and it stops at the same point, but I can't see the warnings as they are suppressed. Now regarding your suggestion Barand, once I can get passed the above error, I intend to try your suggestion. Looking back at the previous posts, I see it was Maxxd that suggested the inclusion of the $_POST parameter and on reflection I don't understand why, as no variables are posted from a previous script. Any more help would be appreciated!
  20. Right! I get the list now, with <--- Please Select--->, but my original question was how can I set the selected value to the one of my choosing. I want the Events showing id = 1, but the Mood id = 27. I thought that the last parameter in the function was going to do that? So as Barand said the function only has 3 arguments and I am passing 4. I assume that a new argument is needed, but what?
  21. As I said last evening, I am now sure that the Event And Mood function is not returning any data. How can I check the array, as print_r(ret1) did not print anything apart from Array? Here is the code so far: <?php include ("connect_Verses4Cards_LOCAL.php"); $conn = get_db_conn_verse(); //Function to build select options based on passed array function buildSelectOptions($name, array $options, $current=null){ $htmlString = "<select name='{$name}' id='{$name}'>\n"; $htmlString .= "\t<option value='-1'> -- Please select -- </option>\n"; foreach($options as $value=>$option){ $htmlString .= "\t<option value='{$value}'"; if($value == $current){ $htmlString .= " selected"; } $htmlString .= ">{$option}</option>\n"; } $htmlString .= "</select>\n"; return $htmlString; } function getEvents($conn){ $qry = "SELECT id ,Event_Type FROM Events ORDER BY id"; $sql = mysqli_query($conn, $qry)or die(mysqli_error($conn)); if(mysqli_num_rows($sql) < 1){ return array(); } while($res1 = mysqli_fetch_array($sql)){ $ret1[$res1['id']] = $res1['Event_Type']; } return $ret1; } function getMoods($conn){ $qry = "SELECT id ,Event_Sub_Type FROM Event_Sub ORDER BY id"; $sql = mysqli_query($conn, $qry)or die(mysqli_error($conn)); if(mysqli_num_rows($sql) < 1){ return array(); } while($res2 = mysqli_fetch_array($sql)){ $ret2[$res2['id']] = $res2['Event_Sub_Type']; } return $ret2; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <!--Design by Free CSS Templates http://www.freecsstemplates.org Released for free under a Creative Commons Attribution 2.5 License Name : Yosemite Description: A two-column, fixed-width design with dark color scheme. Version : 1.0 Released : 20091106--> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta name="keywords" content="" /> <meta name="description" content="Input form for getting Verse output" /> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>1066 Cards 4U - Verse Input Form</title> <link href="style.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body> <div id="wrapper"> <div id="menu"> <ul> <!-- --> </ul> </div><!-- end #menu --> <div id="header"> <div id="logo"> <h1><a href="http://www.1066cards4u.co.uk">1066 Cards 4U</a></h1> </div><!-- end #wrapper --> </div><!-- end #header --> <div id="page"> <div id="page-bgtop"> <div id="page-bgbtm"> <div id="content"> <h1>Verse Choices Form</h1> <p> <br></br> <br></br> You can filter the database, by selecting one of the items in each drop down menu and clicking the submit button.<br></br> This will list all greetings of the chosen type of Event and Mood.<br></br> If you do not make a choice the default selections will be used.</p> <br></br> <h3>BASIC VERSION</h3> <br></br> <!-- Start of FORM --> <form action="VerseQuery.php" method="post"> <select name="Event_Type"> <option value= "<?php echo buildSelectOptions('event', getEvents($conn), $_GET['event'],1);?>" </option> </select> <select name="Mood"> <option value= "<?php echo buildSelectOptions('mood', getMoods($conn), $_GET['mood'], 27);?>" </option> </select> <input type="submit" value="submit"/> </form><!-- End of FORM --> <br></br> <h3>ADVANCED VERSION</h3> <p>If you wish to change the Font color to any color, use the following button</p> <br></br> <!-- Start of FORM --> <form action="AltVerseQuery1.php" method="post"> <select name="Event_Type"> <option value= "<?php echo buildSelectOptions('event', getEvents($conn), $_GET['event']);?>" </option> </select> <select name="Mood"> <option value= "<?php echo buildSelectOptions('mood', getMoods($conn), $_GET['mood']);?>" </option> </select> <input type="submit" value="submit"/> </form><!-- End of FORM --> <br></br><br></br> <form method="post" action="Verse_Menu.php"> <input type="submit" value="Return To Verse Menu"/> </form> </div><!-- end #content --> <div id="sidebar"> <div id="search" > <form method="get" action="http://1066cards4u.co.uk"> <div> <input type="text" name="s" id="search-text" value="" /> <input type="submit" id="search-submit" value="GO" /> </div> </form> </div> <div style="clear: both;"> </div> <h2>Useful Links</h2> <ul.a> <li><p><a href="Articles/Instructions for Using Verse Database-V2.12.pdf" target="_blank">Insructions for using Verse Printing UtilityPrintable PDF Version</a></p></li> <li><p><a href="Articles/Nominal Settings.PDF" target="_blank">Nominal Settings and Cutting List for Verse Database PDF Version</a></p></li> <li><p><a href="Articles/How to use the Color Chooser_rasterized.PDF" target="_blank">How to use the Color Picker</a></p></li> </ul.a> </div><!-- end #sidebar --> <div style="clear: both;"> </div> </div><!-- end #page-bgtop --> </div><!-- end #page-bgbtm --> </div><!-- end #page --> </div> <div id="footer"> <p>Copyright (c) 2008 Sitename.com. All rights reserved. Design by <a href="http://www.freecsstemplates.org/" rel="nofollow">FreeCSSTemplates.org</a>.</p> </div><!-- end #footer --> </body> </html> Your help is appreciated!
  22. I believe that the Event And Mood function is not returning any data. I tried to see if any data was being generated with print_r() but just printed Array when I put it just before the return ret. I have shut down for the evening and will answer in full tomorrow.
  23. Right getting closer! Now runs without errors, but the lists are empty? Can you explain where the 'events' and 'mood' come from in the following: echo buildSelectOptions('event', getEvents($conn), $_GET['event']); and echo buildSelectOptions('mood', getMoods($conn), $_GET['mood']); I can see in the actual function they are in place of the local variable $name. I have tested the MYSQL SELECT query and that works OK, so why is the list empty?
  24. But the change you suggested in #9 was in the final buildselectoption line? The $conn is the MySqli connection string to run the MySQL query. Is that telling me that this string is empty? That would imply that the connection function was not working. Any other ideas?
  25. I have tried checking this code on my localhost and I am getting an error that I can't figure out why it is giving this error! Here is the code: <?php include ("connect_Verses4Cards_LOCAL.php"); $conn = get_db_conn_verse(); //Function to build select options based on passed array function buildSelectOptions($name, array $options, $current=null){ $htmlString = "<select name='{$name}' id='{$name}'>\n"; $htmlString .= "\t<option value='-1'> -- Please select -- </option>\n"; foreach($options as $value=>$option){ $htmlString .= "\t<option value='{$value}'"; if($value == $current){ $htmlString .= " selected"; } $htmlString .= ">{$option}</option>\n"; } $htmlString .= "</select>\n"; return $htmlString; } function getEvents(){ $qry = "SELECT id ,Event_Type FROM Events ORDER BY id"; $sql = mysqli_query($conn, $qry)or die(mysqli_error($conn)); if(mysqli_num_rows($sql) < 1){ return array(); } while($res1 = mysqli_fetch_array($sql)){ $ret1[$res1['id']] = $res1['Event_Type']; } return $ret1; } function getMoods(){ $qry = "SELECT id ,Event_Sub_Type FROM Event_Sub ORDER BY id"; $sql = mysqli_query($conn, $qry)or die(mysqli_error($conn)); if(mysqli_num_rows($sql) < 1){ return array(); } while($res2 = mysqli_fetch_array($sql)){ $ret2[$res2['id']] = $res2['Event_Sub_Type']; } return $ret2; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <!--Design by Free CSS Templates http://www.freecsstemplates.org Released for free under a Creative Commons Attribution 2.5 License Name : Yosemite Description: A two-column, fixed-width design with dark color scheme. Version : 1.0 Released : 20091106--> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta name="keywords" content="" /> <meta name="description" content="Input form for getting Verse output" /> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>1066 Cards 4U - Verse Input Form</title> <link href="style.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body> <div id="wrapper"> <div id="menu"> <ul> <!-- --> </ul> </div><!-- end #menu --> <div id="header"> <div id="logo"> <h1><a href="http://www.1066cards4u.co.uk">1066 Cards 4U</a></h1> </div><!-- end #wrapper --> </div><!-- end #header --> <div id="page"> <div id="page-bgtop"> <div id="page-bgbtm"> <div id="content"> <h1>Verse Choices Form</h1> <p> <br></br> <br></br> You can filter the database, by selecting one of the items in each drop down menu and clicking the submit button.<br></br> This will list all greetings of the chosen type of Event and Mood.<br></br> If you do not make a choice the default selections will be used.</p> <br></br> <h3>BASIC VERSION</h3> <br></br> <!-- Start of FORM --> <form action="VerseQuery.php" method="post"> <select name="Event_Type"> <option value= "<?php echo buildSelectOptions('Event_Type', getEvents(), $_GET['Event_Type']);?>" </option> </select> <select name="Mood"> <option value= "<?php echo buildSelectOptions('Event_Sub_Type', getMoods(), $_GET['Event_Sub_Type']);?>" </option> </select> <input type="submit" value="submit"/> </form><!-- End of FORM --> <br></br> <h3>ADVANCED VERSION</h3> <p>If you wish to change the Font color to any color, use the following button</p> <br></br> <!-- Start of FORM --> <form action="AltVerseQuery1.php" method="post"> <select name="Event_Type"> <option value= "<?php echo buildSelectOptions('event', getEvents(), $_GET['event']);?>" </option> </select> <select name="Mood"> <option value= "<?php echo buildSelectOptions('mood', getMoods(), $_GET['mood']);?>" </option> </select> <input type="submit" value="submit"/> </form><!-- End of FORM --> <br></br><br></br> <form method="post" action="Verse_Menu.php"> <input type="submit" value="Return To Verse Menu"/> </form> </div><!-- end #content --> <div id="sidebar"> <div id="search" > <form method="get" action="http://1066cards4u.co.uk"> <div> <input type="text" name="s" id="search-text" value="" /> <input type="submit" id="search-submit" value="GO" /> </div> </form> </div> <div style="clear: both;"> </div> <h2>Useful Links</h2> <ul.a> <li><p><a href="Articles/Instructions for Using Verse Database-V2.12.pdf" target="_blank">Insructions for using Verse Printing UtilityPrintable PDF Version</a></p></li> <li><p><a href="Articles/Nominal Settings.PDF" target="_blank">Nominal Settings and Cutting List for Verse Database PDF Version</a></p></li> <li><p><a href="Articles/How to use the Color Chooser_rasterized.PDF" target="_blank">How to use the Color Picker</a></p></li> </ul.a> </div><!-- end #sidebar --> <div style="clear: both;"> </div> </div><!-- end #page-bgtop --> </div><!-- end #page-bgbtm --> </div><!-- end #page --> </div> <div id="footer"> <p>Copyright (c) 2008 Sitename.com. All rights reserved. Design by <a href="http://www.freecsstemplates.org/" rel="nofollow">FreeCSSTemplates.org</a>.</p> </div><!-- end #footer --> </body> </html> I am getting ' Warning! mysqli_query() expects paramenter 1 to be mysqli, null given in.....' I have used this method many times before with no problem, in fact the page I am trying to chage worked fine before I altered it with the suggested code. The variable $conn seems to be the problem, but this is returned in the included file. Here is the connection file: <?php //set up a couple of functions for use by Verses function get_db_conn_verse() { $host_name = "localhost"; $database = "db395629647"; // Change your database nae $username = "root"; // Your database user id $password = "xxxxx"; // Your password //connect to server and select database; you may need it $conn = new mysqli($host_name, $username, $password, $database); //if connection fails, stop script execution if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } return $conn; } ?> I can't spot any errors, so why am I getting this 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.