Page 1 of 1

would like to display form errors on same page

Posted: Wed Feb 05, 2003 8:07 am
by deejay
Hi

I have made a form that writes to a database and have a password confirmation and to see if the username is used by someone else.

i use the code for example
{

die ("Your Password has not matched<p>");

}

this then displays that message on its own, how can display this message at the top of the form.

Thanks

Deej

Posted: Wed Feb 05, 2003 8:31 am
by volka
e.g. by printing the form again

Code: Select all

<?php
...
if (!$bMatched)
{
?>
<p>Your Password has not matched</p>
<form method=...
...
</form>
<?php
die ();
}
...
?>

Posted: Wed Feb 05, 2003 9:40 am
by deejay
thanks, was pretty obvious really eh.

I am now having a problems rediplaying the information already entered. I would have thought something like

<?php echo $firstName ?>

should do it, but just prints that line "<?php echo $firstName ?>". i take it is something simple again, will keep trying things :?

Thanks again

Deej

Posted: Wed Feb 05, 2003 10:16 am
by volka
maybe a stupid question: your php-processor is working? e.g.

Code: Select all

<?php phpinfo(); ?>
does not only print that line when requested?
And if so, what does

Code: Select all

<html><head></head>
<body>
	<fieldset><legend>posted data for this request</legend>
		<pre><?php print_r($_POST); ?></pre>
	</fieldset>
	<hr />
	<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
		<!-- switching data here, no sense, just an example  -->
		<input type="text" name="i1" value="<?php if(isset($_POST['i2'])) echo $_POST['i2']; ?>" />: i1<br />
		<input type="text" name="i2" value="<?php if(isset($_POST['i1'])) echo $_POST['i1']; ?>" />: i2<br />
		<input type="submit" name="subutton" value="submit a" />
		<?php if(isset($_POST['subutton']) && $_POST['subutton']=='submit a') echo '*' ?><br />
		<input type="submit" name="subutton" value="submit b" />
		<?php if(isset($_POST['subutton']) && $_POST['subutton']=='submit b') echo '*' ?><br />
		<input type="submit" name="subutton" value="submit c" />
		<?php if(isset($_POST['subutton']) && $_POST['subutton']=='submit c') echo '*' ?><br />
	</form>
</body></html>
do?

Posted: Wed Feb 05, 2003 10:28 am
by deejay

Posted: Wed Feb 05, 2003 10:34 am
by volka
then it does what it is supposed to do and the error must be somewhere in your script ;)
Might we see it?

Posted: Wed Feb 05, 2003 10:53 am
by deejay
Yeah of course,

Here i have included from after my connection until end of the repeated form. the form can be seen at

http://www.cctv-city.com/signup/ccMembersSignUp.php

if ($submit) {


// this code parses the email string

$as_email = addslashes($_POST['email']);
$user_email = trim($as_email);

// check password confirmation is identical

if ($password_conf!== $user_password ) {

die ("Your Password has not matched<p>");

}

// the next lines check to see if the username is already being used


$result=mysql_query("SELECT * from ccMembers WHERE username = '$username'");

if(mysql_num_rows($result)>0)

{
/*********************************************************************************
************************FORM REPEATED ********************************************
***********************************************************************************/

die ('
<link rel="stylesheet" href="../phpBB/templates/subSilver/subSilver.css" type="text/css">
<form method="post" action="<?php echo $PHP_SELF?>">

<input type=hidden name="user_id" value="<?php echo $user_id ?>">



<table width="100%" cellspacing="2" cellpadding="2" border="0" align="center">
<tr>
<td align="left"><b><font class="errorMessage">Error: You have choosen the same username as someone else. Could you plese choose another one.</font></b></td>
</tr>
</table>

<table border="0" cellpadding="3" cellspacing="1" width="100%" class="forumline">
<tr>
<th class="thHead" colspan="2" height="25" valign="middle">Registration
Information</th>
</tr>
<tr>
<td class="row2" colspan="2"><span class="gensmall">Items marked with
a * are required unless stated otherwise.</span></td>
</tr>
<tr>

<td class="row1" width="38%" height="60"><span class="gen">First Name: *</span></td>

<td class="row2" height="60">
<input type="Text" name="firstName" style="width: 200px" size="25" maxlength="25" value="<?php echo $firstName ?>">
</td>
</tr>
<tr>
<td class="row1" width="38%"><span class="gen">Last Name: *</span></td>
<td class="row2">
<input type="Text" name="lastName" style="width: 200px" size="25" maxlength="25" value="<?php echo $lastName ?>">

</td>
</tr>

<tr>

<td class="row1" width="38%"><span class="gen">Email: *</span></td>
<td class="row2">
<input type="Text" name="email" style="width: 200px" size="25" maxlength="25" value="<?php echo $user_email ?>">

</td>
</tr>


<tr>
<td class="row1" width="38%"><span class="gen">Username: *</span></td>
<td class="row2">
<input type="text" class="post" style="width:200px" name="username" size="25" maxlength="25" value="<?php echo $username ?>">
</td>
</tr>




<tr>

<td class="row1" width="38%"><span class="gen">Password: *</span></td>
<td class="row2">
<input type="password" name="user_password" style="width: 200px" size="25" maxlength="25" value="<?php echo $user_password ?>">

</td>
</tr>

<tr>

<td class="row1" width="38%"><span class="gen">Password Confirmation: *</span></td>
<td class="row2">
<input type="password" name="password_conf" style="width: 200px" size="25" maxlength="25" value="<?php echo $password_conf ?>">

</td>
</tr>
<tr>

<td class="row1" width="38%">&nbsp;</td>
<td class="row2">&nbsp; </td>
</tr>
<tr>

<th class="thSides" colspan="2" height="25" valign="middle"> Business Information</th>
</tr>
<tr>
<td class="row2" colspan="2"><span class="gensmall">This informatin
will only be used to display the most relevant information to you
when you login to CCTV-City</span></td>
</tr>

<tr>

<td class="row1" width="38%"><span class="gen">Which of follwing categories
do you belong to ?</span></td>

<td class="row2"> <span class="gensmall">
<select name="user_sector">
<option value="$user_sector">
<?php echo $user_sector ?>
</option>
<option value="business user">Business Security User</option>
<option value="home user" selected>Home Security User</option>
<option value="business and home user" selected>Business & Home Security User</option>
<option value="installer" selected>Installers</option>
</select>
</span></td>
</tr>
<tr>

<td class="row1" width="38%"><span class="gen">If you selected Business
user which one of these businesses is the closet to what you do ?</span></td>

<td class="row2"> <span class="gensmall">
<select name="business_group">
<option value="$business_group"><span class="gensmall">
<?php echo $business_group ?>
</span></option>
<option value="retail store"><span class="gensmall">Retail Store</span></option>
<option value="office" selected><span class="gensmall">Office</span></option>
<option value="warehouse or factory" selected><span class="gensmall">Warehouse/Factory</span></option>
<option value="school" selected><span class="gensmall">School</span></option>
<option value="hospital" selected><span class="gensmall">Hospital</span></option>
<option value="night club" selected><span class="gensmall">Night Club</span></option>
<option value="taxis and delivery vehicles" selected><span class="gensmall">Taxi/Delivery Vehicles</span></option>
<option value="vending machines" selected><span class="gensmall">Vending Machines</span></option>
<option value="other" selected><span class="gensmall">Other</span></option>
</select>
</span></td>
</tr>

<tr>

<td class="row1" width="38%"><span class="gen">If you selected Installer
would you like to be sent information on how to become a CCTV-City installer?</span></td>

<td class="row2"> <span class="gensmall">
<input type="radio" name="installer_application" value="1" >
<span class="gen">Yes</span>&nbsp;&nbsp;
<input type="radio" name="installer_application" value="0" checked />
<span class="gen">No</span> </span></td>
</tr>


<tr>
<th class="thSides" colspan="2" height="25" valign="middle"> Message
board Profile Information </th>
</tr>

<tr>
<td class="row2" colspan="2"><span class="gensmall">This information
will be publicly viewable</span></td>
</tr>



<tr>

<td class="row1" width="38%"><span class="gen">ICQ Number:</span></td>

<td class="row2">
<input type="text" name="user_icq" style="width: 100px" size="10" maxlength="15" value="<?php echo $user_icq ?>" >
</td>
</tr>


<tr>

<td class="row1" width="38%"><span class="gen">AIM Address:</span></td>

<td class="row2">
<input type="text" name="user_aim" style="width: 100px" size="10" maxlength="15" value="<?php echo $user_aim ?>" >
</td>
</tr>



<tr>
<td class="row1"><span class="gen">MSN Messenger:</span></td>
<td class="row2">
<input type="text" class="post" style="width: 150px" name="msnm" size="20" maxlength="255" value="<?php echo $msnm ?>" >
</td>
</tr>

<tr>
<td class="row1"><span class="gen">Yahoo Messenger:</span></td>
<td class="row2">
<input type="text" class="post"style="width: 150px" name="user_yim" size="20" maxlength="255" value="<?php echo $user_yim ?>" >
</td>
</tr>


<tr>
<td class="row1"><span class="gen">Website:</span></td>
<td class="row2">
<input type="text" class="post"style="width: 200px" name="user_website" size="25" maxlength="255" value="<?php echo $user_website ?>" >
</td>
</tr>

<tr>

<td class="row1" width="38%"><span class="gen">Location: </span></td>
<td class="row2">
<input type="Text" name="user_from" style="width: 200px" size="25" maxlength="25" value="<?php echo $user_from ?>">
</td>
</tr>
<tr>

<td class="row1"><span class="gen">Occupation: </span></td>
<td class="row2">
<input type="Text" name="user_occ" style="width: 200px" size="25" maxlength="225" value="<?php echo $user_occ ?>"><br>

</td>
</tr>
<tr>
<td class="row1"><span class="gen">Interests:</span></td>
<td class="row2">
<input type="text" class="post" style="width: 200px" name="user_interests" size="35" maxlength="150" value="<?php echo $user_interests ?>" >
</td>
</tr>



<tr>
<td class="row1"><span class="gen">Signature:</span><br>
<span class="gensmall">This is a block of text that can be added
to posts you make. There is a 255 character limit<br>
<br />
HTML is <u>OFF</u><br>
<a href="../phpBB/faq.php?mode=bbcode&sid=1521ecd76f98fde3967d640e20c330b6" target="_phpbbcode">BBCode</a>
is <u>ON</u><br>
Smilies are <u>ON</u></span></td>
<td class="row2">
<textarea name="user_sig" style="width: 300px" rows="6" cols="30" class="post">
<?php echo $user_sig ?>
</textarea>
</td>
</tr>

<tr>
<th class="thSides" colspan="2" height="25" valign="middle">Message
board Preferences<br></th>
</tr>
<tr>
<td class="row1" height="25"><span class="gen">Always show my e-mail
address:</span></td>
<td class="row2" height="25">
<input type="radio" name="user_viewemail" value="1" >
<span class="gen">Yes</span>&nbsp;&nbsp;
<input type="radio" name="user_viewemail" value="0" checked >
<span class="gen">No</span></td>
</tr>

<tr>
<td class="row1"><span class="gen">Hide your online status:</span></td>
<td class="row2">
<input type="radio" name="user_allow_viewonline" value="1">
<span class="gen">Yes</span>&nbsp;&nbsp;
<input type="radio" name="user_allow_viewonline" value="0" checked>
<span class="gen">No</span></td>
</tr>

<tr>
<td class="row1"><span class="gen">Always notify me of replies:</span><br>
<span class="gensmall">Sends an e-mail when someone replies to a
topic you have posted in. This can be changed whenever you post.</span></td>
<td class="row2">
<input type="radio" name="user_notify" value="1">
<span class="gen">Yes</span>&nbsp;&nbsp;
<input type="radio" name="user_notify" value="0" checked>
<span class="gen">No</span></td>
</tr>


<tr>
<td class="row1"><span class="gen">Notify on new Private Message:</span></td>
<td class="row2">
<input type="radio" name="user_notify_pm" value="1" checked >
<span class="gen">Yes</span>&nbsp;&nbsp;
<input type="radio" name="user_notify_pm" value="0" >
<span class="gen">No</span></td>
</tr>



<tr>
<td class="row1"><span class="gen">Pop up window on new Private Message:</span><br>
<span class="gensmall">Some templates may open a new window to inform
you when new private messages arrive.</span></td>
<td class="row2">
<input type="radio" name="user_popup_pm" value="1" checked >
<span class="gen">Yes</span>&nbsp;&nbsp;
<input type="radio" name="user_popup_pm" value="0">
<span class="gen">No</span></td>
</tr>

<tr>
<td class="row1"><span class="gen">Always attach my signature:</span></td>
<td class="row2">
<input type="radio" name="user_attachsig" value="1" checked>
<span class="gen">Yes</span>&nbsp;&nbsp;
<input type="radio" name="user_attachsig" value="0" >
<span class="gen">No</span></td>
</tr>

<tr>
<td class="row1"><span class="gen">Always allow BBCode:</span></td>
<td class="row2">
<input type="radio" name="user_allowbbcode" value="1" checked >
<span class="gen">Yes</span>&nbsp;&nbsp;
<input type="radio" name="user_allowbbcode" value="0" >
<span class="gen">No</span></td>
</tr>


<tr>
<td class="row1"><span class="gen">Always allow HTML:</span></td>
<td class="row2">
<input type="radio" name="user_allowhtml" value="1" >
<span class="gen">Yes</span>&nbsp;&nbsp;
<input type="radio" name="user_allowhtml" value="0" checked >
<span class="gen">No</span></td>
</tr>

<tr>
<td class="row1"><span class="gen">Always enable Smilies:</span></td>
<td class="row2">
<input type="radio" name="user_allowsmilies" value="1" checked >
<span class="gen">Yes</span>&nbsp;&nbsp;
<input type="radio" name="user_allowsmilies" value="0" >
<span class="gen">No</span></td>
</tr>
<tr>
<td class="row1"><span class="gen">Board Language:</span></td>
<td class="row2"><span class="gensmall">
<select name="user_lang">
<option value="english" selected>English</option>
</select>
</span></td>
</tr>


<tr>
<td class="row1"><span class="gen">Board Style:</span></td>
<td class="row2"><span class="gensmall">
<select name="user_style">

<option value="1" selected>subSilver</option>
</select>
</span></td>
</tr>

<tr>
<td class="row1"><span class="gen">Timezone:</span></td>
<td class="row2"><span class="gensmall">
<select name="user_timezone">
<option value="-12">GMT - 12 Hours</option>
<option value="-11">GMT - 11 Hours</option>
<option value="-10">GMT - 10 Hours</option>
<option value="-9">GMT - 9 Hours</option>
<option value="-8">GMT - 8 Hours</option>
<option value="-7">GMT - 7 Hours</option>
<option value="-6">GMT - 6 Hours</option>
<option value="-5">GMT - 5 Hours</option>
<option value="-4">GMT - 4 Hours</option>
<option value="-3.5">GMT - 3.5 Hours</option>
<option value="-3">GMT - 3 Hours</option>
<option value="-2">GMT - 2 Hours</option>
<option value="-1">GMT - 1 Hours</option>
<option value="0" selected>GMT</option>
<option value="1">GMT + 1 Hour</option>
<option value="2">GMT + 2 Hours</option>
<option value="3">GMT + 3 Hours</option>
<option value="3.5">GMT + 3.5 Hours</option>
<option value="4">GMT + 4 Hours</option>
<option value="4.5">GMT + 4.5 Hours</option>
<option value="5">GMT + 5 Hours</option>
<option value="5.5">GMT + 5.5 Hours</option>
<option value="6">GMT + 6 Hours</option>
<option value="6.5">GMT + 6.5 Hours</option>
<option value="7">GMT + 7 Hours</option>
<option value="8">GMT + 8 Hours</option>
<option value="9">GMT + 9 Hours</option>
<option value="9.5">GMT + 9.5 Hours</option>
<option value="10">GMT + 10 Hours</option>
<option value="11">GMT + 11 Hours</option>
<option value="12">GMT + 12 Hours</option>
<option value="13">GMT + 13 Hours</option>
</select>
</span></td>
</tr>
<tr>
<td class="row1"><span class="gen">Date format:</span><br>
<span class="gensmall">The syntax used is identical to the PHP <a href="http://www.php.net/date" target="_other">date()</a>
function.</span></td>
<td class="row2">
<input type="text" name="user_dateformat" value="D M d, Y g:i a" maxlength="14" class="post" >
</td>
</tr>





<tr>
<td class="catBottom" colspan="2" align="center" height="28">
<input type="Submit" name="submit" value="Enter information">
</td>
</tr>
</table>



</form>

');

/*********************************************************************************
************************FORM REPEATED END*****************************************
***********************************************************************************/


the form works so i take it i don't need to show you anymore of this code. all gets a bit long winded and i wouldn't blame you if its too much for you to search through this. Any help is gratefully received.

Cheers

Deej

Posted: Wed Feb 05, 2003 11:39 am
by volka
die ('
<link rel [...]
so you're already within a php-block and even within a string-literal. But printing such a large string is really unnecessary, I suggest using something like

Code: Select all

<?php
...
if(mysql_num_rows($result)>0)
{ // FORM REPEATED 
?>
<link rel="stylesheet" href="../phpBB/templates/subSilver/subSilver.css" type="text/css">
<form method="post" action="<?php echo $PHP_SELF?>">
	<input type=hidden name="user_id" value="<?php echo $user_id ?>">
...
</form>
<?php
	die();
}
...
?>
might also be advisable to put the form into a function so you can reuse it.

Posted: Thu Feb 06, 2003 8:55 am
by deejay
still cant get this sorted :-(

I have put the form on a seperate file and can call it from the main HTML body with

<?php include("../includes/mainForm.php"); ?>

yet it will display with (all inside ?php tags)

die ('
<link rel="stylesheet" href="../phpBB/templates/subSilver/subSilver.css" type="text/css">
<tr>
<td align="left"><b><font class="errorMessage">Error: You have choosen the same username as someone else. Could you plese choose another one.</font></b></td>
</tr>

<?php include("../includes/mainForm.php"); ?>

');



this displays the table but not the include, no error is givien either?

thanks in advace for any tips.

Posted: Thu Feb 06, 2003 9:33 am
by volka
maybe it's still the same error, can't really tell you.
Take a syntax highlighting editor to check that, there are some threads on php-editors around here, e.g. viewtopic.php?t=2911

Posted: Fri Feb 07, 2003 7:18 am
by deejay
it must have something to do with the

die ('
')

syntax as it can't be reading the

<?php include('../includes/mainForm.php'); ?>

although it doesn't print it as text. i have tried using printf instead but anything other than die prints out a form i dont want it to.

I will keep on trying things. :roll:

Posted: Fri Feb 07, 2003 9:29 am
by volka
ah, then you have the include within die(' ... ') ?
In short: die('[text] <?php include('../includes/mainForm.php'); ?> [text] ') ?
if so: That cannot work at all for some reasons.
  1. if you're in a string literal you're -well- within a string. There's no further parsing for control-structures
  2. the stringliteral has been opened by ' so the next (unescaped) ' will close it, which will confuse php the way you did it.
I stronly recommend reading the first three chapters of http://www.php.net/manual/en/ esp. http://www.php.net/manual/en/language.basic-syntax.php and http://www.php.net/manual/en/language.types.string.php
But as a simple example for now take a look at these two codefragments, notice the different colors the source-highlighter of php assigns to the parts.

Code: Select all

<?php
die('just some text');
?>
something outside php, printed as is to the client
<?php // a new php-block
include ('anotherfile.php');
?>

Code: Select all

<?php
die('not closing the literal, this:
<?php include('anotherfile.php') ?>
is neither done nor understood by php
');
?>