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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.