Jump to content

Help With Php Mysql


R3v07v3R

Recommended Posts

Hi I am trying to pull data from a MySQL table but it keeps returning some of the PHP code instead of the results.

 

 

<?


$db_server = '127.0.0.1';
$db_usr = 'user123';
$db_pass = '123456';
$db_database = 'test';


$con = mysql_connect($db_server, $db_usr, $db_pass, $db_database);


if (!$con)
{
die('Could not connect: ' . mysql_error());
}


$query = "SELECT * FROM bookings WHERE `booking_start` <= NOW( ) ORDER BY booking_start";


$result = mysql_query($query);


echo mysql_error();
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$bookingnum = $row['booking_num'];
$servernum = $row['server_num'];
$usrnum = $row['usr_num'];
$start = $row['booking_start'];
$end = $row['booking_end'];
$creation = $row['booking_made'];


echo " <div>
bookingnum: $bookingnum<br />
servernum: $servernum<br />
usrnum: $usrnum<br />
start: $start<br />
end: $end<br />
creation: $creation<br />
</div>
";
}


mysql_close($con);


?>

 

So please tell me if I am missing something, but this is what my query returns.

 

8b80a5f059143cf5a623e61f92d8fa1db51b9ac2af3422e1c9de3fc377f82a082g.jpg

 

and this is what the MySQL table looks like.

 

66698ddc989fe0efccc4ab74e9c5f8c73fcd8cec120e7b998d89216904293f152g.jpg

Link to comment
https://forums.phpfreaks.com/topic/270543-help-with-php-mysql/
Share on other sites

Unfortunately you are working in a .html document which obviously cannot parse php

 

Not necessarily. A server can be configured to .html being able to parse php

 

Hi I am trying to pull data from a MySQL table but it keeps returning some of the PHP code instead of the results.

 

 

<?


$db_server = '127.0.0.1';
$db_usr = 'user123';
$db_pass = '123456';
$db_database = 'test';


$con = mysql_connect($db_server, $db_usr, $db_pass, $db_database);


if (!$con)
{
die('Could not connect: ' . mysql_error());
}


$query = "SELECT * FROM bookings WHERE `booking_start` <= NOW( ) ORDER BY booking_start";


$result = mysql_query($query);


echo mysql_error();
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$bookingnum = $row['booking_num'];
$servernum = $row['server_num'];
$usrnum = $row['usr_num'];
$start = $row['booking_start'];
$end = $row['booking_end'];
$creation = $row['booking_made'];


echo " <div>
bookingnum: $bookingnum<br />
servernum: $servernum<br />
usrnum: $usrnum<br />
start: $start<br />
end: $end<br />
creation: $creation<br />
</div>
";
}


mysql_close($con);


?>

 

<? is used for a document that contains only php nothing else. switch to <?php

Link to comment
https://forums.phpfreaks.com/topic/270543-help-with-php-mysql/#findComment-1391591
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.