Jump to content

Connect to mySql database


krkec

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/283543-connect-to-mysql-database/
Share on other sites

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/. 

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.