Jump to content
Larry Ullman's Book Forums

Nick20

Members
  • Posts

    16
  • Joined

  • Last visited

Nick20's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. Hey people! I've just come across something when using Larry's config script in PHP Advanced. Now I have the error handler running, it flags up all these undefined variable errors wherever I have this type of thing: $content = $_GET['var'] is says that $_GET['var'] isn't defined. I can get round it like this: if(isset($_GET['z_'])){ $content = $_GET['z_']; } else { $content = FALSE; } But seems like a really long way around it do to every time I want to rename a GET variable. I have tried sticking it all in a function, but of course, when I pass the GET function into the function, I get the same error. I also seem to need an ELSE, otherwise, I get undefined errors on $content. Is there a better way round this?? CHeers, Nick
  2. Hi, is it secure to pass a database connection into a function in an external file using a global variable. For example: function get_all_products(){ global $dbc; //where $dbc is database connection $q = 'SELECT * FROM product WHERE active="yes" ORDER BY CatId'; $r = MYSQLI_QUERY ($dbc, $q); $data = array(); (etc) or is there a better/safer way? Thanks very much Nick
  3. Thanks for the reply Craig, I'm pretty sure that shouldn't matter... I believe the @ just suppresses error messages which is I think why I left it off to see it it would help get to the bottom of things!
  4. Hiya, Does anyone have any idea why this works fine: $heading = 1; $q = "SELECT * FROM btc_links WHERE heading = $heading";$r = @mysqli_query($dbc, $q);echo '<br/><p><ul>';while ($row = mysqli_fetch_array($r, MYSQLI_NUM)){echo '<li><a href="'.$row[2].'" target="blank">'.$row[3].'</a></li>';}echo '</ul></p><br/>'; YET... When I try to implement the same code with a function, I get no returns: function get_link($heading){ $q = "SELECT * FROM btc_links WHERE heading = $heading";$r = mysqli_query($dbc, $q);echo '<br/><p><ul>';while ($row = mysqli_fetch_array($r, MYSQLI_NUM)){ echo '<li><a href="'.$row[2].'" target="blank">'.$row[3].'</a></li>';}echo '</ul></p><br/>'; }// end of function $heading = 1; get_link($heading); Hope someone can help, I've been trying to get it to work now for 3 hours!! grr!!! p.s. very excited to be getting Larry's advanced php book through the post tomorrow!! Nick
  5. I don't think I am, but I'm pretty new to this, so just making it up as I go along! The database is really simple - this query just references a bunch of dates of meetings over multiple years. To set up a method of selecting a meeting date, I wanted two dropdown menu levels, the first to select the years of the meetings which is in the first query, $q2, $r2 & $f - this generated the array to list a dropdown from the first year of meetings to whatever the current year is. The second level of dropdown was to list all the meetings in each of those years, so I had to reference the row of the first array (the selected year - which I was having the trouble with) and pull out of the database all the meeting dates that occurred in that year. I'm guessing that there is a simpler way of doing this! Probably with java/ajax or something!
  6. YAYYYY!!!! it's working!! Thanks guys, you've really made my day! The answer was similar to what Antonio suggested but with = rather than >: my original: $q3 = 'SELECT meeting_date FROM btc_meetings WHERE YEAR(meeting_date) = '$year'; working line: $q3 = 'SELECT meeting_date FROM btc_meetings WHERE ( '.$year.' = YEAR(meeting_date) ) ORDER BY meeting_date ASC'; I think it was just a syntax error in specifying the $year string. Now I get: 2002 [ *]2002-01-01 2002-01-01 2002-01-01 2002-01-01 2002-01-01 [*]2003 [*]2004 [*]2005 [*]2006 [*]2007 [*]2008 2008-02-02 (crazy data, but matches the db). Thanks tons again!
  7. Hi HartleySan, Thanks for your reply. I forgot to post that when I run the query with the line "... = $year", or also I just checked with what you suggested <=... I get this: Select meeting date: 2002 2003 2004 2005 2006 2007 - no second level and only the first level of the menu comes up. It doesn't seem to recognise the variable $year as the year from the previous level. When I change the value $year to a constant value for the year, the query works, but of course only brings up that constant year for the second level of the menu.
  8. Hi guys, I hope someone can help! I've been experimenting with some concepts from Larry's book and wanted to create a multilevel dropdown nav style menu which is populated with information gathered from the db. Basically gonna be two columns for selecting minutes of meeting dates. the first column will have all the years from the starting year of meetings up to the current year. THEN (and this is the bit I'm stuck on), the second level will come off each year and show all the meeting dates that occurred in that year. So far I'm pretty much there, all of my queries work in mySQL except for specifying one string in particular, which is the string that specifies which year to use in menu level two. the code I have so far is: $q2 = "SELECT YEAR(CURDATE())"; // select current year $r2 = @mysqli_query ($dbc, $q2); $f = mysqli_fetch_row($r2); echo '<p>Select meeting date:</p>'; echo "<ul>"; for ($year = 2002; $year <= $f[0]; $year++) { echo "<li><a href=\"#\">$year</a><ul>"; $q3 = 'SELECT meeting_date FROM btc_meetings WHERE YEAR(meeting_date) = $year'; $r3 = @mysqli_query ($dbc, $q3); while ($row = mysqli_fetch_array($r3, MYSQLI_NUM)) {echo "<li><a href=\"#\">$row[0]</a></li>";} echo "</li></ul></p>"; } NOW... if I run this script with "2002" in place of $year, i get this: Select meeting date: 2002 2002-01-01 2002-01-01 2002-05-01 2002-05-01 2002-03-01 2003 2002-01-01 2002-01-01 2002-05-01 2002-05-01 2002-03-01 2002-03-01 2002-12-01 2002-04-01 Which seems promising... however, I need to know how to specify that string so that under 2002, all the 2002 dates come up... under 2003, all the 2003 dates come up etc. I hope that makes sense!! Hope someone can help! Cheers, Nick
  9. Thanks again Jonathon, I did as you said - also checking the source code produced by the browser - as I did, I noticed an '=' missing from the email value field, which explained that. Also on the 50th time of inspecting the script I noticed I'd put: if (isset($POST['submitted'])) { rather than if (isset($_POST['submitted'])) { Works fine now! Newb error! Anyway, I really appreciate your timely and helpful responses - enjoy the rest of the day!!
  10. I still get the same problems happening though: 1) I enter all the details correctly and click submit: the form resets recalling (sticky style) only first and last name. No info is entered into the database (on checking thru terminal) and no congratulations msg is displayed 2) I intentionally miss some of the registration fields to test the error reporting: the form resets recalling (sticky style) only first and last name. No user (or debugging) error msg is displayed
  11. Many thanks for your help, Jonathon, I really appreciate it! Well spotted on the q vs g typo! I missed that one! I ran the query in terminal and it ran fine. Query ok 1 row affected. I think the problem must be with the form part of the script, but I still can't see what!
  12. Ah... I see! I just used that script independently, however, just to see if I was able to connect to the db - I'm not running that script in conjunction with the Register script. My connect to db script is: <title>mysqli_connect</title> <?php # mysqli_connect.php // This file contains the database access information // This file also establishes a connection to MySql and selects the database //Set the database access information as constants: DEFINE ('DB_USER', 'root'); DEFINE ('DB_PASSWORD', 'root'); DEFINE ('DB_HOST', 'localhost'); DEFINE ('DB_NAME', 'sitename'); // Make the connection: $dbc = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die ('Could not connect to MySql: ' .mysqli_connect_error() ); ?> As I say, connection to the database doesn't seem to be a problem, just getting that script to work!
  13. Thanks Jonathon... sorry be being slow, but which part of the code do I need to change? I can only see mysqli's? I was just copying it out the book, but must have missed an 'i' or something!
×
×
  • Create New...