Hello i got a problem with my mysql code it gives the following error upon trying to output:
Parse error: syntax error, unexpected $end in C:\xampplite\htdocs\learncent\acksearch\search.php on line 25
<?php
$db = new mysqli("localhost","root","","acksocial");
if(mysqli_connect_error())
{
printf("Connection failed:%s \n",mysqli_connect_error());
exit();
}
$name = mysqli_real_escape_string($db, $_POST['search']);
$table = 'acksearch';
if($result = $db->query("SELECT * FROM $table WHERE name = $name", MYSQLI_ASSOC))
{
while($row = $result->fetch_object())
{
// $row is an associative array
// Do something here
echo "Name: ".$row['name'];
echo " country: ".$row['country'];
}
$db->close();
?>
EDIT:
added 1 more } and no error but it wont output the result?
Would be good if anyone could help me.
EDIT AGAIN : Now the code look like this
<?php
$db = new mysqli("localhost","root","","acksocial");
if(mysqli_connect_error())
{
printf("Connection failed:%s \n",mysqli_connect_error());
exit();
}
$name = mysqli_real_escape_string($db, $_POST['search']);
$table = 'acksearch';
if($result = $db->query("SELECT * FROM $table WHERE name = $name", MYSQLI_ASSOC))
{
while($row = $result->fetch_object())
{
// $row is an associative array
// Do something here
echo "Name: ".$row['name'];
echo " country: ".$row['country'];
}
The error its giving its:
Parse error: syntax error, unexpected $end in C:\xampplite\htdocs\searcher.php on line 25
Thanks Fredrik
you did not close the while loop:
you need to add
}after the last row.