Topshed Posted November 23, 2007 Share Posted November 23, 2007 G'day, Being new to this I am using books to learn and typing in code, but my latest effort defies my logic I am trying to find a unique record and print it to the screen but I cannot solve the errors as the code is as printed in the book <?php require_once '../Includes/my_conn.php'; $dbname = "steam"; // Make connection to database If no connection made, display error Message $connect = mysqli_connect($host,$account,$password) OR DIE("Error !! Unable to connect to database"); echo 'Step 1: Connected successfully! <BR>'; // Select database or print error message if unsuccessful $db = mysqli_select_db($connect,"$dbname") or die( "Unable to select database ".steam); echo 'Step 2: Connected to ('.$dbname.') successful!<BR>'; $db="SELECT * FROM lner WHERE br_no = lner"; if ($result = mysqli_query($connect,$db)) { //$row = mysqli_fetch_array($result); if (mysqli_num_rows($result) >0 { //This line gives the error //syntax error, unexpected '{' in test-1.php on line 16 while ($row = mysqli_fetch_assoc($result)){ print "Number"; print "{$row['br_no']}<br />\n"; print "Type"; print "{$row['lclas']}<br />\n"; print "Type"; print "{$row['lclas']}<br />\n"; } } mysqli_free_result($resu8lt); } mysqli_close(); ?> If I comment the { out then an error jumps to the next line unexpected T_WHILE in test-1.php on line 17 Someone please give me a hand thanks in advance Roy.. Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted November 23, 2007 Share Posted November 23, 2007 change if (mysqli_num_rows($result) >0 { //This line gives the error to if (mysqli_num_rows($result)) >0 { //This line gives the error PhREEEk Quote Link to comment Share on other sites More sharing options...
phpSensei Posted November 23, 2007 Share Posted November 23, 2007 Change mysqli_free_result($resu8lt); to mysqli_free_result($result); Quote Link to comment Share on other sites More sharing options...
revraz Posted November 23, 2007 Share Posted November 23, 2007 Tracking down missing () {} [] can be painful. Get a good editor that highlights matching ( [ { Quote Link to comment Share on other sites More sharing options...
phpSensei Posted November 23, 2007 Share Posted November 23, 2007 Tracking down missing () {} [] can be painful. Get a good editor that highlights matching ( [ { Its a pretty short script, you probably can do it without the highlighters. Quote Link to comment Share on other sites More sharing options...
revraz Posted November 23, 2007 Share Posted November 23, 2007 But he didn't. Quote Link to comment Share on other sites More sharing options...
Topshed Posted November 23, 2007 Author Share Posted November 23, 2007 Thank you guys for that, I take the point about the highlighting, I did not want to be seen as unclear in my post but I now have two problems sort of... if (mysqli_num_rows($result)) >0 { Now give a syntax error unexpected '>' in test-1.php on line 16 and a suggestion as to recommended / best PHP editors, I use Dreamweaver and CSE Validator neither of which appear to be much help Regards Roy... Quote Link to comment Share on other sites More sharing options...
phpSensei Posted November 23, 2007 Share Posted November 23, 2007 $result = mysqli_query($connect,$db)) You trying to count the num of rows for a connection? Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted November 23, 2007 Share Posted November 23, 2007 Sorry... if (mysqli_num_rows($result)) >0 { to if (mysqli_num_rows($result) > 0) { PhREEEk Quote Link to comment Share on other sites More sharing options...
trq Posted November 23, 2007 Share Posted November 23, 2007 This line... if (mysqli_num_rows($result)) >0 { should be.... if (mysqli_num_rows($result) > 0) { Better still.... if (mysqli_num_rows($result)) { Quote Link to comment Share on other sites More sharing options...
phpSensei Posted November 23, 2007 Share Posted November 23, 2007 Ya you beat me to it, the space between the 0 and the > was read as an operation by the php. Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted November 23, 2007 Share Posted November 23, 2007 Top - There have been many discussions on which is the best PHP editor, and there are different types of editors as well. There are 'notepad' type replacement apps that simply highlight code, etc., and then there are studios, or suites, with debugging features, code beautifiers, etc. It depends on what you want. I use a standalone notepad replacement called Notepad Pro by GridinSoft. It does everything I need, and although extremely feature-rich, you can use it right from the setup and worry about features later. If you search the forums here, or do a google search for PHP editors, you'll have your hands full in no time. I came from old skool HTML programming solely using Notepad. I started programming in PHP using Notepad and got along just fine. In fact, I believe it -forced- me to be a better trouble-shooter. Some of the studios might actually make a newb programmer a bit lazy. Going from Notepad to the GridinSoft Notepad was a welcome change, and having it match up braces and parens I have found time-saving over and over again. There is no substitute for learning, but once you have learned, there are tools to make your life easier. You learn with a hammer, but sometimes a nail gun comes in damn handy. = ) PhREEEk Quote Link to comment Share on other sites More sharing options...
Topshed Posted November 23, 2007 Author Share Posted November 23, 2007 Thanks guys, I am starting to think php don't like me much now line 5 which has worked fine for a day or so, now reports Call to undefined function mysqli_connect() in test-1.php on line 5 $connect = mysqli_connect($host,$account,$password) OR DIE("Error !! Unable to connect to database"); I have double checked that $host,$account & $password are exactly the same in .y include which I have changed to syntax for Roy.... Quote Link to comment Share on other sites More sharing options...
revraz Posted November 23, 2007 Share Posted November 23, 2007 It's hard to imagine that mysqli wouldn't be supported if it worked in the past, but you could try to change mysqli_connect() to mysql_connect() Quote Link to comment Share on other sites More sharing options...
Topshed Posted November 23, 2007 Author Share Posted November 23, 2007 To refresh <?php //include_once("../includes/BStesty_conn.php"); $host = 'xxx.xx.xxx.xx'; $account = 'topshed_Roy'; $password = 'xxxxxx'; $dbname = 'topshed_steam'; // Make connection to database If no connection made, display error Message $connect = mysql_connect($host,$account,$password) OR DIE("Error !! Unable to connect to database"); echo 'Step 1: Connected successfully! <BR>'; // Select database or print error message if unsuccessful $db = mysql_select_db($connect,"$dbname") or die( "Unable to select database ".topshed_steam); echo 'Step 2: Connected to ('.$dbname.') successful!<BR>'; $db="SELECT * FROM lner WHERE br_no = lner"; if ($result = mysql_query($connect,$db)) { //$row = mysqli_fetch_array($result); if (mysql_num_rows($result)) { while ($row = mysql_fetch_assoc($result)){ print "Number"; print "{$row['br_no']}<br />\n"; print "Type"; print "{$row['lclas']}<br />\n"; print "Type"; print "{$row['lclas']}<br />\n"; } } mysql_free_result($resu8lt); } mysql_close(); ?> Your suggestion got mt past that error but it would not go past $db = mysqli_select_db($connect,"$dbname") which is not suprising BUT removing the i from the select statement gave me mysql_select_db(): supplied argument is not a valid MySQL-Link resource ?>???%#*@ Just as a matter of interest will the rest of the script work when I get this bit right ? Regards Roy Quote Link to comment Share on other sites More sharing options...
revraz Posted November 23, 2007 Share Posted November 23, 2007 Remove the quotes from $dbname and see if that helps Quote Link to comment Share on other sites More sharing options...
Topshed Posted November 23, 2007 Author Share Posted November 23, 2007 Hi revraz The board is telling me you posted a reply about 20 mins ago but it appears to have disapeared into a black hole ?? could you post again please Thanks Roy.. Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted November 23, 2007 Share Posted November 23, 2007 This $db = mysql_select_db($connect,"$dbname") or die( "Unable to select database ".topshed_steam); should be $db = mysql_select_db("$dbname") or die( "Unable to select database ".$dbname); Quote Link to comment Share on other sites More sharing options...
Topshed Posted November 23, 2007 Author Share Posted November 23, 2007 Thank you all so much for your assistance, It now appears it was not all me but my ISP had PHP set up so that 5xx commands and mysqli_ commands gave errors I sent them a clip from a Sticky at the top of this group,and they fixed it by putting a php.ini in my root. Then every thing you said worked and I had it fully working in about 20 minutes. All I need to do now is change my dreamwaever template to handle the php code rather than the old ASP code Kind regards You guys smoked me with your fast responses Roy.... :-X Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.