ProdSawax Posted July 16, 2013 Share Posted July 16, 2013 Hello, I have download a 'sign up email login form' on the web, the process works (email confirmation), but when after signed i want to echo/print the username I got errors. Here my code (at bellow 'echo 'username'': <?phpsession_start();include_once 'inc/php/config.php';include_once 'inc/php/functions.php';error_reporting(E_ALL);ini_set( 'display_errors','1');include 'inc/elements/signed.php';?><?php//setup some variables$action = array();$action['result'] = null;//check if the $_GET variables are present //quick/simple validationif(empty($_GET['email']) || empty($_GET['key'])){ $action['result'] = 'error'; $action['text'] = 'We are missing variables. Please double check your email.'; } if($action['result'] != 'error'){ //cleanup the variables $email = mysql_real_escape_string($_GET['email']); $key = mysql_real_escape_string($_GET['key']); //check if the key is in the database $check_key = mysql_query("SELECT * FROM `confirm` WHERE `email` = '$email' AND `key` = '$key' LIMIT 1") or die(mysql_error()); if(mysql_num_rows($check_key) != 0){ //get the confirm info $confirm_info = mysql_fetch_assoc($check_key); //confirm the email and update the users database $update_users = mysql_query("UPDATE `users` SET `active` = 1 WHERE `id` = '$confirm_info[userid]' LIMIT 1") or die(mysql_error()); //delete the confirm row $delete = mysql_query("DELETE FROM `confirm` WHERE `id` = '$confirm_info[id]' LIMIT 1") or die(mysql_error()); if($update_users){ $action['result'] = 'success'; $action['text'] = 'User has been confirmed. Thank-You!'; }else{ $action['result'] = 'error'; $action['text'] = 'The user could not be updated Reason: '.mysql_error();; } }else{ $action['result'] = 'error'; $action['text'] = 'The key and email is not in our database.'; }}?><?=show_errors($action); ?><?phpinclude 'hotel/reception.php'; echo "Welcome 'username'"; ?><?phpinclude 'inc/elements/footer2in.php'; ?>confirm11.phpconfirm11.phpconfirm11.phpconfirm11.php Quote Link to comment https://forums.phpfreaks.com/topic/280210-php-mysql-html-echo-username-problem/ Share on other sites More sharing options...
a246530 Posted July 30, 2013 Share Posted July 30, 2013 (edited) To accomplish this i set the username as a session variable (mostly because i had it display on all pages at the top right so the user could verify it was them as well as change any settings for their account). I am not sure if this is what you would want to do, but seeing as you already have a session going it seems like the easiest approach. I had a box when the user signs in for their username and literally just posted it to session username. $_SESSION['username']=$_POST['username']; As far as your line, echo "Welcome 'username'" is concerned, You arent actually telling it to echo the username you would have for that person, but rather just username itself. Edited July 30, 2013 by a246530 Quote Link to comment https://forums.phpfreaks.com/topic/280210-php-mysql-html-echo-username-problem/#findComment-1442648 Share on other sites More sharing options...
Muddy_Funster Posted July 30, 2013 Share Posted July 30, 2013 A couple of things RE the last post, first, the form method being used here is GET, not POST and second, the username is not part of the form data at all, so your idea won't work at all, even after changing to GET. Now to the OP. What you will actualy need to do is echo the information brought back from the database by changing the line pointed out by the last post to the following, assuming the field in the database that is hoding the username info is called username (if not change accordingly) is echo "Welcome '{$confirm_info['username']}'"; That said, check your database to see that the update and delete queries are doing exactly what you expect them to, I would be supprised if they are, I also seriously urge you to never use select * for production scripts. And another thing - you need to stop breaking in and out of PHP all over the place when it is totaly unnescacery to do so. Quote Link to comment https://forums.phpfreaks.com/topic/280210-php-mysql-html-echo-username-problem/#findComment-1442653 Share on other sites More sharing options...
ProdSawax Posted August 2, 2013 Author Share Posted August 2, 2013 Thank you both. I'm newby too. Muddy_Funster had right.In the dB, I'm using these 2 tables: users(id, username, password, email, active) and confirm(id, userid,key,email). When I echo: echo "Welcome '{$confirm_info['userid']}'"; I got well "Welcome 133" and 133 corresponding well to new user. So now, I need to go one step further and to query 'replace {$confirm_info['userid']} by {$users_info['username']} ? In order to get: "welcome UserVerynice" . Quote Link to comment https://forums.phpfreaks.com/topic/280210-php-mysql-html-echo-username-problem/#findComment-1443206 Share on other sites More sharing options...
ProdSawax Posted August 2, 2013 Author Share Posted August 2, 2013 Had tried (doesn't work) this: $users_info = mysql_query("SELECT users.id, users.username, confirm.userid WHERE `$users_info[id]` = '$confirm_info[userid]' LIMIT 1") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/280210-php-mysql-html-echo-username-problem/#findComment-1443211 Share on other sites More sharing options...
ProdSawax Posted August 2, 2013 Author Share Posted August 2, 2013 Precision users.id = confirm.userid : same value I tried also without success: $users_info = mysql_query("SELECT 'username' FROM `users` WHERE `id` = '$confirm_info[userid]' LIMIT 1") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/280210-php-mysql-html-echo-username-problem/#findComment-1443216 Share on other sites More sharing options...
Muddy_Funster Posted August 2, 2013 Share Posted August 2, 2013 Had tried (doesn't work) this: $users_info = mysql_query("SELECT users.id, users.username, confirm.userid WHERE `$users_info[id]` = '$confirm_info[userid]' LIMIT 1") or die(mysql_error()); You completly missed out the FROM clause here, and you only need to prefix the field name with the tablename if the same field exists in multiple tables that you are selecting from. What you want should be someting like this : $users_info = mysql_query("SELECT users.id, users.username FROM users INNER JOIN confirm ON users.id = confirm.userid WHERE `email` = '$email' AND `key` = '$key' LIMIT 1") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/280210-php-mysql-html-echo-username-problem/#findComment-1443250 Share on other sites More sharing options...
ProdSawax Posted August 2, 2013 Author Share Posted August 2, 2013 Thank you Muddy_Funster On progress, only one error: 'Column 'email' in where clause is ambiguous' (and doesn't display "welcome Username") Quote Link to comment https://forums.phpfreaks.com/topic/280210-php-mysql-html-echo-username-problem/#findComment-1443263 Share on other sites More sharing options...
ProdSawax Posted August 2, 2013 Author Share Posted August 2, 2013 I trying this (without success): $users_info = mysql_query("SELECT users.id, users.username, users.email FROM users INNER JOIN confirm ON users.id = confirm.userid WHERE `email` = '$email' AND `key` = '$key' LIMIT 1") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/280210-php-mysql-html-echo-username-problem/#findComment-1443267 Share on other sites More sharing options...
ProdSawax Posted August 2, 2013 Author Share Posted August 2, 2013 My last try (didn't echo any error, but didn't echo the 'username' too) : $users_info = mysql_query("SELECT users.id, users.username FROM users INNER JOIN confirm ON users.id = confirm.userid WHERE users.id = confirm.userid LIMIT 1") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/280210-php-mysql-html-echo-username-problem/#findComment-1443272 Share on other sites More sharing options...
ProdSawax Posted August 2, 2013 Author Share Posted August 2, 2013 FYI /When I made: print_r($users_info); I got the error: Resource id #7 Quote Link to comment https://forums.phpfreaks.com/topic/280210-php-mysql-html-echo-username-problem/#findComment-1443277 Share on other sites More sharing options...
ProdSawax Posted August 2, 2013 Author Share Posted August 2, 2013 I'm stock at error: Column 'email' in where clause is ambiguous $users_info = mysql_query("SELECT users.id, users.username FROM users INNER JOIN confirm ON users.id = confirm.userid WHERE `email` = '$email' AND `key` = '$key' LIMIT 1") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/280210-php-mysql-html-echo-username-problem/#findComment-1443279 Share on other sites More sharing options...
ProdSawax Posted August 2, 2013 Author Share Posted August 2, 2013 When I tried without the WHERE $users_info = mysql_query("SELECT users.id, users.username FROM users INNER JOIN confirm ON users.id = confirm.userid") or die(mysql_error()); I got this : 'Welcome Resource id #7' Quote Link to comment https://forums.phpfreaks.com/topic/280210-php-mysql-html-echo-username-problem/#findComment-1443281 Share on other sites More sharing options...
DavidAM Posted August 2, 2013 Share Posted August 2, 2013 I'm stock at error: Column 'email' in where clause is ambiguous $users_info = mysql_query("SELECT users.id, users.username FROM users INNER JOIN confirm ON users.id = confirm.userid WHERE `email` = '$email' AND `key` = '$key' LIMIT 1") or die(mysql_error()); Apparently the "email" column exists in both tables. You will need to qualify it in the WHERE clause with the name of the table you want to compare it to: ... WHERE users.email = '$email' -- OR ... WHERE confirm.email = '$eamil' FYI /When I made: print_r($users_info); I got the error: Resource id #7 $users_info is the reqult of a mysql_query call. It is a resource for accessing the data. You need to use mysql_fetch_assoc or one of its siblings to actually get the data. Quote Link to comment https://forums.phpfreaks.com/topic/280210-php-mysql-html-echo-username-problem/#findComment-1443283 Share on other sites More sharing options...
Solution ProdSawax Posted August 2, 2013 Author Solution Share Posted August 2, 2013 Thank you so much Guru,I replaced by:$users_info = mysql_query("SELECT users.id, users.username FROM users INNER JOIN confirm ON users.id = confirm.userid WHERE confirm.email = '$email' AND `key` = '$key' LIMIT 1") or die(mysql_error());with later in code:<?phpwhile($resultat = mysql_fetch_assoc($users_info)){ print_r($resulat);echo $resultat['username'];}?>and that's work !Have a nice day Guru! Quote Link to comment https://forums.phpfreaks.com/topic/280210-php-mysql-html-echo-username-problem/#findComment-1443288 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.