Solved Designing a basic website for a friend.

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

techkid

David
Thread Starter
Joined
Sep 1, 2004
Messages
2,339
Hi everyone,

I am writing a basic website for a friend, as a proof of concept for a project she is looking into. What it is, she wants to help people with mental health issues express themselves and submit poetry to help themselves and potentially others.

Now, while my knowledge of website design is far out of date (HTML 4.01 is... what, 15 years old now? And superseded by HTML 5), I am trying to just get the idea down, so we can get it done professionally and properly when we do go live. But I am running into issues with my code shown below:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
    <title>Soul's Fire</title>
    </head>
    <body background="Images/background.png">
        <center><img src="Images/heading.png"></center>
        <h1 align="center"><font color="#cc9900">Soul's Fire</font></h1>
        <p align="center">Words go here</p>
        <?php
            $dbconnect=mysqli_connect("127.0.0.1","user","password","poems");
            $result=mysqli_query($dbconnect, "SELECT * FROM 'submissions' WHERE Approved='Y' ORDER BY RAND() LIMIT 1");
            if ($row=mysqli_fetch_row($result))
        {
            echo "<table border=1 width='80%'>\n";
            echo "<tr><th width='10%'>Author</th><th width='15%'>Title</th><th width='10%'>Time Submitted</th><th width='*'>Entry</th></tr>\n";
            do
                {
                printf("<tr><td align='center'>%s</td><td align='center'><b>%s</b></td><td align='center'>%s</td><td>%s</td></tr>\n",
                $row["Author"], $row["Title"], $row["Time_submit"], $row["Entry"]);
                }
            while ($row=mysqli_fetch_row($result));
            echo "</table><br>\n";
            echo ("<p align='center'><a href='#top'>Back to Top</a></p>");
            }
               else
            {
            echo "No records in database.";
            }
        ?>
        <div align="center">
            <table width="50%">
            <tr>
                <th align="left">Probably have visitor submissions here</th>
                <th align="right">And I will probably use this for feedback</th>
            </tr>
            </table>
        </div>
        <h1 align="center"><font color="#cc9900">If you would like me to add content down here, let me know</font></h1>
    </body>
</html>
When I test the page out, I get this:

Untitled.png

What I am trying to achieve, is to post one random poem on the homepage which has been approved (I have made a table in MySQL where poetry is saved with a basic Y/N approval process, for future use), for a viewer to read and see what the site is about. But I need to have this issue sorted before I can proceed.

Thank you in advanced.
 

JiminSA

Jim
Joined
Dec 15, 2011
Messages
3,407
If you don't want warning messages to show, simply put the following line at the top of your php ...
PHP:
error_reporting(E_ALL & ~(E_WARNING));
... that will exclude the warning message only;)
 

colinsp

Colin
Joined
Sep 5, 2007
Messages
2,362
While you are at it change your first line of code to

Code:
<!DOCTYPE html>
Then you can make use of html 5. ;)

I would also consider using div's in CSS rather than tables for the display of the poem then you can easily make the site responsive for small screened devices.
 

techkid

David
Thread Starter
Joined
Sep 1, 2004
Messages
2,339
Thank you, colinsp and JiminSA. Like I said, though, my knowledge is way out of date. Even when I was studying (in 2003) I was not that good at it. And now things have changed and I don't have much free time to study, so I am using the little I do have to make the proof of concept work. Which it currently is not.
 

techkid

David
Thread Starter
Joined
Sep 1, 2004
Messages
2,339
Well, the previous error (Warning: mysqli_fetch_row() expects parameter 1 to be mysqli_result, boolean given in C:\wamp64\www\souls_fire\index.php on line 13) references this section:

Code:
if ($row=mysqli_fetch_row($result))
 {
  echo "<table border=1 width='80%'>\n";
  echo "<tr><th width='10%'>Author</th><th width='15%'>Title</th><th width='10%'>Time Submitted</th><th width='*'>Entry</th></tr>\n";
  do
   {
   printf("<tr><td align='center'>%s</td><td align='center'><b>%s</b></td><td align='center'>%s</td><td>%s</td></tr>\n",
   $row["Author"], $row["Title"], $row["Time_submit"], $row["Entry"]);
   }
  while ($row=mysqli_fetch_row($result));
  echo "</table><br>\n";
I have tried to look up the use of "mysqli_result", but implementation was only making the issue worse. I cannot see any issue with it, but I still cannot pull the data from the database.
 

JiminSA

Jim
Joined
Dec 15, 2011
Messages
3,407
According to the warning message your table is empty - i.e. no array of rows in $result just the boolean 'false' ...
 

techkid

David
Thread Starter
Joined
Sep 1, 2004
Messages
2,339
The thing is, I do in fact have data there (enough to test the idea anyway)...
Untitled.png
 

JiminSA

Jim
Joined
Dec 15, 2011
Messages
3,407
I really don't know why your select is not picking up the random record:(
Be that as it may, let's try an alternative randomising method ...
Simplify your select like so:
PHP:
$result=mysqli_query($dbconnect, "SELECT * FROM 'submissions' WHERE Approved='Y');
...then put the selection into an array:
PHP:
while ($row=mysqli_fetch_row($result))
{
    $random_array[] = $row['ID'];
}
... then select a random id:
PHP:
$random_id = array_rand($random_array, 1);
and finally get the selected record:
PHP:
$result=mysqli_query($dbconnect, "SELECT * FROM 'submissions' WHERE ID='$random_id'");
... and use that.
 

techkid

David
Thread Starter
Joined
Sep 1, 2004
Messages
2,339
I identified the problem. It was in fact my use of quotations...

"SELECT * FROM 'submissions' WHERE Approved='Y' ORDER BY RAND() LIMIT 1" causes the error, but

"SELECT * FROM submissions WHERE Approved='Y' ORDER BY RAND() LIMIT 1" works.

I ended up poking around in phpMyAdmin, trying to figure out that line (which worked the first time around), when it generated an SQL error. Taking the quotes out fixed it.
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Members online

Top