+ 3

PHP and mysql help

Hi All I am trying to do an sql query where it links from the index page to the article page using a hyperlink. I have been racking my brain on it for several weeks now and trying to use internet tutorials but i just cant seem to get it working. I will paste the code for the index page and the article page below . Index <?php //Code to connect Database to Site $databaseName='group3'; //Database Name $host='localhost'; //Location of the Database $user='acastio'; //Username $password='default1'; //Password $conn = mysqli_connect($host, $user, $password, $databaseName); if (mysqli_connect_errno($conn)) { echo 'Failed to connect to MySQL: ' . mysqli_connect_error(); } ?> <!DOCTYPE html> <?php include "header.php"; ?> <div> <?php $sql = "SELECT Article.aid, Article.publish_date, Article.author_id, Article.title, Article.body, Article.has_image, User.full_name FROM Article LEFT JOIN User ON Article.author_id = User.uid"; $result = mysqli_query($conn, $sql); while ($row = mysqli_fetch_assoc($result)) { echo "<a href=byline.php?id=" . $row['author_id'] . "><h3>" . $row['full_name'] . "</h3></a><a href=article.php?id=" . $row['aid'] . "><h4>" . $row['title'] . "</h4></a>" . $row['body']; echo $row['author_id']; } $conn->close(); ?> </div> <?php include "footer.php"; ?> Article <?php //Code to connect Database to Site $databaseName='group3'; //Database Name $host='localhost'; //Location of the Database $user='acastio'; //Username $password='default1'; //Password $conn = mysqli_connect($host, $user, $password, $databaseName); if (mysqli_connect_errno($conn)) { echo 'Failed to connect to MySQL: ' . mysqli_connect_error(); } $id = $_GET["id"]; $id = mysqli_real_escape_string($conn,$id); $sql = "SELECT Article.aid, Article.publish_date, Article.author_id, Article.title, Article.body, Article.has_image, User.full_name FROM Article LEFT JOIN User ON Articl

12th Apr 2018, 4:31 PM
Zoe
Zoe - avatar
5 ответов
+ 2
Maybe try code similar to this: $byline_url = 'byline.php?id' . $row['author_id']; $article_url = 'article.php?id=' . $row['aid']; echo '<a href="' . $url . '"><h3>' . $row['full_name'] . '</h3></a><a href='"' . $article_url' . '"><h4>' . $row['title'] . "</h4></a>" . $row['body']; Can you copy and paste the generated HTML into the SoloLearn Playground? Maybe then we can see what HTML you are generating. Also give any PHP errors or warnings.
14th Apr 2018, 1:24 AM
Emma
+ 2
Don't be sorry for not knowing something ☺ We're all learning.
14th Apr 2018, 1:00 PM
Emma
+ 1
Hi all Thank you for answering my question it was for an assignment that was due on the 13th but I some how fixed the code and got it working when I was trying to put it back to how it originally was ... not sure what was different when I changed it back make it work but it did ... I am sorry I do not know what the difference is between mysql and SQL .
14th Apr 2018, 12:59 PM
Zoe
Zoe - avatar
+ 1
:)
14th Apr 2018, 1:01 PM
Zoe
Zoe - avatar
0
hi all i'am sorry before, I'm a beginner for SQL and PHP. I must learn to much about it. I'm sure step by step understand to both case. I have a question for all, in PHP, what is a different specific between mysql and SQL server for configuration in PHP ?? please, anyone answer this to solve this case thankyou all
14th Apr 2018, 2:59 AM
fajar muhammad
fajar muhammad - avatar