jimfog Posted April 2, 2013 Share Posted April 2, 2013 Let us suppose the username wants to change the e-mail he has given-which means updating the e-mail in the database. As I see one way to target the specific email of the specific user is the password And another is with the e-mail itself. IS my second statement correct? meaning targeting with a query the e-mail in order to update it the same time. Link to comment Share on other sites More sharing options...
justsomeguy Posted April 2, 2013 Share Posted April 2, 2013 You can use any unique column to identify the record to update. Link to comment Share on other sites More sharing options...
jimfog Posted April 2, 2013 Author Share Posted April 2, 2013 You can use any unique column to identify the record to update.to understand precisely what I am talking about here is the query-sorry for not showing it earlier:update busines_users,credentials set phone="'.$phone.'",email="'.$email.'" where busines_users.crID=credentials.crID and credentials.email="'.$email.'"' Just tell me your opinion if the above "makes sense"-focus on the email part. Link to comment Share on other sites More sharing options...
justsomeguy Posted April 2, 2013 Share Posted April 2, 2013 It makes sense to me, when you run it does it do what you expect? Is crID a primary key in that table? Link to comment Share on other sites More sharing options...
jimfog Posted April 3, 2013 Author Share Posted April 3, 2013 CrId is the primary key and what I get is very very weird. If in the form I update only the phone everythingis OK(I must stress hear that I am updating phone and email). But the weird begins when I go to update the e-mail.I get an empty array back-I need to say also that the results of the query are passed to an array-see the code to understand what I am talking about:Here is the update function: function update_contact_details($post,$email,$conn) { $updatecont=array(); $phone=mysql_real_escape_string($_POST['phone']); $email= mysql_real_escape_string($_POST['e-mail']); $conn->set_charset("utf8"); $result = $conn->query('update busines_users,credentials set phone="'.$phone.'",email="'.$email.'" where busines_users.crID=credentials.crID and credentials.email="'.$email.'"'); if (!$result){ throw new Exception('Aδυναμία σύνδεσης με την βάση.'); return false; } else{ $result1 = $conn->query('select busines_users.phone,credentials.email from busines_users,credentials where busines_users.crID=credentials.crID and credentials.email="'.$email.'"'); } if (!$result1){ throw new Exception('Aδυναμία σύνδεσης με την βάση.'); return false; } elseif( $result1->num_rows>0) { $updatect=$result1->fetch_object(); $updatecont['email']=$updatect->email; $updatecont['phone']=$updatect->phone; } return $updatecont; } And here is the code that calls the function: if(isset($_POST['contactupdt']))//this here means that the user just pressed the update/save form button-it has name="'contactupdt" { $updatecont=update_contact_details($_POST,$_SESSION['valid_user'],$conn); var_dump($updatecont); foreach ($updatecont as $contactdls) {echo $contactdls.'<br>';} } Thanks Link to comment Share on other sites More sharing options...
birbal Posted April 3, 2013 Share Posted April 3, 2013 If CrID is primary key , you can use that alone to determine unique user in your update query. In your code $email will be same for the new one and stored one (use in SET and WHERE) so it will not match if user is trying to change his email to other one. Link to comment Share on other sites More sharing options...
jimfog Posted April 4, 2013 Author Share Posted April 4, 2013 If CrID is primary key , you can use that alone to determine unique user in your update query.I must stress, that phone and e-mail are in different tables....in order to use crID to determine unique user I must reach to itwith the e-mail...(so using the e-mail is inevitable)unless you have something else in your mind In your code $email will be same for the new one and stored one (use in SET and WHERE) so it will not match if user is trying to change his email to other one. IS that the reason you think I was receiving an empty array? Link to comment Share on other sites More sharing options...
jimfog Posted April 4, 2013 Author Share Posted April 4, 2013 (edited) here is an alternative query I run: update busines_users,credentials set phone='6973999099',email='john@yahoo.com' where( select credentials.crID from credentials where email='foryou1911@gmail.com'); I get though the following error message: Error code 1093, SQL state HY000: You can't specify target table 'busines_users' for update in FROM clause I tried this also: update busines_users,credentials set phone="'.$phone.'",email="'.$emailnew.'" where busines_users.crID=credentials.crID and credentials.email='' '$email' "; Other errors appeared,worst than the case above-the whole page script is ruined. In general, it seems that I cannot update the e-mail and the same time use it i the where clause. Edited April 4, 2013 by jimfog Link to comment Share on other sites More sharing options...
jimfog Posted April 5, 2013 Author Share Posted April 5, 2013 Ι FOUND THE G......ERROR----I DID NOT UPDATE THE SESSION DURING THE E-MAIL CHANGE......YEAHHHHHHHHHHHHHHHHHHHHHH. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now