krkec Posted November 2, 2013 Share Posted November 2, 2013 Hi I am trying to connect to mysql database and retreve one number. Database has this columns: ID(int), Datum(date), KID(int). <!DOCTYPE html> <html> <head> <link type='text/css' rel='stylesheet' href='style.css'/> <title>PHP!</title> </head> <body> <?php $month = 11; $year = 2013; $list_day = 1; $mysqli= new mysqli("localhost","root","m62rm8F4","test"); if (mysqli_connect_errno($mysqli)) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); exit(); } $query = "SELECT `KID` FROM `upis` WHERE (`Datum` = '" . $year . "-" . $month . "-" . $list_day. "')"; $res = $mysqli->query($query); $row = $res->fetch_array(MYSQLI_NUM); $intnum = $row[0]; echo $intnum; ?> </body> </html> I only get on screen: query($query); $row = $res->fetch_array(MYSQLI_NUM); $intnum = $row[0]; echo $intnum; ?> Please help! What am i doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/283543-connect-to-mysql-database/ Share on other sites More sharing options...
Ch0cu3r Posted November 2, 2013 Share Posted November 2, 2013 (edited) How are you running the PHP code? Are you loading the .php file directly into your browser? (eg the address bar starts with file://). Web browser do not understand PHP code, this is why I think you are seeing the code in the browser. In order to run PHP code on your computer you need to install a http webserver (such as Apache) that is configured with PHP. You can then run the .php files by going to http://localhost/. Edited November 2, 2013 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/283543-connect-to-mysql-database/#findComment-1456624 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.