Jump to content

BuckeyeTheDog

New Members
  • Posts

    9
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

BuckeyeTheDog's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks, PFM and Kicken. I have found the problem. I have attached the updated code below (still going to clean it up). Still learning PHP. Best I can tell, the usage of the {$subject["id"]} occurred outside of my while statement, and therefore somehow it was not acknowledging the this var/array. When I ran the var_dump outside this while {} statement, I got NULL and some other things like it. When I moved it back in the while statement, I got the results i expected and got the var_dump to dump lots. I'm not sure I understand why this is the case. And why things are lost outside that while statement. If you could explain that to me- it would be helpful. Thanks, and here is my working code (just not totally cleaned up)... <?php require_once ('includes/conf.php'); ?> <?php include ('includes/header.php'); ?> <?php require_once ('includes/functions.php'); ?> <table id="stucture"> <tr> <td id="navigation"> <ul class="subjects"> <?php $subject_set = get_all_subjects(); while ($subject = mysql_fetch_array($subject_set)) { echo "<li>{$subject['menu_name']}</li>"; $query2 = "SELECT * FROM pages WHERE subject_id = {$subject["id"]}"; $page_set = mysql_query($query2); if (!$page_set) { die ("Database query failed: " . mysql_error()."<br>Query was: ".$page_set);} echo "<ul class='pages'>"; while ($page = mysql_fetch_array($page_set)) { echo "<li>{$page['menu_name']}</li>"; } echo "</ul>"; } ?> </ul> </td> <td id="page"><h2>Content Area</h2> </td> </tr> </table> <?php require ('includes/footer.php'); ?>
  2. I apologize if this is in the wrong category. I'm not sure if this is a MySQL statement problem or a php variable problem..
  3. Hello all, I am using the Lynda.com PHP course to further learn php. On one of the examples, they are using a SQL Query that works for them but is erroring out for me. It is the query below for the $page_set variable, particularly the use of the WHERE subject_id = {$subject["id"]}". <?php require_once ('includes/conf.php'); ?> <?php include ('includes/header.php'); ?> <?php require_once ('includes/functions.php'); ?> <table id="stucture"> <tr> <td id="navigation"> <ul class="subjects"> <?php $subject_set = mysql_query("SELECT * FROM subjects", $connection); if (!$subject_set) { die ("Database query failed: " . mysql_error()); } while ($subject = mysql_fetch_array($subject_set)) { echo "<li>{$subject["menu_name"]}</li>"; } $page_set = mysql_query("SELECT * FROM pages WHERE subject_id = {$subject["id"]}"); // This appears to be the problem area, unless it is fooling me. It works with this exact statement in their code. if (!$page_set) { die ("Database query failed: " . mysql_error()); } echo "<ul class='pages'>"; while ($page = mysql_fetch_array($page_set)) { echo "<li>{$page['menu_name']}</li>"; } echo "</ul>"; ?> </ul> </td> <td id="page"><h2>Content Area</h2> </td> </tr> </table> <?php require ('includes/footer.php'); ?> The error listed is this: Database query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 Thanks, you all are the best! BtD
  4. Are you actually trying to create the schedule, or display the schedule that has been created?
  5. Thanks, tjmbc. Your answer worked fine- as a matter of fact, it pointed out that I had a deeper path issue that was the culprit... It's now fixed and good to go...
  6. Hello all, 1) Can I set a subdirectory path for an includes file?? As in, when my main php file is on the root can I "include" my server login file from a subdirectory? If so, currently I'm not having luck doing it... Here's a sample... include("/public_html/phptest/AbConnect.php"); in which public_html is my ftp webserver directly, phptest is a subfolder and AbConnect.php is the file with the login info. If I can do this, how do I do it? Or do I need the included file in the same directory? 2) When/if I have PHP and HTML files in a subdirectory and you want to have an "includes" file, do you just place it in that same subdirectory, or can you/ how would you reference a different subdirectory- or go up the path to the root??? Thanks for your help...
  7. Newbie here. Thanks for all your help! I seem to be struggling with setting up accounts and passwords using PHPMyAdmin (on MacOSX and Xampp). Using PHP, I can access my localroot when using the default "root" and no password. I have set up extra MySQL databases and seem to be able to access them with my root account and no password. But when I set up a new user and a password, I can't seem to make things work. I'm quite frustrated. I'm back to the most basic PHP code. As stated above, this code seems to work except when I try my account name and password... $cxn = mysqli_connect("localhost","flange1","xxx","buckeye") or die ("Couldn't connect to server."); I get this error code back... Warning: mysqli_connect() [function.mysqli-connect]: (28000/1045): Access denied for user 'flange1'@'localhost' (using password: YES) in /Applications/xampp/xamppfiles/htdocs/db_login 2.php on line 11 Couldn't connect to server. I'm guessing I am just not setting the account up in PHPMyAdmin correctly. Is there anything tricky about this? I have attached a jpg of that admin screen. Thanks! I'm going crazy here... [attachment deleted by admin]
  8. Thanks for the help. My wife also pointed out the I was missing the "i" in the "mysqli_num_rows". We fixed that and it is working fine... You guys were great with such quick responses....
  9. Hello all. I'm a newbie to php. Just installed XAMPP on a Mac and I'm using "PHP and MySQL for Dummies"- sorry. Everything is installed and running fine, but my I can't get my first exercise in accessing MySQL to work... Here is the warning I'm receiving... Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /Applications/xampp/xamppfiles/htdocs/NoDamnWay.php on line 21 And here is my PHP... (I've called out the offending Line 21 below...) <?php echo "<html> <head><title>Test My SQL- It'll be a miracle if this works </title></head> <body>"; $host="localhost"; $user="root"; $password=""; $cxn = mysqli_connect ($host,$user,$password); $sql= "SHOW STATUS"; $result = mysqli_query($cxn,$sql); if($result == false) { echo "<h4>Error: ".mysqli_error($cxn)."</h4>"; } else { echo "<table border='1'> <tr><th>Variable_name</th> <th>Value</th></tr>"; /*LINE 21*/ for($i = 0; $i < mysql_num_rows($result); $i++) { echo "<tr>"; $row_array = mysqli_fetch_row($result); for($j = 0;$j < mysqli_num_fields($result);$j++) { echo "<td>".$row_array[$j]."</td>\n"; } } echo "</table>"; } ?> </body></html> Thanks for helping a newbie!!!
×
×
  • 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.