Hello, I have a problem with my script. Originally, it worked perfect on my old server which was running a PHP4 version. However, I had to transfer it to a new server which is running PHP5. I'm now experiencing problems with it, and I think it's down to the new version. When logging in, I'm getting: The corresponding PHP code lines for 46 are: $query1 = mysql_query("SELECT * FROM users WHERE username = '$username'"); while($info = mysql_fetch_array( $query1 )){ ... } PHP: And for 70 they are: if (!$info=mysql_fetch_array($query1)){ ... } PHP: Any help is greatly appreciated as this script is very important to me. Thanks, Lee.
If you changed the server, did your database go with you? Try replacing this. $query1 = mysql_query("SELECT * FROM users WHERE username = '$username'"); PHP: with this. $query1 = mysql_query("SELECT * FROM users WHERE username = '$username'") OR die( mysql_error() ); PHP:
I had to make a new DB but it's all configured to it within the code. I'll try what you advised, thanks EDIT: I just tried it, and it doesn't seem to have given any more output :/
I don't think this is an PHP5 issue... hm, try echoing the query string and see if it contains the expeced content. echo "SELECT * FROM users WHERE username = '$username'"; PHP: Also, you can try putting this at the top of your page. error_reporting(E_ALL); PHP:
brum, this warning is the result of trying to fetch a result from a query that returned zero results. not a php5 issue. as advised, add or die(mysql_error()); at the end of each of the mysql_ functions you're using including the connection to the db and the db selection, so that you can debug whats going on.
I added the or die(mysql_error()); and it didn't give any more information than it did before I used it :/
Oh my WORD! Sorry guys! I just realised how much of an idiot I've just been ... I have THREE folders on my webspace referring to cpcads, lol I've been using the wrong folder! I just uploaded to the right folder, and I get:
This means there's an non existant key in an array. This isn't necessarily a bad thing. The error_reporing just informs you of that. Does the MySQL part work after you changed the folder?
OK, here goes: <?php $logout = $_REQUEST['out']; if($logout == 1){ setcookie('username','',time()-5); setcookie('submit','',time()-5); setcookie('pass','',time()-5); ECHO "<META HTTP-EQUIV='Refresh' CONTENT='0;URL=account.php'>"; exit; } $dbh=mysql_connect ("localhost", "***", "***") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("***"); $promo = $_REQUEST['promo']; $marketer = $_REQUEST['marketer']; IF($promo == 0 && ($marketer == 0)){ setcookie('checkbox','none',time()+5); setcookie('submit','2'); ECHO "<META HTTP-EQUIV='Refresh' CONTENT='0;URL=account.php'>"; //ECHO "Didn't select one account"; }ELSE{ } IF($promo == 1 && ($marketer == 1)){ setcookie('checkbox','both',time()+5); setcookie('submit','2'); ECHO "<META HTTP-EQUIV='Refresh' CONTENT='0;URL=account.php'>"; // ECHO "Selected both accounts"; }ELSE{ } $username = $_REQUEST['username']; $password = $_REQUEST['password']; IF($promo == 1){ //echo "Promo == 1"; //echo "Username is $username"; //echo "<br>password is $password"; // now check $query1 = mysql_query("SELECT * FROM users WHERE username = '$username'"); while($info = mysql_fetch_array( $query1 )){ //echo $info['username']; //setcookie('submit','2'); if ($password != $info['password']){ //Wrong password, send back //echo "wrong pass entered"; setcookie('pass','2',time()+5); setcookie('submit','2'); ECHO "<META HTTP-EQUIV='Refresh' CONTENT='0;URL=account.php'>"; }ELSE{ //Right! send back //echo "username and pass OK"; setcookie('submit','2'); setcookie('username',"$username"); setcookie('acctype',"<b>P</b>romo"); ECHO "<META HTTP-EQUIV='Refresh' CONTENT='0;URL=account.php'>"; exit; } } if (!$info=mysql_fetch_array($query1)){ //echo "Username not found"; setcookie('pass','2',time()+5); setcookie('username','',time()-5); setcookie('submit','2'); ECHO "<META HTTP-EQUIV='Refresh' CONTENT='0;URL=account.php?user=2'>"; } } IF($marketer == 1 && ($promo == 0)){ // now check $query1 = mysql_query("SELECT * FROM users2 WHERE username = '$username'"); while($info = mysql_fetch_array( $query1 )){ //$result = mysql_query($query1); //$exist=mysql_num_rows($result); setcookie('submit','2'); $ppoints = $info['points']; $ppused = $info['pused']; setcookie('points',"$ppoints"); setcookie('pused',"$ppused"); if ($password != $info['password']){ //Wrong password, send back setcookie('pass','2',time()+5); ECHO "<META HTTP-EQUIV='Refresh' CONTENT='0;URL='account.php'>"; exit; } //Right! send back setcookie('username',"$username"); setcookie('acctype',"<b>M</b>arketer"); ECHO "<META HTTP-EQUIV='Refresh' CONTENT='0;URL=account.php'>"; exit; } if (!$info=mysql_fetch_array($query1)){ //echo "Username not found"; setcookie('pass','2',time()+5); setcookie('username','',time()-5); setcookie('submit','2'); ECHO "<META HTTP-EQUIV='Refresh' CONTENT='0;URL=account.php?user=2'>"; } } ?> PHP: P.S. Hope there aren't any rival PPC companies watching this thread
I would remove the single quotes from around the variables in the SQL queries. The single quotes can have the effect of literalizing the query so that MySql is looking for $username instead of the "bob". See if that does the trick.
I tested a version of the parts of your script which are giving you a problem on a local database. I changed the minimum needed to make it work -- leaving the code intact. I did not have a problem with it. I am using PHP 5.1.1 with Zend 2.1.0 So I tested on a second database and I was able to generate the same errors because the user did not have the privileges needed to access the database. Is this the problem?
Hmm interesting. Thanks for your experimenting I'll have a look.. I'll make another user with full privileges and replace it with the old one in my code, and see if that works. EDIT: Grrr still doesn't work and I've doubled checked the name of the DB, username and password. Hmm..
This is the worst part of debugging. In you situation, I would do the following. Write a very small routine to check database access. From the code we know the user is able to access MySql. This is because it is not dieing with a failed access to MySql. I would do a redundant check to be certain I granted that user full access to the specific database. I would pick a table and with a simple query, see if I can access that table and display contents from a column. I normally do this at the command line because it is much faster than using a browser to test. The error codes are the same. I also capture and print row counts to the screen to help verify that it is working. I see that you were doing something similar. If that works, I would then try the query which is giving me grief, pre-setting tthe values in the test script. If that works, I would try it from the web. If that fails, I would make sure all error settings are turned on and direct them to a separate file. Those errors may give us a clue as to what is the issue between your web servers, PHP, and MySql. I am certain you have tried this, but sometimes stepping through once more reveals the problem. This is especially mysterious because the code worked under PHP 4.x. I do encounter problems in running other people's scripts under PHP 5.x because it is stricter than 4.x, but it looks like you follow good coding style.