Just changed from hosting company, now code not working

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lmejia_hn
Forum Newbie
Posts: 2
Joined: Tue Mar 20, 2007 9:49 am

Just changed from hosting company, now code not working

Post by lmejia_hn »

Hi all, this is my first post and fairly new to PHP.

Im migrating my applications to another hosting provider, already have my website running, so connections to the DB are working OK. But it seems that certain code is not comfortable with, but at the same time, works ok on my actual server:

URL--> http://www.mysite.com/list.php?idc=6

Code: Select all

<?
  $conn= @mysql_connect("localhost","$user","$pwd");
  $db= mysql_select_db($db_name,$conn) or die("Cant connect.");
  $sql="SELECT name, picture FROM categories WHERE id_category=$idc";
  print $sql;
  $result=mysql_query($sql,$conn) or die ('Error '.mysql_error());
?>
The result is the following message:
SELECT name, picture FROM categories WHERE id_category=Error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

It seems that is an issue with the quotes (single/double), because the result is not displaying the value of the variable idc. Both servers (actual and new) share the same configuration:

Apache 2.0
PHP 4.3.9
mySQL 4.1.20

I tried to search the forum and Google and it seems that some people write the code like this:
$sql="SELECT name, picture FROM categories WHERE id_category='$idc' ";

Any idea?, maybe a setting that I dont know?. Sorry if this is a dumb question ;)

Thx

Leo
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

it's a register globals issue.

your new host has it turned OFF which is good.

you'll need to use the $_GET[] array to reference your URL params now.
mentor
Forum Contributor
Posts: 100
Joined: Sun Mar 11, 2007 11:10 am
Location: Pakistan

Post by mentor »

Make a .php file containing this code only

Code: Select all

<?php
phpinfo();
?>
And upload this file to your new server and open in the browser. In the page output find the value for 'register_globals'. If it is off, then you can do one solve this problem in the following ways

1. Turn on the register_globals (it will not be possible because you are on a shared web server)
2. Use $_GET as Burrito suggessted.
3. put extrac($_REQUEST) on the top of every .php file.
4. Turn on register_globals using .htaccess as below
make a text file with the name .htaccess and put the following code in it and upload to the root folder
php_flag register_globals on
If you already have a .htaccess file in your website, then simply put this code in it.

More about Register Globals
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

DO NOT TURN ON REGISTER GLOBALS.

It is bad advice and you can pay a terrible price by doing so. Recode your app to use the superglobal array. NEVER, EVER turn on register globals, not matter what others tell you. It is just plain silly, bad advice.
lmejia_hn
Forum Newbie
Posts: 2
Joined: Tue Mar 20, 2007 9:49 am

Post by lmejia_hn »

Thanks for the prompt answers guys. My issue here is that I have 3 websites using the normal reference $variable, so if I keep that OFF the sites will not work. I have been reading about the risks, and yes, I will recode my app in order to have them OFF.

Thx

Leo
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Good man. I know it is a lot of work recoding, but it is a lot less work then explaining to your clients or users that your insecure code in conjunction with your insecure setup resulted in a compromise of your now insecure data... :wink:
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Post Reply