Jump to content

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.