fife Posted July 28, 2010 Share Posted July 28, 2010 Hello. Basically I have created a form that you fill in and an email gets sent to your in box and you have an access_level of 1. Within this email there is one field. A validation_id. Now what im trying to do is when you click this link it opens the webpage and updates your access_level to 2. I have wrote my query and array and i can see exactly which bit is wrong. Its where i have validation_id= $validation_id") Now its not working and I can see the error. Problem is im too new at this to understand why its wrong and how to fix it can anyone help? Here is the rest of the code. Also could you please explain? I would really like to understand it before i move any further. p.s. I have already selected my database in the included file <? include('database_name'); session_start(); $validation_id =$_GET['validation_id']; $FullRec__query=sprintf("SELECT * FROM Members WHERE validation_id= $validation_id"); $FullRec = mysql_query($FullRec__query, $database name) or die(mysql_error()); $FullRecArray = mysql_fetch_array($FullRec); $UdateAccessQuery = sprintf("UPDATE Members SET access_level = '2' WHERE validation_id = $validation_id"); mysql_query($UdateAccessQuery, $database_name) or die(mysql_error()); ?> Quote Link to comment https://forums.phpfreaks.com/topic/209135-update-access-level/ Share on other sites More sharing options...
lemmin Posted July 28, 2010 Share Posted July 28, 2010 What is the error that is output to you? I'm guessing your $_GET variable doesn't actually contain a validation_id, or it isn't what you expect. What does the url look like from the email? Quote Link to comment https://forums.phpfreaks.com/topic/209135-update-access-level/#findComment-1092231 Share on other sites More sharing options...
fife Posted July 28, 2010 Author Share Posted July 28, 2010 Warning: sprintf() [function.sprintf]: Too few arguments in /home/site/validation_members.php on line 6 Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/validation_members.php on line 8 Quote Link to comment https://forums.phpfreaks.com/topic/209135-update-access-level/#findComment-1092233 Share on other sites More sharing options...
lemmin Posted July 28, 2010 Share Posted July 28, 2010 Try it like this: $FullRec__query=sprintf("SELECT * FROM Members WHERE validation_id= %s", $validation_id); and $UdateAccessQuery = sprintf("UPDATE Members SET access_level = '2' WHERE validation_id = %s", $validation_id); Quote Link to comment https://forums.phpfreaks.com/topic/209135-update-access-level/#findComment-1092237 Share on other sites More sharing options...
fife Posted July 28, 2010 Author Share Posted July 28, 2010 Ok made the change which i think I understand. Not too sure what %s does but yes it makes sense how ever. this now popped up which I definately dont understand! Parse error: syntax error, unexpected T_VARIABLE in /home/validation_members.php on line 12 Quote Link to comment https://forums.phpfreaks.com/topic/209135-update-access-level/#findComment-1092240 Share on other sites More sharing options...
lemmin Posted July 28, 2010 Share Posted July 28, 2010 That is just a normal syntax error. It means you are likely missing a semi-colon or quotation somewhere. Could you post your new code indicating which is line 12? The %s is a format indicator. It tells the function to treat the variable as a string. Here is the documentation: http://us.php.net/manual/en/function.sprintf.php Quote Link to comment https://forums.phpfreaks.com/topic/209135-update-access-level/#findComment-1092246 Share on other sites More sharing options...
fife Posted July 28, 2010 Author Share Posted July 28, 2010 Cool ok I will have a read of that thank you very much. I fixed the code on line 12 i was missing a , but now I get a new error. I will post the error and all of the php on the page again. Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/validation_members.php on line 8 <? include('../database name here); session_start(); $validation_id =$_GET['validation_id']; $FullRec__query=sprintf("SELECT * FROM Members WHERE validation_id= %s", $validation_id); $FullRec = mysql_query($FullRec__query, $database name here) or die(mysql_error()); $FullRecArray = mysql_fetch_array($FullRec); $UdateAccessQuery = sprintf("UPDATE Members SET access_level = '2' WHERE validation_id =%s", $validation_id); mysql_query($UdateAccessQuery, $database name here) or die(mysql_error()); ?> [code=php:0] Quote Link to comment https://forums.phpfreaks.com/topic/209135-update-access-level/#findComment-1092254 Share on other sites More sharing options...
lemmin Posted July 28, 2010 Share Posted July 28, 2010 I'm assuming that you are replacing what is actually written for "$database name here." That is where the error is occurring. Make sure that the variable you use there is the same as the one that is set to your mysql_connect() function. If you are only connecting to one database, you can just remove it completely because it will default to the last connection made. Quote Link to comment https://forums.phpfreaks.com/topic/209135-update-access-level/#findComment-1092257 Share on other sites More sharing options...
fife Posted July 28, 2010 Author Share Posted July 28, 2010 yes I am definately connecting to the right database name. Here is my error again Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/sites/yourarena.co.uk/public_html/joining/validation_members.php and the code with the included page at the top <? include('database name here'); session_start(); //this section is included in the include above $hostname = ""; $database = ""; $username = ""; $password = ""; $YA1 = mysql_pconnect($hostname, $username, $password) or trigger_error(mysql_error(),E_USER_ERROR); mysql_select_db($databasecname here); //this is on the validation page its self $validation_id =$_GET['validation_id']; $FullRec__query=sprintf("SELECT * FROM Members WHERE validation_id= %s", $validation_id); $FullRec = mysql_query($FullRec__query, $database name here) or die(mysql_error()); $FullRecArray = mysql_fetch_array($FullRec); $UdateAccessQuery = sprintf("UPDATE Members SET access_level = '2' WHERE validation_id =%s", $validation_id); mysql_query($UdateAccessQuery, $database name here) or die(mysql_error()); ?> Quote Link to comment https://forums.phpfreaks.com/topic/209135-update-access-level/#findComment-1092262 Share on other sites More sharing options...
lemmin Posted July 28, 2010 Share Posted July 28, 2010 Try removing the second argument from your mysql_query() functions. They are optional if you are only connecting to one database. Quote Link to comment https://forums.phpfreaks.com/topic/209135-update-access-level/#findComment-1092275 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.