-4

im setting up a new mysql/php server, im trying to pull data from the mysql db but everything after the <?php tag is cutoff

ive tried putting test html, <p>test</p> above the php and after, only the test html above html was displayed

<?php
mysql_connect("localhost","root","");
mysql_select_db("pet");
$sql = mysql_query("SELECT * FROM pet");
$name = 'name';
$owner = 'owner';
$species = 'species';
$sex = 'sex';
$birth = 'birth';
$death = 'death';
$rows = mysql_fetch_assoc($sql);
echo 'Name: ' . $rows[$id] . '<br>' . 'Owner: ' . $rows[$owner] . '<br>' . 'Species: ' . $rows[$species] . '<br>' . 'Sex: ' . $rows[$sex] . '<br>' . 'Birthday: ' . $rows[$birth];
?>

i expected the table to be displayed, but the output was just the above mentioned "test" from <p>test</p> at the top, nothing else

edit: forgive me, this is my first post and im new to sql and php

Geno Chen
  • 4,916
  • 6
  • 21
  • 39
Bitshawn
  • 19
  • 3
  • Almost 2019 and people are still using `mysql_` functions? (Hopefully your PHP version is new enough that using them will fail, which may be the root of your issue.) – Alexander O'Mara Dec 23 '18 at 05:19
  • @AlexanderO'Mara Yep, that's the consequence of bad API design from the beginning. It's been what, 20 years now? People are still teaching crappy code in classrooms. There are still old books. Infinite number of blog posts from people with tutorials that will never really go away. At least `mysql_*` is gone as of PHP 7, so I think folks won't have to deal with it much longer. – Brad Dec 23 '18 at 05:29
  • 1
    @AlexanderO'Mara Come to think of it, the lack of the original MySQL extension might very well be the root issue here for this question. – Brad Dec 23 '18 at 05:30

2 Answers2

1

Have you looked through the error logs?

Errors and warnings usually appear in ....\logs\php_error.log or ....\logs\apache_error.log depending on your php.ini settings.

But what I think is happening here is that your PHP is crashing when it tries to parse $row[$id] since you haven't yet initialized $id.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Tim Austin
  • 31
  • 1
  • 6
0

you have an error in your code ! if you are using a new version of PHP you must use mysqli instead of mysql you can see the exact error in php error log