form feedback

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jamrop
Forum Commoner
Posts: 80
Joined: Fri May 16, 2003 5:38 pm

form feedback

Post by jamrop »

Hey i am trying to get create a register form. When a user does an error and want to be able to display the message in the form table, but atm it is displayed at the top of the page. If i move the code so the error message shows in the form table, my header location does not work. Been driving me crazy. Any help plz

code :

Code: Select all

<?php
 
equire('dbinfo.php');	
if (isset($submit)) {
$valid=true;
if (!$username | !$password | !$confirm |  !$postcode  |  !$email  | !$hometel  |  !$mobtel)
{$errmsg.="You have not filled in a required field<br>"; $valid=false;}
					
$sql = "select username from members where username = '$username'";
$rs=mysql_query($sql,$db);
$numofrows =mysql_num_rows($rs);
if($numofrows !=0) {

$errmsg.=" Sorry, the username: <strong> $username </strong> is already taken, please pick another one<br>"; $valid=false;}
							
if  ($password != $confirm){
$errmsg.="Passwords did not match, Please try again<br>"; $valid=false;}
									
$email = trim($email);
$_name = "/^[-!#$%&''*+\\.\/0-9=?A-Z^_'{|}~]+";
$_host = "([-0-9A-Z]+\.)+";
$_tlds = "([0-9A-Z]){2,4}$/i";
if (!preg_match($_name."@".$_host .$_tlds,$email) )
{$errmsg.="Invalid email address, Please try again<br>";
$valid= false;}
							
}
					
if ($valid!=true)
{echo ( $errmsg.$form);}
					
else {
					
$regdate= date('m d,  Y');
$insert= "insert into members (username,password,email,postcode,home_tel,mobile_tel,datejoined,lastlog,valid) value ('$username', '$password', '$email', '$postcode', '$hometel', '$mobtel', '$regdate', 'never' ,0)";
					
mysql_query($insert,$db);
					
					
$adminaddr="jamie@hotmail.com"; 

mail($adminaddr, 'Member account', "Hey Jamie, $REMOTE_ADDR
$username has asked to join huddersfield classified  Thank you");
header("location:test1.php");}

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">



<html>



<head>



<title>Main menu</title>



<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">



<script language="JavaScript" type="text/JavaScript">



<!--



function MM_preloadImages() { //v3.0



  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();



    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)



    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}



}







function MM_swapImgRestore() { //v3.0



  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;



}







function MM_findObj(n, d) { //v4.01



  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {



    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}



  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];



  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);



  if(!x && d.getElementById) x=d.getElementById(n); return x;



}







function MM_swapImage() { //v3.0



  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)



   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}



}



//-->



</script>



</head>







<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onLoad="MM_preloadImages('classfied/home_f2.gif','classfied/login_f2.gif','classfied/reg_f2.gif','classfied/help_f2.gif','classfied/contact_f2.gif','classfied/subhomebut_r1_c2_f2.gif','classfied/subgardenbut_r1_c2_f2.gif','classfied/subfamilybut_r1_c2_f2.gif','classfied/subvehbut_r1_c2_f2.gif','classfied/substudentbut_r1_c2_f2.gif')">
<table width="100%" border="0" cellpadding="0" cellspacing="0">



  <tr> 



    <td height="90" valign="top"><img src="classfied/huddlogo.gif" width="300" height="80"></td>



    <td align="right" valign="bottom"> 



      <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="400" height="75">



        <param name="movie" value="classfied/advert.swf">



        <param name="quality" value="high">



        <embed src="classfied/advert.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="400" height="75"></embed></object></td>



  </tr>



  <tr bordercolor="#000000"> 



    <td width="45%" height="19" align="right" bgcolor="#000099"><font color="#FFFFFF" size="-1" face="Verdana, Arial, Helvetica, sans-serif"><strong>Bringing 



      People Together</strong></font></td>



    <td width="55%" align="left" valign="middle" bgcolor="#000099">&nbsp; </td>



  </tr>



</table>



<table width="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF">
  <tr  bgcolor="#99CCFF"> 
    <td width="16%" height="29" align="center" valign="middle"><a href="hudds.htm" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('home','','classfied/home_f2.gif',1)"><img src="classfied/home.gif" name="home" width="105" height="25" border="0"></a></td>
    <td width="16%" align="center"><a href="login/login.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('login','','classfied/login_f2.gif',1)"><img src="classfied/login.gif" name="login" width="105" height="25" border="0"></a></td>
    <td width="16%" align="center"><a href="reg/register.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('reg','','classfied/reg_f2.gif',1)"><img src="classfied/reg.gif" name="reg" width="105" height="25" border="0"></a></td>
    <td width="16%" align="center"><a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('help','','classfied/help_f2.gif',1)"><img src="classfied/help.gif" name="help" width="105" height="25" border="0"></a></td>
    <td width="16%" align="center"><a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('contact','','classfied/contact_f2.gif',1)"><img src="classfied/contact.gif" name="contact" width="105" height="25" border="0"></a></td>
  </tr>
</table>



<table width="100%" border="0" cellpadding="0" cellspacing="0">



  <tr bgcolor="#000099"> 



    <td width="50%" height="29" align="right" valign="middle"></td>



    <td width="50%" valign="top"></td>



  </tr>



</table>



<table width="100%" height="418" border="0">



  <tr> 



    <td width="1%">



    <td width="98%" valign="top"> <table width="100%" border="0" cellpadding="0" cellspacing="1" bordercolor="#666666">



        <tr> 



          <td width="17%" height="282" align="center" valign="top" bgcolor="#FFFFFF"><font size="-1" face="Verdana, Arial, Helvetica, sans-serif"><strong>Catergory 



            </strong> </font> <table width="100%" border="1" cellpadding="1" cellspacing="1" bordercolor="#33CC99">



              <tr> 



                <td bgcolor="#99FFCC"><a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image10','','classfied/subhomebut_r1_c2_f2.gif',1)"><img name="Image10" border="0" src="classfied/subhomebut_r1_c2.gif"></a></td>



              </tr>



              <tr> 



                <td bgcolor="#99FFCC"><a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image9','','classfied/subgardenbut_r1_c2_f2.gif',1)"><img name="Image9" border="0" src="classfied/subgardenbut_r1_c2.gif"></a></td>



              </tr>



              <tr> 



                <td height="21" bgcolor="#99FFCC"><a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image11','','classfied/subfamilybut_r1_c2_f2.gif',1)"><img src="classfied/subfamilybut_r1_c2.gif" name="Image11" width="110" height="18" border="0"></a></td>



              </tr>



              <tr> 



                <td bgcolor="#99FFCC"><a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image13','','classfied/substudentbut_r1_c2_f2.gif',1)"><img src="classfied/substudentbut_r1_c2.gif" name="Image13" width="124" height="18" border="0"></a></td>



              </tr>



              <tr> 



                <td height="20" bgcolor="#99FFCC"><a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image12','','classfied/subvehbut_r1_c2_f2.gif',1)"><img name="Image12" border="0" src="classfied/subvehbut_r1_c2.gif"></a></td>



              </tr>



            </table>



            <font size="-1" face="Georgia, Times New Roman, Times, serif"><strong><br>



            Search</strong></font> <table width="100%" border="1" cellpadding="1" cellspacing="1" bordercolor="#33CC99">



             <form name="find" action="../search.php" method="post"> <tr>



                  <td align="center" bgcolor="#99FFCC">

<input type="text" size="20" name="find">

                  </td>



              </tr>



              <tr>



                <td align="center" bgcolor="#99FFCC"><input name="submit" type="submit" value="Submit" size="20"></td>



              </tr></form>



            </table> 



          <td width="4%" valign="top"></td>

[color=red]//form table[/color]

          <td width="79%" valign="top"><font size="-1" face="Arial, Helvetica, sans-serif"><strong>Register</strong></font></p>
            <p><font size="-1" face="Verdana, Arial, Helvetica, sans-serif">Registration 
              at Huddersfield Classified is easy to do and absolutely free</font></p>
            <p><font size="-1" face="Verdana, Arial, Helvetica, sans-serif">Please 
              enter your details below<br>
              </font></p>
            <table width="100%" border="0" cellspacing="1" cellpadding="0">
              <tr>
                <td width="30%">Username:</td>
                <td width="63%"><form name="register" action="<?php $PHP_SELF ?>" method="post">
                    <input type="text" name="username" value="<?php echo $username ?>"size="30">
                 </td>
              </tr>
              <tr>
                <td>Password:</td>
                <td><input type="password" name="password"></td>
              </tr>
              <tr>
                <td>Confirm Password:</td>
                <td><input type="password" name="confirm"></td>
              </tr>
              <tr>
                <td>Address Postcode<span class="small">(<font color="#FF0000">this 
                  will not be displayed <br>
                  with your adverts, this is for security reasons only</font>)</span></td>
                <td><input type="text" name="postcode" value="<?php echo $postcode ?>" size="10"></td>
              </tr>
              <tr>
                <td>Email:<span class="small">(<font color="#FF0000">A valid email address is required <br>
                  to activate your account </font>)</span></td>
                <td><input type="text" name="email" value="<?php echo $email ?>" size="30"></td>
              </tr>
              <tr>
                <td>Home Telephone :</td>
                <td><input type="text" name="hometel" value="<?php echo $homtel ?>"></td>
              </tr>
              <tr>
                <td>Mob Telephone (Optional):</td>
                <td><input type="text" name="mobtel" value="<?php echo $mobtel ?>"></td>
              </tr>
              <tr>
                <td>&nbsp;</td>
                <td>
                    <input type="submit" name="submit" value="Submit">
                  </form></td>
              </tr>
            </table>



            </td>



        </tr>



      </table></tr>



</table>



</body>



</html>




?>

Thanks very much

Jamie
qartis
Forum Contributor
Posts: 271
Joined: Sat Dec 14, 2002 4:43 pm
Location: BC, Canada
Contact:

Post by qartis »

If you're willing to sacrifice a hundredth of a second for php, then just add this above everything:

Code: Select all

<?
ob_start();
?>
And at the end:

Code: Select all

<?
ob_end_flush();
?>

Will turn on output buffering, which allows Header() redirects after text has been 'sent' to the browser.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Tip: do the form processing on a diff page

also use the proper $_GET or $_POST globals

;)
Post Reply