Jump to content

mysql code must be wrong


ballhogjoni

Recommended Posts

This  is the error I get: Parse error: syntax error, unexpected $end in /home/realfina/public_html/signup=/article_cash/test.php on line 28

<?php
$username="xxxxxxxxx";
$password="xxxxxxxxxxx";
$database="xxxxxxxx";

$mysqli = mysqli_connect("localhost","$username","$password","$database");

if (mysqli_conect_errno()) {
  printf("connect failed:%s\n", mysqli_connect_error());
  exit();
} else {
    $sql = "SELECT TOP 1 * FROM xxxxxxxxx ORDER BY ID DESC";
    $res = mysqli_query($mysqli, $sql);

        if ($res) {
                while ($newArray = mysqli_fetch_array($res, MYSQLI_ASSOC)) {
                      $id = $newArray['id'];
                      $testfield = $newArray['testfield'];
                      echo "The Id is ".$id." and the text is ".$testfield."<br>;
                    }
} else {
    printf(Could not retrieve records: %s\n, mysqli_error($mysqli));
}
}

mysqli_free_result($res);
mysqli_close($mysqli);

?>
Link to comment
https://forums.phpfreaks.com/topic/32925-mysql-code-must-be-wrong/
Share on other sites

simcoweb's correction will solve the parse error (the original line of code had one double-quote after the last variable.)

Because of the misplaced ; after the echo line in the post, I suspect that your code has a [b]"< br / >"[/b] (without the spaces) but that the final double-quote on this is missing. This < br / > caused the newline in the post because the code was not enclosed in [ CODE ] tags. Posting this in [ CODE ] tags also would have helped find the problem as the color highlighting would have pointed out the missing quote.

The next problem, as kenrbnsn pointed out, would be the missing quotes in the printf(...) statement.

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.