Php select behaviour

I have moved some code from one server to another and i think my code may be a little outdated due to it now not working

[php]

IPad: <? $sql="SELECT * FROM ipad_list order by asset asc"; $result=mysql_query($sql); while (($row=mysql_fetch_array($result)) { $id1=$row["asset"]; $options1.="".$id1.''; } ?> Choose One <? echo $options1 ?> [/php]

But on my new server i get add behaviour and this appear on my screen instead of the populated dropdown.

“.$id1.”; }

I am assuming this might be down to the php version. i was sure both were on version 5 !

Can some please point me in the right direction for fixing this ?

Your code is out of date. mysql_ functions have been removed from the latest version.

There are large differences in versions 5. So, that really is of no help.

".$id1."; }

This EXACTLY is what appears in the select input? If so, you are not showing us the correct code.

Hi and thank you for reply.

The

“.$id1.”; }

Is what displays on my html page but perfect on my other server. Appreciate things change but as I do this myself my code doesn’t change as quickly and I have re learn again and then get told my code is old.

The excerpt of code I pasted is how I populate my drop down and if someone could show me what the difference is now I would be greatfull.

Thank you all for you help.

P

Well, Primax, Astonecipher is correct on your using deprecated code. The one main issue is your calls to
MySQL. This will be removed completely soon. It your server is your own computer, then, no issue there.
But, if you are using a real server, you need to move up to at the minimum MySQLi. This is extremely easy
to do! You just have to change the connection to your database and the calls to queries. When you call
other functions such as mysql_num_rows(), they still work as mysqli_num_rows(). It is easy to update to
the improved version. Later on learn PDO…

Now, the problem that I think you have is that the new server has stricter rules on escaping characters.
This is just a guess, but, have seen it before… You current line of code uses double-quotes, escaped
double-quotes and single quotes. It is like this:
$options1.="<OPTION VALUE="$id1">".$id1.’’;
Try this version and let us know if it works…
$options1.="".$id1."";
Just simpler in my opinion as it just has two single quotes between the double-quotes. Let us know…

Hi Ernie.

Thank you for the reply. Am getting frustrated with all this as i am learning all this myself as i go along and researching from the net and then finding out a few months later the code i am using no longer works !! Ugh…
thank you for the explanation, really help.
Appear i might have to go through my code and readdress alott of it which really hurts !
This is all private stuff only used in house which i am pleased about.

Will plod on !

Well, learning and being told to change your processes are always annoying! We seem to have to say it a
lot on this site. Mostly it is because those learning was steered to a site that knows less than they should.
This site is full of great programmers that are really here only to help and learn better ways to do their own
work. So, do not hesitate to ask anything you need.

I updated several of my old test sites to the improved version of MySQL and found it was so easy, that I think
you will not have problems with it. As in the code you posted, you just have to change the way you connect
to the database. This creates a pointer to the connection. Quite often it is just $conn. So, your one line of
MySQL : $result=mysql_query($sql); Would be : $result=mysqli_query($conn, $sql); Easy change.

You can change your code one page at a time. There is no need to change it all at once. If you have a
large number of pages, you probably have one connection string page. You can add in a second one that
uses the MySQLi version. Just name the connection variable a different name than the current one. Then,
upgrade one page at a time using the new version. Should be easy. The general layout for a MySQLi
connection is loosely like this:
// Variables for connecting to your database. These variable values come from your hosting account.
$hostname = “localhost”; // This depends on your server
$dbname = “zzz”;
$username = “zzz”;
$password = “zzz?”;
// Connecting to your database
$db_connect = mysqli_connect($hostname, $username, $password, $dbname);
// Check if connection was actually made
if (mysqli_connect_errno()) { echo "Failed to connect to the database system! Error: " . mysqli_connect_error(); }

You can skip the variables and just put the values into the connect() function if you want. Very similar to
your old connection to the database. The $db_connect was used to not be confused with the standard
$conn that you might be using…

Here is a nice tutorial on this that might help. Lots of info if you walk thru the “Next-Chapter” links…
http://www.w3schools.com/php/php_mysql_connect.asp
This also shows the PDO examples which are also quite easy and is more versatile for you to learn in the
future as this is the way PHP is heading. (OR, actually already there…)

Hope this helps!

WOW Ernie. Cannot thank you enough for that !!

Amazing, i was just wondering where to start as this has messed up alot of what i originaly done.

Oh well best start !!

Thank you again.

P

You are very welcome… Do not hesitate to ask any further questions. I think you should remember that
anything can be done in programming if you keep calm, learn how to do it, think out your logic and then just
program program program… LOL

Let us know when you get stuck again…

Sponsor our Newsletter | Privacy Policy | Terms of Service