Join 307,116 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 2,005 people online right now. Registration is fast and FREE... Join Now!
I am having trouble with update profiles of users in my database. The validation is not working as well as updating the information supplied by the user. Below is the code that is to be implemented.
This is the Session Code; <?php session_start(); //session_register("session");
?>
This is the Check Code; <? 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 the PHP code; <? include "session.php"; include 'config.php'; include 'opendb.php'; $todo=$_POST['todo']; $password=$_POST['password']; $name=$_POST['name']; $email=$_POST['email']; $sex=$_POST['sex'];
require "check.php";
if(isset($todo) and $todo=="update-profile"){
$status = "OK"; $msg=""; if (strlen($name) < 5) { $msg=$msg."Your name must be more than 5 char length<BR>"; $status= "NOTOK";}
if($status<>"OK"){ // if validation failed echo "<font face='Verdana' size='2' color=red>$msg</font><br><input type='button' value='Retry' onClick='history.go(-1)'>"; }else{ // if all validations are passed. if(mysql_query("update plus_signup set password='password',email='$email',name='$name',sex='$sex' where userid='$_SESSION[userid]'")){ echo "<font face='Verdana' size='2' color=green>You have successfully updated your profile<br></font>"; }else{echo "<font face='Verdana' size='2' color=red>There is some problem in updating your profile. Please contact site admin<br></font>";} }}
require "bottom.php"; ?> <?php include 'closedb.php'; ?>
Please spot out the errors in this block of codes.
Thank You.
Admin Edit: Please use code tags when posting your code. Code tags are used like so =>
and it's always better to put quotes after the '=' and the value and second you just put a 'name' attribute not an 'id' you should always but both because sometimes it does not send and you cannot retrieve the data with only a 'name' attribute.
Thanks Danny, I just used the html code u corrected, I still got this error
"; $status= "NOTOK"; } if {($status<>"OK") // if validation failed echo " "; }else { // if all validations are passed. if(mysql_query("UPDATE plus_signup SET password='$password',email='$email',name='$name',sex='$sex' where userid='$_SESSION['userid']'")){ echo "You have successfully updated your profile "; }else{echo "There is some problem in updating your profile. Please contact site admin ";} } require "bottom.php"; ?>
this is the PHP code again. <? include "session.php"; include 'config.php'; include 'opendb.php'; $todo=$_POST['todo']; $password=$_POST['password']; $name=$_POST['name']; $email=$_POST['email']; $sex=$_POST['sex'];
require "check.php";
if(isset($todo) && $todo=="update-profile") { $status = "OK"; $msg=""; if (strlen($name) < 5) { $msg=$msg."Your name must be more than 5 char length<BR>"; $status= "NOTOK"; } if {($status<>"OK") // if validation failed echo "<font face='Verdana' size='2' color=red> <input type='button' value='Retry' onClick='history.go(-1)'>"; }else { // if all validations are passed. if(mysql_query("UPDATE plus_signup SET password='$password',email='$email',name='$name',sex='$sex' where userid='$_SESSION['userid']'")){ echo "<font face='Verdana' size='2' color=green>You have successfully updated your profile<br></font>"; }else{echo "<font face='Verdana' size='2' color=red>There is some problem in updating your profile. Please contact site admin<br></font>";} } require "bottom.php"; ?>
<? include "session.php"; include 'config.php'; include 'opendb.php'; $todo=$_POST['todo']; $password=$_POST['password']; $name=$_POST['name']; $email=$_POST['email']; $sex=$_POST['sex'];
require "check.php";
if(isset($todo) && $todo=="update-profile") { $status = "OK"; $msg=""; if (strlen($name) < 5) { $msg=$msg."Your name must be more than 5 char length<BR>"; $status= "NOTOK"; } if {($status<>"OK") // if validation failed echo "<font face='Verdana' size='2' color=red> <input type='button' value='Retry' onClick='history.go(-1)'>"; }else { // if all validations are passed. if(mysql_query("UPDATE plus_signup SET password='$password',email='$email',name='$name',sex='$sex' where userid='$_SESSION['userid']'")){ echo "<font face='Verdana' size='2' color=green>You have successfully updated your profile<br></font>"; }else{echo "<font face='Verdana' size='2' color=red>There is some problem in updating your profile. Please contact site admin<br></font>";} } require "bottom.php"; ?>
thanks! [/quote]
this is the Code
CODE
<? include "session.php"; include 'config.php'; include 'opendb.php'; $todo=$_POST['todo']; $password=$_POST['password']; $name=$_POST['name']; $email=$_POST['email']; $sex=$_POST['sex'];
require "check.php";
if(isset($todo) && $todo=="update-profile") { $status = "OK"; $msg=""; if (strlen($name) < 5) { $msg=$msg."Your name must be more than 5 char length<BR>"; $status= "NOTOK"; } if {($status<>"OK") // if validation failed echo "<font face='Verdana' size='2' color=red> <input type='button' value='Retry' onClick='history.go(-1)'>"; }else { // if all validations are passed. if(mysql_query("UPDATE plus_signup SET password='$password',email='$email',name='$name',sex='$sex' where userid='$_SESSION['userid']'")){ echo "<font face='Verdana' size='2' color=green>You have successfully updated your profile<br></font>"; }else{echo "<font face='Verdana' size='2' color=red>There is some problem in updating your profile. Please contact site admin<br></font>";} } require "bottom.php"; ?>
"; $status= "NOTOK"; } if($status == "OK") { echo " "; } else { // if all validations are passed. if(mysql_query("UPDATE plus_signup SET password='$password',email='$email',name='$name',sex='$sex' where userid='$_SESSION['userid']'")){ echo "You have successfully updated your profile "; }else{echo "There is some problem in updating your profile. Please contact site admin ";} } require "bottom.php"; ?>
if(mysql_query("UPDATE plus_signup SET password='$password',email='$email',name='$name',sex='$sex' where userid='$_SESSION['userid']'")){ echo "<font face='Verdana' size='2' color=green>You have successfully updated your profile<br></font>"; }else{echo "<font face='Verdana' size='2' color=red>There is some problem in updating your profile. Please contact site admin<br></font>";}
you shouldn't put the mysql_query in an if statement you should just put this:
CODE
mysql_query("UPDATE plus_signup SET password='$password',email='$email',name='$name',sex='$sex' where userid='$_SESSION['userid']'") or die("Error, The update did not work! : ".mysql_error());
so you should put a or die() at the end so then if it doesn't work it displays an error message so debugging is easier
I still found the same error on clicking the submit button without filling the form.
CODE
"; $status= "NOTOK"; } if($status == "OK") { echo " "; } else { // if all validations are passed. mysql_query("UPDATE plus_signup SET password='$password',email='$email',name='$name',sex='$sex' where userid='$_SESSION['userid']'") or die("Error, The update did not work! : ".mysql_error()); echo "You have successfully updated your profile "; }else{echo "There is some problem in updating your profile. Please contact site admin ";} } require "bottom.php"; ?>
.
Do you think there is something apart from the code I need to do on my server or database?
else { // if all validations are passed. if(mysql_query("UPDATE plus_signup SET password='$password',email='$email',name='$name',sex='$sex' where userid='$_SESSION['userid']'")){ echo "<font face='Verdana' size='2' color=green>You have successfully updated your profile<br></font>"; }else{echo "<font face='Verdana' size='2' color=red>There is some problem in updating your profile. Please contact site admin<br></font>";} }
instead of putting an else {} then an if inside of that else you can just put else if {} just to keep it cleaner!
and for that error make sure you don't have any open echo quotes it looks like thats what the problem is because it prints part of the code so it must be that check to see if you forgot a quote.
This is what I did and same error comes. This is frustrating!!!
CODE
<? include "session.php"; include 'config.php'; include 'opendb.php'; $todo=$_POST['todo']; $password=$_POST['password']; $name=$_POST['name']; $email=$_POST['email']; $sex=$_POST['sex'];
require "check.php";
if(isset($todo) && $todo=="update-profile") { $status = "OK"; $msg=""; if (strlen($name) < 5) { $msg=$msg."Your name must be more than 5 char length<BR>";} {$status= "NOTOK";} if($status == "OK") echo{ "<font face='Verdana' size='2' color=red> <input type='button' value='Retry' onClick='history.go(-1)'>";} elseif { $query= mysql_query("UPDATE plus_signup SET password='$password',email='$email',name='$name',sex='$sex' where userid='$_SESSION['userid']'") or die("Error, The update did not work! : ".mysql_error());} echo {"<font face='Verdana' size='2' color=green>You have successfully updated your profile<br></font>";} else{echo "<font face='Verdana' size='2' color=red>There is some problem in updating your profile. Please contact site admin<br></font>";} } require "bottom.php"; ?>
This is the error I get displaying on the web browser
CODE
";} // you can add email validation here if required. // The code for email validation is available at www.plus2net.com if($status<>"OK"){ // if validation failed echo "$msg "; }else{ // if all validations are passed. $query(mysql_query("update plus_signup set email='$email',name='$name',sex='$sex' where userid='$session[userid]'"));{ echo "You have successfully updated your profile "; }else{echo "There is some problem in updating your profile. Please contact site admin ";} }} echo "
Welcome $session[userid] Click here to logout | Change Password| Update Profile
"; ?>
This is the PHP code.
CODE
<? include "include/session.php"; include "include/config.php"; if(isset($todo) and $todo=="update-profile"){ // set the flags for validation and messages $status = "OK"; $msg=""; } // if name is less than 5 char then status is not ok if (strlen($name) < 5) { $msg=$msg."Your name must be more than 5 char length<BR>";}
if($status<>"OK"){ // if validation failed echo "<font face='Verdana' size='2' color=red>$msg</font><br><input type='button' value='Retry' onClick='history.go(-1)'>"; }else{ // if all validations are passed. $query(mysql_query("update plus_signup set email='$email',name='$name',sex='$sex' where userid='$session[userid]'"));{ echo "<font face='Verdana' size='2' color=green>You have successfully updated your profile<br></font>"; }else{echo "<font face='Verdana' size='2' color=red>There is some problem in updating your profile. Please contact site admin<br></font>";} }} echo "<center><font face='Verdana' size='2' ><br>Welcome $session[userid] Click <a href=logout.php>here to logout</a> | <a href=change-password.php>Change Password</a>| <a href=update-profile.php>Update Profile</a><br></center></font>";
}else{ $query(mysql_query("update plus_signup set password='$password',email='$email',name='$name',sex='$sex' where userid='$session[\'userid'\]'"));[b]{[/b]