Hi fellow coders, I'm a noob to PHP/mySQL and I'm enjoying it, but I'm stuck... I'm in the process of developing my first database driven website. I've created the database, the tables... loaded one table in particular with content in an attempt to pull data from it via PHP. If you go to my website live via the browser, there is a navigation system that seems to work but, it's not loading content from the db table. It's just blank content with a nav system that changes the page in the address bar but blank content. I've provided the code along with a image shot of the table in my database I'm trying to GET the data from. The db table i'm getting from is called vls_pages. It is also the table featured in the image. I'm hoping someone can point me to getting this to function correctly. Thank you everyone index.php CODE: ----------------------------------------------------------------------------------------------------------------------- Code: <?php // Load Setup document: include ('_config/setup.php'); ?> <!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title><?php echo $page_title; ?></title> <link rel="stylesheet" type="text/css" href="_css/styles.css"> </head> <body> <div class="wrap_overall"> <div class="nav_main"> <?php include('_template/nav_main.php'); ?> </div> <div class="body_header"> <?php get_page_name($dbc, $pg); ?> </div> <div class="content"> <?php get_page_body($dbc, $pg); ?> </div> <div class="footer"> <?php include('_template/footer.php'); ?> </div> </div> </body> </html> ----------------------------------------------------------------------------------------------------------------------- setup.php CODE: ----------------------------------------------------------------------------------------------------------------------- Code: <?php ## Setup Document // host(or location of the database), username, password, database name //Variables for connecting to your database. //These variable values come from your hosting account. $hostname = "***************"; $username = "***************"; $password = "***************"; //Connecting to your database $dbc = @mysqli_connect($hostname, $username, $password) OR DIE ("Unable to connect to database! Please try again later."); // Check connection if (mysqli_connect_errno($dbc)) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } include('_functions/snippets.php'); if ($_GET['pgname'] == '') { $pg = 'home'; } else { $pg = $_GET['pgname']; } $page_title = get_page_title($dbc, $pg); ?> ----------------------------------------------------------------------------------------------------------------------- snippets.php CODE: ----------------------------------------------------------------------------------------------------------------------- Code: <?php // Snippets; Functions function get_page_title ($dbc, $pg) { $query = "SELECT pgtitle FROM vls_pages AND pgstatus = 1 LIMIT 1"; $result = @mysqli_query($dbc, $query); $page = @mysqli_fetch_assoc($result); return $page['pgtitle']; @mysqli_close($dbc); } function get_page_name ($dbc, $pg) { $query = "SELECT pgname FROM vls_pages WHERE pgname = '$pg' AND pgstatus = 1 LIMIT 1"; $result = @mysqli_query($dbc, $query); $page = @mysqli_fetch_assoc($result); echo '<h1>'.$page['pgname'].'</h1>'; @mysqli_close($dbc); } function get_page_body ($dbc, $pg) { // the database connection, our query $query = "SELECT * FROM vls_pages WHERE pgbody = '$pg' AND pgstatus = 1 LIMIT 1"; $result = @mysqli_query($dbc, $query); $page = @mysqli_fetch_assoc($result); echo '<div class="content">'.$page['pgbody'].'</div>'; @mysqli_close($dbc); } ?> -----------------------------------------------------------------------------------------------------------------------
use var_dump() to check if the the query is being fetched or not. ex :- PHP: <?php $que = $this->db->query( "SELECT * FROM `exam`" ); $exam = array( ); while ( $res = $que->fetch_assoc() ) { $exam[ ] = $res; } var_dump($exam); // This will show all the data of the exam. In the similar way try for restexit; This will help you in finding the where the problem lies. make check point and check your code ! Good Day !
where in the coding would I place this lil script, after each of my functions on the "snippets.php" page.... before I request the @mysqli_close?
@VisionslC U will get the revised code soon ! Sunday my ofc will be off , i will optimize your code .. Hope would be helpful . Take care.
There is a problem in the mysql statement. This was your code where the error lies Snippets PHP: function get_page_title ($dbc, $pg) { $query = "SELECT pgtitle FROM vls_pages AND pgstatus = 1 LIMIT 1"; $result = @mysqli_query($dbc, $query); $page = @mysqli_fetch_assoc($result); return $page['pgtitle']; @mysqli_close($dbc); } Corrected code:- PHP: function get_page_title ($dbc, $pg) { $query = "SELECT pgtitle FROM vls_pages WHERE pgstatus = 1 LIMIT 1"; $result = @mysqli_query($dbc, $query); $page = @mysqli_fetch_assoc($result); var_dump($page); echo "page title part"; exit; return $page['pgtitle']; @mysqli_close($dbc); }
This is how var_dump is used. Remove the var_dump and exit after testing. and also u not need to call the db connection each and every time you call the function. . try using a framework dude !