Note that there are some explanatory texts on larger screens.

plurals
  1. POHaving issues with displaying data retrieved from a MySQL database with PHP
    text
    copied!<p><strong>I'm very new to PHP; and am doing a few sample projects to help me learn, this project was done for fun. There's probably some idiotic and highly unintelligibly created code in here. Considering I'm a newbie, there's probably a syntax error but I've been searching for hours without any luck.</strong></p> <p>Basically I'm making a extremely simple comment/shoutbox system in which the user who posts the data is kept anonymous. I'm doing things separate at the moment; then I plan on combining them into one. I know that the submitting part is working correctly as I've checked the MySQL database via PHPMyAdmin, however I can't seem to get the data to display right. I've searched for over 2 hours for my simple syntax mistake, and have given up deciding to bring it to a reliable and friendly community.</p> <p>I've removed all of the connection information to my database, as I know all of this is correct and I'd rather not expose it on a public 'forum'.</p> <pre><code>&lt;html&gt; &lt;body&gt; &lt;?php $username=""; $password=""; $database=""; mysql_connect("localhost",$username,$password); mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM data"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); ?&gt; &lt;table border="2" cellspacing="2" cellpadding="2"&gt; &lt;tr&gt; &lt;th&gt;&lt;font face="Arial, Helvetica, sans-serif"&gt;Name(No specific order)&lt;/font&gt;&lt;/th&gt; &lt;/tr&gt; &lt;?php $i=0; while ($i &lt; $num) { $ name=mysql_result($result,$i,""); ?&gt; &lt;tr&gt; &lt;td&gt;&lt;font face="Arial, Helvetica, sans-serif"&gt;&lt;?php echo $name; ?&gt;&lt;/font&gt;&lt;/td&gt; &lt;/tr&gt; &lt;?php $i++; } ?&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>I have two tables, id and name. ID is a automatic increment INT, and name is set up a text. ID is also the primary of the database. The submitting system is working perfectly fine, however the displaying isn't. </p> <p>When I view the page, where there should be text($name), instead I get a blank area, and no text. This is what I received when I visited the page, with only one database entry:</p> <pre><code>&lt;html&gt; &lt;body&gt; &lt;table border="2" cellspacing="2" cellpadding="2"&gt; &lt;tr&gt; &lt;th&gt;&lt;font face="Arial, Helvetica, sans-serif"&gt;Name(No specific order)&lt;/font&gt;&lt;/th&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;font face="Arial, Helvetica, sans-serif"&gt;&lt;/font&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Any help would be appreciated, thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload