Jump to content

[SOLVED] Arrays #$%^&$#


Topshed

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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

 

 

 

Link to comment
Share on other sites

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.... ;D:D :-X

 

 

 

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.