White_Lily Posted January 23, 2013 Share Posted January 23, 2013 Hi, I have ahd a slight problem with the deprecation of mysql_*() functions, and so are swapping them for mysqli_*() functions, how I have come across an error which states that $connect is undefined. <?php $GLOBALS["host"] = "localhost"; $GLOBALS["user"] = "web113-social-1"; $GLOBALS["pass"] = "********"; $GLOBALS["database"] = "***************"; $connect = mysqli_connect($GLOBALS["host"], $GLOBALS["user"], $GLOBALS["pass"], $GLOBALS["database"]); ?> I have compared this against php.net's examples, and this code looks almost exact. I dont know what the problem is. Any help would be appreciated. - Lily Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 23, 2013 Share Posted January 23, 2013 (edited) Why are you putting sensitive information into the globals array? Use constants. The code you've posted would not produce an error about an undefined variable. You're also not checking for errors. Edited January 23, 2013 by Jessica Quote Link to comment Share on other sites More sharing options...
White_Lily Posted January 23, 2013 Author Share Posted January 23, 2013 Notice: Undefined variable: connect in/home/sites/janedealsart.co.uk/public_html/social/inc/functions.php on line 17 Actually Jessica - yes it is producing an undefined variable error. Quote Link to comment Share on other sites More sharing options...
White_Lily Posted January 23, 2013 Author Share Posted January 23, 2013 (edited) Okay, so I looked back at php.net to see what error checking they use... <?php $connect = mysqli_connect("localhost", "username", "password", "database"); if(!$connect){ die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error()); } echo 'Success... ' . mysqli_get_host_info($connect) . "\n"; ?> Guess what... Still getting an Undefined $connect error... dispite manually typing in the connection settings. Edited January 23, 2013 by White_Lily Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 23, 2013 Share Posted January 23, 2013 Line 17... So there's a whole bunch of code you didn't post. Like I said - the code YOU ORIGINALLY POSTED could not produce that error. Quote Link to comment Share on other sites More sharing options...
White_Lily Posted January 23, 2013 Author Share Posted January 23, 2013 I figured it out, it was the $connect variable being undefined, how I don't know, but all I did was re-type the connection details re-uploaded the file, and the error disappeared and data from the database showed. Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 23, 2013 Share Posted January 23, 2013 *smh* Whatever. 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.