ballhogjoni Posted January 5, 2007 Share Posted January 5, 2007 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 More sharing options...
kenrbnsn Posted January 5, 2007 Share Posted January 5, 2007 I'm surprised that is the only syntax error you're getting since you don't have any quotes deliminating the string in this line:[code]<?php printf(Could not retrieve records: %s\n, mysqli_error($mysqli));?>[/code]Ken Link to comment https://forums.phpfreaks.com/topic/32925-mysql-code-must-be-wrong/#findComment-153315 Share on other sites More sharing options...
ballhogjoni Posted January 5, 2007 Author Share Posted January 5, 2007 I was actually getting an error when I put the quotes in this lineprintf("Could not retrieve records: %sn", mysqli_error($mysqli)); Link to comment https://forums.phpfreaks.com/topic/32925-mysql-code-must-be-wrong/#findComment-153319 Share on other sites More sharing options...
simcoweb Posted January 5, 2007 Share Posted January 5, 2007 It should work if you change this line as follows:echo "The Id is $id and the text is $testfield"; Link to comment https://forums.phpfreaks.com/topic/32925-mysql-code-must-be-wrong/#findComment-153344 Share on other sites More sharing options...
PFMaBiSmAd Posted January 5, 2007 Share Posted January 5, 2007 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 https://forums.phpfreaks.com/topic/32925-mysql-code-must-be-wrong/#findComment-153358 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.