R3v07v3R Posted November 10, 2012 Share Posted November 10, 2012 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. and this is what the MySQL table looks like. Link to comment https://forums.phpfreaks.com/topic/270543-help-with-php-mysql/ Share on other sites More sharing options...
Manixat Posted November 10, 2012 Share Posted November 10, 2012 Unfortunately you are working in a .html document which obviously cannot parse php Link to comment https://forums.phpfreaks.com/topic/270543-help-with-php-mysql/#findComment-1391590 Share on other sites More sharing options...
MDCode Posted November 10, 2012 Share Posted November 10, 2012 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 More sharing options...
Manixat Posted November 10, 2012 Share Posted November 10, 2012 Unfortunately you are working in a .html document which obviously cannot parse php ??? Link to comment https://forums.phpfreaks.com/topic/270543-help-with-php-mysql/#findComment-1391592 Share on other sites More sharing options...
MDCode Posted November 10, 2012 Share Posted November 10, 2012 Yes, a server can be configured to parse php in a .html file. Also, if it were a .html file unable to be parsed, then everything would be displayed not just under the while loop Link to comment https://forums.phpfreaks.com/topic/270543-help-with-php-mysql/#findComment-1391593 Share on other sites More sharing options...
Manixat Posted November 10, 2012 Share Posted November 10, 2012 <? is used for a document that contains only php nothing else. switch to <?php[/font] And make sure your file's extension is .php and you're running it on a server Link to comment https://forums.phpfreaks.com/topic/270543-help-with-php-mysql/#findComment-1391594 Share on other sites More sharing options...
R3v07v3R Posted November 10, 2012 Author Share Posted November 10, 2012 Not necessarily. A server can be configured to .html being able to parse php <? is used for a document that contains only php nothing else. switch to <?php That worked perfectly, thank you. I never knew that made a difference. Link to comment https://forums.phpfreaks.com/topic/270543-help-with-php-mysql/#findComment-1391595 Share on other sites More sharing options...
MDCode Posted November 10, 2012 Share Posted November 10, 2012 Completely untrue, php documents can contain html as well as javascript etc. <? is used for only php documents while <?php is correct for documents containing more than php (their echoed html) Link to comment https://forums.phpfreaks.com/topic/270543-help-with-php-mysql/#findComment-1391596 Share on other sites More sharing options...
Pikachu2000 Posted November 10, 2012 Share Posted November 10, 2012 <? works only with the short_open_tag directive set to On. <?php works regardless of the setting. HTML has nothing to do with it. Link to comment https://forums.phpfreaks.com/topic/270543-help-with-php-mysql/#findComment-1391615 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.