Napravio sam MySQL bazu i uspješno sam se konektovao na nju. U bazi sam napravio tabelu 'food' koja ima četiri kolone 'id', 'food', 'calories', 'zdravo_nezdravo'.
Pokušavam već 2 sata da izvršim ovaj dio koda, ali ne ide mi.
Code:
<?php
require 'mysqlconnect.inc.php'
//$query = "SELECT `food`,`callories` FROM `food` ORDER BY `id`";
$query = "SELECT `food`, `calories` FROM `food` ORDER BY `id`";
if($query_run = mysql_query($query))
{
echo 'Query success';
else
{
echo 'Query dont sucess';
}
}
?>
<?php
require 'mysqlconnect.inc.php'
//$query = "SELECT `food`,`callories` FROM `food` ORDER BY `id`";
$query = "SELECT `food`, `calories` FROM `food` ORDER BY `id`";
if($query_run = mysql_query($query))
{
echo 'Query success';
else
{
echo 'Query dont sucess';
}
}
?>
A evo koda za konektovanje sa bazom:
Code:
<?php
ini_set("display_errors",1);
$dbhost = 'localhost:3306 ';
$dbuser = 'root';
$dbpass = '';
$db = 'adatabase';
$conn = mysql_connect($dbhost,$dbuser,$dbpass);
mysql_selectdb($db);
if (!$conn) {
die('Could not connect: ' . mysql_error());
}
echo 'OK';
?>
<?php
ini_set("display_errors",1);
$dbhost = 'localhost:3306 ';
$dbuser = 'root';
$dbpass = '';
$db = 'adatabase';
$conn = mysql_connect($dbhost,$dbuser,$dbpass);
mysql_selectdb($db);
if (!$conn) {
die('Could not connect: ' . mysql_error());
}
echo 'OK';
?>
Poruka koja mi se javlja kao greška je:
Parse error: syntax error, unexpected T_VARIABLE in C:\wamp\www\hari\index.php on line 5
EDIT
Promijenio sam tabelu u 'hrana' iz razloga sto sam mislio da polje 'food' i isti naziv tabele 'food' stvara problem. Medjutim ponovo dobijam istu grešku. Evo koje naredbe sam pokušao da propustim i ni jedna nije prošla:
Code:
//$query = "SELECT 'food', 'calories' FROM 'Hrana';
//"$query = "SELECT `food` FROM `Hrana`";"
//$query = "SELECT food FROM Hrana";
//$query = "SELECT 'food' FROM 'Hrana'";
$query = "SELECT `id` FROM `hrana`";
//$query = "SELECT 'food', 'calories' FROM 'Hrana';
//"$query = "SELECT `food` FROM `Hrana`";"
//$query = "SELECT food FROM Hrana";
//$query = "SELECT 'food' FROM 'Hrana'";
$query = "SELECT `id` FROM `hrana`";
Uvijek ista greška....
[Ovu poruku je menjao Kondenzator dana 18.01.2013. u 16:06 GMT+1]