- This topic is empty.
-
AuthorPosts
-
December 31, 2013 at 7:36 am #159347MBMParticipant
The array is named $message not errMessage. I renamed it errMessage just in case. I must have made a type somewhere as although I still don’t get an error message in the address bar I see :
message=Array
December 31, 2013 at 2:28 pm #159407__ParticipantThe array is named $message not errMessage. I renamed it errMessage just in case.
No, you’re right:
$message
is correct. My mistake. I’m not sure what’s going on.Try this: under
if( $errMessage ){
add this line and see what it prints:
var_dump( $errMessage ); exit;
December 31, 2013 at 4:40 pm #159419MBMParticipantif($formValue['forename']==""){ $message [] = "Please enter your forename" ; var_dump( $message ); exit; header("Location: register.php?message=$message");
No data entered :
array(1) { [0]=> string(23) "Please enter a forename" }
Forename entered, no other data entered :
array(1) { [0]=> string(22) "Please enter a surname" }
Forename & surname entered, no other data entered :
array(1) { [0]=> string(23) "Please enter a username" }
etc, etc
Two of the strings have the same value (23). Is that the problem?
And the address bar reads :
register.php?CreateRecord=1
Which is from :
<form action="register.php?CreateRecord=1" method="post" enctype="multipart/form-data" name="form1" id="registerform">
December 31, 2013 at 7:05 pm #159422__ParticipantTwo of the strings have the same value (23). Is that the problem?
No;
23
is the number of characters in the string, not the value.array(1)
To clarify, you only get one element in the array, even when you enter no data?
What version of PHP are you running?
Would you also post the complete current script you are using (perhaps make a gist on github)?
December 31, 2013 at 7:52 pm #159423MBMParticipantCorrect. Only one element is displayed regardless of how many of the fields are filled in.
PHP Version 5.3.3.
The registration form php (content removed) :
https://gist.github.com/gyprosetti/f9606ea721650f4756be
common.php :
https://gist.github.com/gyprosetti/715e2344708256acaf23
I removed the links to my css and uploaded and test that, just in case, but it didn’t make a difference.
December 31, 2013 at 9:24 pm #159424__ParticipantYou’re still putting a
header
call with every test. Once you send that Location header, the client (browser) abandons you script in favor of the new location. It will never see anything after the first one.Compare this to the example I posted, where the Location header is sent only after all of the checks have been completed.
January 1, 2014 at 9:58 am #159443MBMParticipantThere’s something wrong with my syntax :
if(isset($_POST['Submit'])){ if($formValue['forename']==""){ $errmessage[] = "Please enter a forename" ; }elseif($formValue['surname']==""){ $errmessage[] = "Please enter a surname" ; }elseif($formValue['username']==""){ $errmessage[] = "Please enter a username" ; }elseif($formValue['password']==""){ $errmessage[] = "Please enter a password" ; }elseif($formValue['email']==""){ $errmessage[] = "Please enter your email address" ; if( $errmessage ){ $message = implode( "<br>",$errmessage ); header( "Location: register2.php?message=$message" ); exit; } }else{ DBConnect();
January 1, 2014 at 8:49 pm #159460__ParticipantIf you indent your code, it will be much easier to pick out syntax and logical errors.
Beyond that, however, you should be using a code editor that can take care of basics like this for you. I use Komodo, which is free (as in beer) and runs on Linux/Mac/Windows. It’s an amazing piece of software. (If you’re serious about coding, the full IDE is well worth its price as well. Unpaid testimonial.)
<?php if(isset($_POST['Submit'])){ if($formValue['forename']==""){ $errmessage[] = "Please enter a forename" ; } elseif($formValue['surname']==""){ $errmessage[] = "Please enter a surname" ; } elseif($formValue['username']==""){ $errmessage[] = "Please enter a username" ; } elseif($formValue['password']==""){ $errmessage[] = "Please enter a password" ; } elseif($formValue['email']==""){ $errmessage[] = "Please enter your email address" ; if( $errmessage ){ $message = implode( "<br>",$errmessage ); header( "Location: register2.php?message=$message" ); exit; } }else{ DBConnect();
See it? You’re missing at least two closing brackets, and I suspect your
if( $errmessage )
is not where you meant it to be. There’s a few other things, as well.<?php if(isset($_POST['Submit'])){ if($formValue['forename']==""){ $errmessage[] = "Please enter a forename" ; } // use if(), not elseif(). // elseif() means you'll only deal with one error at a time. if($formValue['surname']==""){ $errmessage[] = "Please enter a surname" ; } if($formValue['username']==""){ $errmessage[] = "Please enter a username" ; } if($formValue['password']==""){ $errmessage[] = "Please enter a password" ; } if($formValue['email']==""){ $errmessage[] = "Please enter your email address" ; // I think one of your closing brackets was meant to go here: } if( $errmessage ){ $message = implode( "<br>",$errmessage ); // the "Location" header requires a FULLY QUALIFIED URL. // you _must_ include the schema and domain name. // the path alone is incorrect, // and won't work in all browsers under all circumstances. header( "Location: http://example.com/register2.php?message=$message" ); exit; } }else{ DBConnect(); // this is the other missing bracket }
January 2, 2014 at 6:14 am #159475MBMParticipantI’m getting :
Parse error: syntax error, unexpected '}' in /web/users/j9136124/rating/register2.php on line 44
When I remove it, it flags another error.
In the header locations I have :
header( "Location: https://mywebsite.com/register2.php?message=$message" );
January 2, 2014 at 9:54 am #159491__ParticipantI’m getting :
Parse error: syntax error, unexpected '}' in /web/users/j9136124/rating/register2.php on line 44
Is this using the code you showed me above?
Have you tried reformatting it (indenting your code)?
Keep in mind that when PHP finds an error, it isn’t necessarily the exact line you need to fix. PHP has no way of knowing what you wanted to do; it just knows what line it was on when things got so bad it had to stop parsing. Often times, the mistake you actually need to fix is a few lines above, so make sure to check before simply deleting whatever is on the line PHP reported.
In the header locations I have :
header( "Location: https://mywebsite.com/register2.php?message=$message" );
Good.
January 2, 2014 at 11:08 am #159499MBMParticipantI’ve added the code as you posted it, complete with indents. The updated gist is here :
January 3, 2014 at 7:12 pm #159603__ParticipantOkay, look here:
}else{ DBConnect(); // this is the other missing bracket } $Link = mysql_connect( // . . .
I suggested that closing bracket because the
else
block was open, and that was the end of the code you posted.Doing this (adding the rest of your code after) means that
DBConnect()
will only happen if the form was not submitted, while the$Link ...
and all of the following code will always happen.Is that what you intended? or should
$Link ...
be inside the firstif
(i.e., “happens when the form is submitted and there were no errors”)?I’ve added the code as you posted it, …
Note that I want to see the code you’re actually using
…which may or may not be the code I showed you. : )
January 3, 2014 at 7:21 pm #159604MBMParticipant$Link = mysql_connect($Host, $User, $Password);
Is after the DBConnect();
I’ve updated the github and removed non relevant HTML content.
January 7, 2014 at 4:12 pm #159870MBMParticipantI’ve debugged the code but it’s still not working as it should, the error messages are displayed in the address bar and not the page itself.
I’ve tried :
<?php print $message ; ?>
To display the messages.
January 7, 2014 at 4:27 pm #159871AlenParticipantTry using
<?php echo $_POST['message']; ?>
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.