OsirisElKeleni Posted November 24, 2014 Share Posted November 24, 2014 Hello again! I'm here with another PHP/Mysqli related question, I want to output the data i receive from the Query: SHOW tables; Into html code, more specific: links. This is what i try'd to do: <div class="container"> <div class="header" align="center"> <nav> <ul> <li><a href="#">Home</a></li> <li><a href="#">Databases</a> <ul> <?php $mysqli = new mysqli('localhost','*****','*****','*****'); if ($mysqli->connect_error) { die("Connection failed: " . $mysqli->connect_error); } $sql = 'show tables from osiris1q_mtg'; $result = $mysqli->query($sql); if(!$result = $mysqli->query($sql)){ die('There was an error running the query [' . $mysqli->error . ']'); } // output data of each row while($row = $result->fetch_assoc()){ echo "<li><a href='#'></a>"$row"</li>"; } } else { echo "<li><a href='#'></a>0 results</li>"; } </ul> </li> </ul> </nav> </div> <!-- end .header --> ?> This is the header.php file which is included in the actual index page. This doesn't return anything not even the html parts of it. Even all the files i have 'included' aren't showing up anymore. I hope i explained myself good enough for anyone to understand How Anyone can help me out! Thank you in Advance! Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted November 24, 2014 Share Posted November 24, 2014 your code contains a fatal php parse/syntax error, because you are missing a closing ?> tag. you need to have php's error_reporting set to E_ALL and display_errors set to ON in your php.ini so that php will report and display all the errors it detects. you will save a ton of time. for parse errors in your main file, you cannot put these settings into your code, because your code never runs to make use of the settings. Quote Link to comment Share on other sites More sharing options...
OsirisElKeleni Posted November 24, 2014 Author Share Posted November 24, 2014 your code contains a fatal php parse/syntax error, because you are missing a closing ?> tag. you need to have php's error_reporting set to E_ALL and display_errors set to ON in your php.ini so that php will report and display all the errors it detects. you will save a ton of time. for parse errors in your main file, you cannot put these settings into your code, because your code never runs to make use of the settings. I dont see where I'm missing the closing tag i'm sorry, The php.ini file i've uploaded and this is the error: Parse error: syntax error, unexpected '$row' (T_VARIABLE), expecting ',' or ';' in /home/osiris1q/public_html/includes/header.php on line 20 This is the line but i dont see whats wrong: echo "<li><a href='#'></a>"$row"</li>"; Quote Link to comment Share on other sites More sharing options...
Solution Ch0cu3r Posted November 24, 2014 Solution Share Posted November 24, 2014 (edited) This is the line but i dont see whats wrong: It is not a valid string! You have ended the string, followed that by $row and started a new string. That is not the correct string syntax. The correct way would be to use the concatenation operator ( . a period ) between the string and the variable. If you are to display the table name. Then the while loop needs to be while($row = $result->fetch_row()) { echo "<li><a href='#'></a>".$row[0]. "</li>"; } Next problem is the closing php tag ?> is in the wrong place. It should be after this else statement else { echo "<li><a href='#'></a>0 results</li>"; } // closing tag should be after the above lines ?> You cannot place raw HTML between php tags. Edited November 24, 2014 by Ch0cu3r 1 Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 24, 2014 Share Posted November 24, 2014 There are several problems with that code. Line 22: There is an else statement that is NOT associated with any if() statement. The two previous if() statements were closed right after they were started. So, that else statement is out of context. Line 24: There is a closing bracket for the else condition, directly followed by raw HTML code. Line 29: There is a closing PHP tag, but the code that it follows is HTML <div class="container"> <div class="header" align="center"> <nav> <ul> <li><a href="#">Home</a></li> <li><a href="#">Databases</a> <ul> <?php $mysqli = new mysqli('localhost','*****','*****','*****'); if ($mysqli->connect_error) { die("Connection failed: " . $mysqli->connect_error); } $sql = 'show tables from osiris1q_mtg'; $result = $mysqli->query($sql); if(!$result = $mysqli->query($sql)){ die('There was an error running the query [' . $mysqli->error . ']'); } // output data of each row while($row = $result->fetch_assoc()){ echo "<li><a href='#'></a>"$row"</li>"; } } else { echo "<li><a href='#'></a>0 results</li>"; } </ul> </li> </ul> </nav> </div> <!-- end .header --> ?> 1 Quote Link to comment Share on other sites More sharing options...
OsirisElKeleni Posted November 24, 2014 Author Share Posted November 24, 2014 Thank you all for you're replies! I have been stupid and forgot thet HTML doen't belong in the php tags.. And indeed the else function is nothing without an if Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.