little help? :)
here is the error
Warning: Supplied argument is not a valid MySQL result resource in /www/welcometovernon/coupons/update.php on line 84
here is that line
$result =mysql_query("SELECT * FROM coupons WHERE username=$username",$db);
Im already connect to the database and everything.. the table is called coupon.. username is a variable sent through a form, and is also the name of one of the collums in the database
You say your TABLE is "coupon" but your query is selecting from "coupons".
i mean its called coupons
I just looked at my scripts to confirm. I always use single quotes around my variables:
"SELECT * FROM coupons WHERE username='$username'"
If that doesn't clear it up the only other thing could be your link to the connection - $db.
Make sure the link is still valid and you have not reused that variable.
BTW. Once you connect to your db you do not need to use the link in your query.
$result = mysql_query($query);
$result = mysql_query($query,$db);
will both work.
I write my code like below because I find that I'm always having to debug my sql statements to find out where I have made a silly mistake. As Randman suggests, use single quotes around $username. Also, check that username holds a value and is not just an empty string.
$sql = "SELECT * FROM coupons WHERE username='$username'"
echo $sql; // print out the sql string for debugging purposes.
I'm glad you said that. I always echo my sql's during development cycle. In fact, after each process and periodically through the program I echo all my variables. Makes it real easy to debug.
It's an old programmer's trick. Back in the old days when they had keypunch departments and programs were carried in boxes of cards, it might take several days before your program could be executed. Variable checking could cut weeks and months off the development cycle.
Gosh, how did we do it then. No wonder I have gray hair. I love programming today.