Jump to content


  • Posts

  • Joined

  • Last visited

Steve_Berry's Achievements


Member (2/5)



  1. No. No text is displayed. There should be a message when the page loads. When an option is chosen, and the submit button is clicked, there should be some text, but the page just resets. i have attached an image of what I mean: initial page, options, and then submitted.
  2. Hello, after some search, testing etc. I found something online to help with what I have been trying to do. I displays the options fine, but I still don't get the required data to display. For example, <option value="Page 1">Page 1</option> does not show Page 1 text. I also have an if else statement where the else part does not appear to work - no message. This is the code: <div class="container"> <form name="myForm" method="post" action=""> <div class="select-block"> <select name="Pages"> <option value="" disabled selected>Testin 123</option> <option value="Page 1">Page 1</option> <option value="Page 2">Page 2</option> <option value="Page 3">Page 3</option> <option value="Page 4">Page 3</option> </select> </div> <input type="submit" name="submit" value="Submit"> </form> <?php if(isset($_POST['myForm'])){ if(!empty($_POST['Pages'])) { //Connect to the database $pdo = new PDO("mysql:host=localhost;dbname=timeline", "root", ""); $sql = "SELECT * FROM testdb ORDER BY id"; $stmt = $pdo->prepare($sql); $stmt->execute(); $data = $stmt->fetchAll(); echo $data['pages']; } else { echo 'Please select an option.'; } } ?> </div> Please, could you help with the code. Thanks
  3. I have tried a few things, as a beginner I guessed what I needed to do. The following code is what I have tried - not working obviously. Am I on the right track. If not I would appreciate an example. Thanks. <select onchange="reload(this.form)"> <option>test one</option> <option> <?php foreach ($data as $output) { echo $output['header']; } ?> </option> </select>
  4. I am trying to use a <select> <option> to display text on a web page. The data comes from a database. This is what I am attempting: When an option is selected and submit button clicked them some text will be displayed. At the moment I do have text on the web page, but none of the selected options change this. I have four pieces of text: Page 1, Page 2 etc. At the moment Page 4 text is displayed. I would like each piece of text to be displayed. This is the php: <?php // Connect to the database $pdo = new PDO("mysql:host=localhost;dbname=###", "###", ""); $sql = "SELECT * FROM testdb ORDER BY id"; try { $stmt = $pdo->prepare($sql); $stmt->execute(); $data = $stmt->fetchAll(); } catch(Exception $ex){ echo ($ex -> getMessage()); } ?> This is the html: <form name="###" method="post" action="#"> <p></p> <select onchange="reload(this.form)"> <option>test one</option> <?php foreach ($data as $output) { ?> <option value=''><?php echo $output['header']; ?></option> <?php } ?> </select> <br> <button type="submit" value="submit">Submit</button> </form> <?php echo $output['pages']; ?> I would appreciate help with this. However, from previous attempts at adding data to a page I used isset() and I think $_POST(), possibly together. If these are the things I need to use, then please could you include their usage within any examples you feel would help. Thank you.
  5. Hello. I have a page that displays data from a database based on pagination. All works well if I display all records (19 at the moment), but if I choose to view 8, or 10, or less than 19, I see duplicates of the same data, as well as new data not showing. How can I prevent duplications and have new date viewed without having to view all data? include("headsection.php"); include("nav.php"); if(isset($_GET['page'])) { $page = $_GET['page']; } else { $page = 1; } $num_per_page = 20; $start_from = ($page -1) * 2; $sql = "SELECT * FROM people ORDER BY id ASC LIMIT $start_from, $num_per_page"; $result = $con->query($sql); if( $result->num_rows > 0) { ?> <h1 class="center">List of all Users</h1> <table class="container3"> <tr> <td width="auto">PID</td> <td width="auto">Name</td> <td width="auto">Relationship</td> <td width="auto" class="center" colspan="3">Actions</td> </tr> <form action="" method="POST"> <?php while( $row = $result->fetch_assoc()){ echo "<input type='hidden' value='". $row['id']."' name='id'>"; //added echo "<tr>"; echo "<td class='success'>".$row['pid'] . "</td>"; echo "<td class='success'>".$row['name'] . "</td>"; echo "<td class='success'>".$row['relationship'] . "</td>"; echo "<td><a href='view.php?id=".$row['id']."' class='primary' title='view'>V</a></td>"; echo "<td><a href='edit.php?id=".$row['id']."' class='warning' title='edit'>E</a></td>"; echo "<td><a href='delete.php?id=".$row['id']."' class='danger' title='delete'>D</a></td>"; echo "</tr>"; } ?> </form> </table> <?php $pr_query = "SELECT * FROM people ORDER BY id"; $pr_result = $con->query($pr_query); $total_record = mysqli_num_rows($pr_result); //echo $total_record; $total_page = ceil($total_record/$num_per_page); echo "<h3 class='center'>Number of records in database: " . $total_record . "</h3>"; echo "<p class='center'>"; if ($page > 1 ){ echo "<a class='primary' href='users.php?page=".($page-1)."'>Previous</a>"; } for($i=1; $i<$total_page; $i++) { echo "<a class='primary' href='users.php?page=".$i."'>$i</a>"; } if ($i > $page ){ echo "<a class='primary' href='users.php?page=".($page+1)."'>Next</a>"; } echo "</p>"; ?> <br><br> <?php } else { echo "<br><br>No Record Found"; } ?> <?php include("footsection.php"); ?> As the site is localhosted, i am using mysqli - the site will not be online. Thanks in advance for any help.
  6. Thanks for the response. I apologise as I did not make it clear enough about what I would like to happen. There are no issues with how the form produces data on the page. It may not be dynamic but the links work - data is inserted depending on which button is placed. What I need help with relates to the inserted pages. For example. The button named Lowe Egypt, will show text and images from the database. However, the page will contain information of rulers at the time so Ruler1, Ruler2 etc, will be a link. So, essentially, a link that is itself in a data table, ideally the same one as the page that is displaying the link. I have included a link that better explains what I mean. The Lower Egypt information would be a menu selection, as you know, and you can see the list of rulers I mentioned. Once clicked the information would be shown in the same page as Lower Egypt was - replacing it obviously. My skills or lack of, prevent me from setting up the Lower Egypt page with dynamic links. Is it possible to use <a href="timeline.php?id=( some number ) within the same code as the Lower Egypt text? As a test, I use this: <a href="#">a link to ruler</a>, which displays as a link. How do I: add to the php on the timeline php to have this link working. create a different Select from etc to have this link working. At the moment the text for the links does not exist. I need to know how to Select it first. Ideally I would like to use <a href="timeline.php?id">, but if the link refers to a different page (or needs to) say - rulers.php?id, than that would be fine. i would be grateful, If you can provide help with the code to do any of this.
  7. This is a question about dynamic links. At the moment I have a dynamic page from a table, I'll call it tableA. The links all work fine, so when clicked, information is displayed from the table. The issue will be when I come to create a new table entry. This new pages (or entry), will itself contain a link to other information. Assuming I have the required information in tableA, how do I activate a dynamic link from within a page that itself dynamically produced? I use PDO for the link to the database, and the page that shows the text uses a form, with buttons to allow the user to select a menu item. The php: <?php // Connect to the databaase $PDO = new PDO("mysql:host=****;dbname=****", "****", "****"); // set the PDO error mode to exception $PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // Set up defaults $current_title = ""; $current_page_data = ""; // Check if the user posted the page if($_SERVER['REQUEST_METHOD'] == 'POST') { // Check if user pressed a menu button if(isset($_POST["menu"])) { // User has selected a menu, meaning a page was selected, now load the page $current_title = filter_input(INPUT_POST, "menu"); // Now get current data from the database, if the page was never created, add it to the database $stmt = $PDO->prepare("SELECT * FROM pages WHERE pageheader=?"); $stmt->execute([$current_title]); $row = $stmt->fetch(); if($row) { // Page is in the databaswe already, load the text for it if(isset($row["pagetext"]) AND trim($row["pagetext"])!="") { $current_page_data = $row["pagetext"]; } } else { // Page was never created, add it with blank text $current_page_data = "This page is under contruction!<br><br>Please check back again later!"; } } } ?> The form (partial): <form name="****form" method="post" action="#"> <table id="timeline"> <tr> <td id="contentMenu"> <span class="item"> <div class="dropdown"> <button class="dropdownButton">Pre 3150 BC</button> <div class="dropdownContent"> <button name="menu" type="submit" value="Predynastic Egypt">Predynastic Egypt</button> <button name="menu" name="menu" value="Lower Egypt">Lower Egypt</button> <button name="menu" type="submit" value="Upper Egypt">Upper Egypt</button> <button name="menu" type="submit" value="Upper and Lower Egypt">Upper &amp; Lower Egypt</button> </div> </span> .... </td> </tr> </table> </form> <!-- page content --> <hr> <h1 class="center"><?php echo $current_title; ?></h1> <hr> <?php echo $current_page_data; ?>
  8. Hello, I meant no disrespect when I asked for no criticism of my code, what I meant was no negative remarks. In other forums, my code as been 'incorrect', 'bad', etc, when all I had done was use examples found online that parts of I did or could not use since I had no idea what went wrong or how to fix it. I discovered what I meant my hiding the id - I think it's called clean urls. I do appreciate your help and hope no offence was taken.
  9. Hello. What I have created is a menu with links. The links will display content on the page from a database. I have the links with id displayed, but nothing is displayed when the link is clicks. I have seen isset() and $_GET used but not a form and I don't know how to change the code to allow the display of data using ID. My site is local, and I am using XAMPP. The database connections work. This is my code: // query $query = "SELECT * FROM topmenu ORDER BY id ASC"; $row = $PDO->query($query); .... <table class="topmenu"> <tr> <td> <h1 class="siteName">site title</h1> </td> <?php foreach($row as $data) { ?> <td><a href="index.php?id=<?php echo $data['id']; ?>"> <?php echo $data['menuheader']; ?> </a></td> <?php } ?> </tr> </table> As a beginner, I would appreciate any help, no criticism of my code please! Also, is there a way of hiding the id in the url? Thanks in advance.
  10. After several attempts, I now have data displayed on my index.php page, but the data is from all rows. Luckily I have two rows. The page also has a menu - with two links. What I would like help with is: How to display index.php with just the data for it - i.e. home page data. How to display data if either the ‘home’ or ‘copyright’ links are clicked. I understand you can use $_GET[‘id’], and isset(), but I don’t know how to do that. I include the full html page code: <?php // database connection require_once('admin/databasecon.php'); ?> <!DOCTYPE html> <html> <?php include 'includes/headsection.php'; ?> <body> <?php // displaying data $table = "pages"; // table $sqli = "SELECT * FROM $table ORDER BY id ASC"; $result = $conn->query($sqli); ?> <!-- topMenu --> <table id="topMenu"> <tr> <td><h1 class="siteName">Scarab Beetle</h1></td> <?php if ($result = mysqli_query($conn, $sqli)) { while($row = $result->fetch_assoc()) { echo "<td class='navItem'>" . "<a href=index.php>" . $row["menuheader"] . "</a>" . "</td>"; } } ?> </tr> </table> <!-- topMenu end --> <!-- timeline menu --> Menu goes here <!-- timeline menu end --> <!-- page title --> <?php if ($result = mysqli_query($conn, $sqli)) { while($row = $result->fetch_assoc()) { echo "<h1 class='centered'>" . $row["pageheader"] . "</h1>"; } } ?> <hr> <!-- page content --> <?php if ($result = mysqli_query($conn, $sqli)) { while($row = $result->fetch_assoc()) { echo $row["pagetext"]; } } ?> <hr> <div class="clear"></div> <!-- footer content --> <?php include 'includes/footersection.php'; ?> <!-- footer content end --> </body> </html> Any help to achieve what I want will be appreciated. Thank you.
  11. Thanks everyone. Will look into PDO further for more help.
  12. I assume you mean the following: try { $conn = new PDO("mysql:host=$servername;dbname=$database", $username, $password); // set the PDO error mode to exception $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); //echo "Connected successfully"; } catch(PDOException $e) { echo "Connection failed: " . $e->getMessage(); } As a point of interest I changed - echo "<pre>" . print_r($result, 1) . "</pre>"; To - echo "<pre>" . print_r($conn, 1) . "</pre>"; To which I got the following: This is - or would be the menu for links to Home page etc. Not sure if this is helpful.
  13. <td class="navItem"> <?php echo "<pre>" . print_r($result, 1) . "</pre>"; if(!empty($result)) { foreach($result as $row) { ?> <a href="index.php?id=<?php echo $row['id']; ?>"><?php echo $row['menuheader']; ?>echo</a> <?php } } ?> </td> This now gives me an error: Notice: Undefined variable: result in C:\xampp\htdocs\testsite\index.php on line 33. I assume this means is not set. How do I remove 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.