July 7, 200917 yr Hey guys, I hope you are all well! I'm struggling with this one. Do you have any idea where I'm going wrong? <? session_start(); include('../db.php'); $code = $_GET['code']; $query = "SELECT * FROM vip WHERE state = '$code'" or die ('Error: '.mysql_error ());; $result = mysql_query($query) OR die(mysql_error()); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $_SESSION['vip_username'] = ($row['username']); $query = "INSERT INTO vip (state) VALUES ('1') WHERE state='$code'"; $result = mysql_query($query); $msg = "Congratulations! You are now a fully fledged member"; include('main.php'); } ?> Basically, a link gets sent to the users email address, they then click the link - it will look something like this example.com/FemG83rO4j7z8rk The code should then get checked in the database - when the code has been located it gets changed to "1" - which means they are an active member. It then registers their session variable and they get forwarded to the member area. But I am getting this error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:xampphtdocsycc2vipactivate.php on line 12 I am at a loss! - Any suggestions? Thanks guys, Nick
July 7, 200917 yr Hi Nick, I tried your code on my own database and got no errors ... are you sure that the contents of db.php aren't causing this problem?
July 7, 200917 yr Author Hmmmmm... nope - db.php is correct - it is called for in many other php files and functions perfectly. Strange...
July 7, 200917 yr Here's the code I ran that didn't have any error messages - does this cause errors for you? <? session_start(); include ("myown_db.php"); $code = "a constant I know exists in table"; $query = "SELECT * FROM vip WHERE state='$code'" or die ('Error: '.mysql_error ());; $result = mysql_query($query) OR die(mysql_error()); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "hi" ; } ?>
July 7, 200917 yr Here's the code I ran that didn't have any error messages - does this cause errors for you? <? session_start(); include ("myown_db.php"); $code = "a constant I know exists in table"; $query = "SELECT * FROM vip WHERE state='$code'" or die ('Error: '.mysql_error ());; $result = mysql_query($query) OR die(mysql_error()); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "hi" ; } ?> I had a similar project with some of my code, turns out it was my installation of PHP/mySQL that was at fault. Try it on another server if you can and rule out the error that way, I ended up putting in another method incase mysql_fetch_array wasn't available.
July 8, 200917 yr [/code] <? session_start(); include('../db.php'); $code = $_GET['code']; $query = "SELECT * FROM vip WHERE state = '$code'"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $_SESSION['vip_username'] = ($row['username']); $query = "INSERT INTO vip (state) VALUES ('1') WHERE state='$code'"; $result = mysql_query($query); $msg = "Congratulations! You are now a fully fledged member"; include('main.php'); } ?> [/code]
Create an account or sign in to comment