AdRock Posted August 12, 2006 Share Posted August 12, 2006 I have a form for my members where they can update their details such as their name and email.The problem I'm having is checking if the email address has been changed before submitting the form and if it has been changed to make sure the email address doesn't already exist in the database.I want it to be able to update just the name and keep the email address or just be able to update the email addressThis is how far I have got but have got the compare email address wrong[code]<?session_start();session_register("session");if(!isset($session['userid'])){echo "<center><font face='Verdana' size='2' color=red>Sorry, Please login and use this page </font></center>";exit;}// This is displayed if all the fields are not filled in$empty_fields_message = "<p>Please go back and complete all the fields in the form.</p>Click <a class=\"two\" href=\"javascript:history.go(-1)\">here</a> to go back";// Convert to simple variables $first_name = stripslashes($_POST['first_name']); $last_name = stripslashes($_POST['last_name']);$email_address = stripslashes($_POST['email_address']);if (!isset($_POST['first_name'])) {?><h2>Update personal details!</h2><form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>"> <p class="style3"><label for="first_name" style="width:8em">First Name:</label> <input type="text" title="Please enter your first name" name="first_name" size="30" value="<? echo $_SESSION['firstname']; ?>"/></p> <p class="style3"><label for=last_name" style="width:8em">Second Name:</label> <input type="text" title="Please enter your last name" name="last_name" size="30" value="<? echo $_SESSION['lastname']; ?>"/></p> <p class="style3"><label for="email_address" style="width:8em">Email address:</label> <input type="text" title="Enter your email address" name="email_address" size="30" value="<? echo $_SESSION['emailaddress']; ?>"/></p> <p class="style3"><label title="Login"> <input type="submit" value="Update" style="margin-left:97px" class="submit-button"/></label></p></form><?php}elseif (empty($first_name) || empty($last_name) || empty($email_address)) { echo $empty_fields_message;}else {include 'includes/connection.php';if (strcmp( $email_address,$_SESSION['emailaddress'] ) !=0){ if(mysql_num_rows(mysql_query("SELECT email_address FROM users WHERE email_address = '$email_address'"))){ $msg=$msg."Your email address has already been used by another member in our database. Please submit a different Email address!!<BR>"; $status= "NOTOK";} }if($status<>"OK"){ echo "<font face='Verdana' size='2' color=red>$msg</font><br><input type='button' class='submit-button' value='Retry' onClick='javascript:history.go(-1)'>"; exit(); }[/code]Has anybody got any ideas how i could ignore the email address if the it matches the email in the database and if it is changed check for an existing email Quote Link to comment Share on other sites More sharing options...
AdRock Posted August 12, 2006 Author Share Posted August 12, 2006 I got this code to check if both the session email and the email text box match and returns the text box email but how do i check to see if the any of the name fileds have changed even if the email hasn't/[code]if (strcmp( $email_address,$_SESSION['emailaddress'] ) !=0){ echo $email_address; }else { echo "No changes made"; }}[/code] Quote Link to comment Share on other sites More sharing options...
onlyican Posted August 12, 2006 Share Posted August 12, 2006 checking something in the database[code]<?php$query = "SELECT * FROM table WHERE email = '".$email."'";$result = mysql_query($query);if(mysql_num_rows($result) == 0){echo "That is not in the database";}else{echo "The email address is in the database";}[/code] Quote Link to comment Share on other sites More sharing options...
AdRock Posted August 13, 2006 Author Share Posted August 13, 2006 Just another quick question......How do I select a field from the database and put it into a variable such as $idI want to get the id from a record and put it into a variable[code]$query = "SELECT * FROM users WHERE id = '".$_SESSION['userid']."'";$result = mysql_query($query);[/code] Quote Link to comment Share on other sites More sharing options...
corbin Posted August 13, 2006 Share Posted August 13, 2006 [code=php:0]$query = "SELECT * FROM users WHERE id = '".$_SESSION['userid']."'";$result = mysql_query($query);$id = mysql_fetch_assoc($result);$id = $id['id'];[/code] Quote Link to comment Share on other sites More sharing options...
onlyican Posted August 13, 2006 Share Posted August 13, 2006 [quote author=corbin link=topic=104014.msg414796#msg414796 date=1155433209][code=php:0]$query = "SELECT * FROM users WHERE id = '".$_SESSION['userid']."'";$result = mysql_query($query);$id = mysql_fetch_assoc($result);$id = $id['id'];[/code][/quote]no Exact[code=php:0]$query = "SELECT * FROM users WHERE id = '".$_SESSION['userid']."'";$result = mysql_query($query);while(row = mysql_fetch_assoc($result)){$id = $row['id'];}[/code] Quote Link to comment Share on other sites More sharing options...
AdRock Posted August 13, 2006 Author Share Posted August 13, 2006 I get this error message now Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/adrock/public_html/jack/edit_profile.php on line 49 Quote Link to comment Share on other sites More sharing options...
onlyican Posted August 13, 2006 Share Posted August 13, 2006 doecho mysql_error(); Quote Link to comment 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.