开发者

output the result of a query of a database? [closed]

开发者 https://www.devze.com 2023-03-27 19:46 出处:网络
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a 开发者_运维技巧specific moment in time,or an extraordinarily narrow situation that is not g
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a 开发者_运维技巧specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 10 years ago.

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:

while($row = $result->fetch_object())
    {

    // $row is an associative array

    // Do something here

echo "Name: ".$row['name'];

echo " country: ".$row['country'];

}///// I added this } here

you need to add } after the last row.


This error occurs if somewhere a } is missing.

In your case there should be a second } prior to $db->close();


You need to close one more brace "}" before you end "?>"

0

精彩评论

暂无评论...
验证码 换一张
取 消