Jump to content

Skorpio

Members
  • Posts

    52
  • Joined

  • Last visited

Skorpio's Achievements

Member

Member (2/5)

0

Reputation

  1. I hadn't thought of any alternatives other than return and echo the function which I have now, function navmenu($db){ $data = $db->query("SELECT * FROM menu")->fetchAll(PDO::FETCH_ASSOC); foreach ($data as $row) { return "<li><a href='{$row['url']}' title='{$row['title']}'><i class='{$row['icon']}'></i> {$row['header']}</a></li>"; } } then // Navigation Menu Function echo navmenu($db);
  2. Thanks, when I put in the additional $row information I again added too many quotes. This has solved the issue which has resulted in the following code foreach ($data as $row) { echo "<li><a href='{$row['url']}' title='{$row['title']}'><i class='{$row['icon']}'></i> {$row['header']}</a></li>"; } If I use the quotes around the {$row['header']} -> '{$row['header']}' they print out on screen. Removing the 2 single quotes has solved the issue and when I view source I get the following <li><a href='?page=home' title='Home Page'><i class='fas fa-home site-nav--icon'></i> Home</a></li>
  3. Thanks for this however as I say I want to put the whole navigation code block into a function so the closing a and li would be an issue. From trying the code I get
  4. Thanks for this. It gives me part of the solution however I get the echo and quotes printed on screen. When I look at the colour coding in brackets the closing single quote, square bracket and closing brace are highlighted in red
  5. I have a navigation list displaying which is a mix of html and php, everything is working fine however now I want to convert this block of code into a function but am having major problems with quotes. The line of code I currently have is $data = $db->query("SELECT * FROM menu")->fetchAll(PDO::FETCH_ASSOC); foreach ($data as $row) { ?> <li><a href="<?php echo $row['url']; ?>" title="<?php echo $row['title']; ?>"><?php echo $row['icon'] . ' ' . $row['header']; ?></a></li> <?php } ?> As I say everything works using the above but now I am trying to echo the full li out and am having major issues with single and double quotes. I currently have echo "<li><a href='#' title='the title'><i class='fas fa-user site-nav--icon'></i> Help</a></li>"; Now I am trying to use the $row['url'], $row['title'], $row['icon'] & $row['header'] as per the top example but I cannot get the combination of quote marks correct, whether to use double, single or a combination. I would be grateful if someone could suggest the correct syntax for the a tag then I can work through the rest. Thanks
  6. I am trying to resolve the initial problem, getting nowhere fast. so it should read $ As the variable is storing all data records? So Should read foreach ($row as $rows){ Is that what you are meaning requinix? The foreach that I am using in the 2nd example works as far as the navigation however I cannot include the content for the page within the foreach which makes the join redundant. I am unsure what the solution is to this but I feel as though I am going round in circles. The above, my first code with the foreach loop would present me with the same issue of not being able to sync the page contact with the navigation.
  7. Although still looking to resolve the issue with my php above I am looking at other solutions. Although the followi8ng code populates my navigation menu correctly I am unable to get the page data to sync with the appropriate navigation choice. $sql= "SELECT * FROM menu LEFT JOIN pages ON menu.id = pages.page_id"; $stmt = $db->query($sql); $row = $stmt->fetchAll(PDO::FETCH_ASSOC); // To print array out echo "<pre>"; print_r($row); echo "</pre>"; Then where the navigation is I have <?php foreach($db->query($sql) as $row){ ?> <a href="<?php echo $row['url']; ?>"><i class="<?php echo $row['icon']; ?>"></i>&nbsp;<?php echo $row['header']; ?></a> <?php } ?> As I say the nav menu is returned correctly but I am unable to sync with the corresponding page from the pages table, the join SQL statement above returns the full array from both tables synced but the issue I am having is the closing brace. I am unable to place it further down the page to enable all the relevant areas of the page to echo the relevant data from the pages table. As per screenshot2 attached it is the placement of the closing brace preventing me from having the corresponding navigation selection and corresponding page showing as the data areas for the pges table are outside of the foreach .
  8. What is? As I say the SQL is working, it is the PHP thats the issue.
  9. Hi I have a 4 button navigation, home, projects, about and contact. This is in one table, menu, this table has the relevant icon to display with the appropriate link and another field is the link itself, ?page=home. Menu is joined with the pages table using the following query SELECT * FROM menu LEFT JOIN pages ON menu.id = pages.page_id When I run this through phpmyadmin sql console everything is returned as expected, all pages match up with the navigation. When I print_r($row); all 4 fields from the nav table and all 7 fields from the pages table, totalling 11 fields, display as per the query running in phpmyadmin which was as expected however, on the actual page it isn't going as hoped and expected. I have /* query for page data(navigation & title) */ $sql= "SELECT * FROM menu LEFT JOIN pages ON menu.id = pages.page_id"; $stmt = $db->query($sql); $row = $stmt->fetchAll(PDO::FETCH_ASSOC); /* to go in php tags where table data required - <?php echo $row['header']; ?> */ // Sidenote, I realise prepare rather than query but need to get this working first echo "<pre>"; print_r($row); echo "</pre>"; // Everything, all records from both tables, showing up as expected in array If I use $row = $stmt->fetch(PDO::FETCH_ASSOC); As expected I only get 1 record returned, all nav buttons are home which is the 1 record with all page data from the pages table and all icons from the menu table are the home icon, again as expected since it is the 1 record. When I use fetchAll everything is returned undefined index, e.g. Undefined index: content3 in C:\xampp\htdocs\test\index.php on line 70 The php used for the navigation is <?php echo $row['url']; ?> <?php echo $row['icon']; ?> <?php echo $row['header']; ?> the full link is <a href="<?php echo $row['url']; ?>"><i class="<?php echo $row['icon']; ?>"></i>&nbsp;<?php echo $row['header']; ?></a> The above is listed 4 times for Home, Projects, About and contact. As I know the SQL is working I realise I have made an error in the PHP but cannot work out what. As far as I can see I should be using fetch, rather than fetchAll, so as to only return 1 record as requested via the navigation links however fetchAll would give me the data required for the navigation to be labelled correctly. I cannot work out where I am going wrong. Any help would be appreciated.
  10. Regarding I can run up to version 7 on the live server through cpanel however the host only supports up to 5.4 which obviously raises issues such as not renewing with them unless they update to at least 5.5 but that's another issue. The levels for access is something I was thinking about for the future but I need to get my head around PDO and Php in general without being overly ambitious but you have given me a lot to think about. Thanks for the suggestions and the help.
  11. I think I have found the reason for the 500 error if nothing else, my host only supports up to php 5.4 so the verify and hash are not supported but that's another issue. but the above code is running but I am still testing the is_valid you suggested.
  12. These are the current checks I have, everything running on xampp but when testing on live server throws a 500 after submission, does not show errors. So I have this, if($pdo){ $stmt = $pdo->prepare("select username, password, active from users where username = :username"); $stmt->bindValue(":username", $username); $stmt->execute(); $user = $stmt->fetch(PDO::FETCH_ASSOC); if($user === false){ $msg = ''; $error .= 'Incorrect Username/Password combination'; } else { $validPassword = password_verify($unhashed, $user['password']); if($validPassword){ if($user['active'] == 1){ if($total == $getCaptchaResults){ $msg = ''; $error .= 'Everything working so far'; // any more ifs - when live response from $_POST[] is HTTP ERROR 500 } else { $msg = ''; $error .= 'Captcha incorrect!'; } } else { $msg = ''; $error .= 'You cannot log in until you click the link in the registration email we sent you.'; }//active } else { $msg = ''; $error .= 'Incorrect Username/Password combination'; } } } } I will look at is_valid and see what happens. Thanks
  13. Starting with your last point, I have removed count and am checking I was planning on the function but wanted to get the code working here first. As the prepared statement is only checking for the username it is returning true even if the password does not match. As I said in my original post I am just going round in circles. If I place the above code in a function function check_credentials ($pdo, $username, $unhashed){ $stmt = $pdo->prepare("select username, password, active from users where username = :username"); $stmt->bindValue(":username", $username); $stmt->execute(); $results = $stmt->fetch(PDO::FETCH_ASSOC); if($results == 1 && password_verify($unhashed, $results['password'])){ $msg = ''; $error .= 'OK'; } else { $msg = ''; $error .= 'No entry'; var_dump($results); } return false; } That will still return a result if the username is entered correctly though, won't it?
×
×
  • 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.