Solved

Need help troublshooting form

Posted on 2006-06-08
9
317 Views
Last Modified: 2008-02-01
I've got something wrong with my form where it's not updating the database when I click submit.  I would like some help troubleshooting the form.  I put the code for the page below.

<?php
session_start();
header("Cache-control: private");

if($_POST['UserName']!="" && $_POST['Password1']!="" && $_POST['Password2']!="" && $_POST['Email']!=""  && $_POST['Name'] !="" && $_POST['Country'] !="" && $_POST['State'] !="" && $_POST['City'] !=""&& $_POST['ZipCode'] !="" && $_POST['Adress'] !="" && $_POST['phone']!="" && $_POST['company']!=="" && $_POST['checkbox']!="" && !($_POST['Country']==60 && $_POST['idtax']==""))
{
      $errorMsg="";
      include ("../dbase.php");
      include ("../settings.php");

      $replacevalues = array('&','/'," ","?","+","%","$","#","@");
      $username=str_replace($replacevalues,"", $_POST['UserName']);
      
      $result = mysql_query("SELECT user FROM chatoperators WHERE user='$username'");
      if (mysql_num_rows($result)==1){
      $errorMsg="Username exists, please choose another one!";
      } else if($_POST['Password1']!=$_POST['Password2']) {
      $errorMsg="Passwords do not match";
      }else if(strlen($_POST['Password1'])<6){
      $errorMsg="Passwords must be at least 6 characters long";

      } else {
            //user ID
            $dateRegistered=time();
            $currentTime=date("YmdHis");
            $userId=md5("$currentTime".$_SERVER['REMOTE_ADDR']);
            $db_pass=md5($_POST['Password1']);
            
            $_SESSION['UID']=$userId;
            $_SESSION['email']=$_POST['Email'];
            $_SESSION['password']=$_POST['Password1'];
            $_SESSION['emailtype']=$_POST['emailtype'];
            
            if(mysql_query("INSERT INTO chatoperators VALUES ('$userId','$username', '".$_POST['Password1']."', '".$_POST['Email']."', '".$_POST['Name']."', '".$_POST['Country']."', '".$_POST['State']."','".$_POST['City']."', '".$_POST['ZipCode']."', '".$_POST['phone']."', '".$_POST['Adress']."', '".$_POST['PMethod']."', '".$_POST['PInfo']."', '$dateRegistered','$dateRegistered','0','0','500','pending','$sopepercentage','".$_POST['emailtype']."','".$_POST['company']."','".$_POST['idtax']."')"))
            { } else { $errorMsg="Could not modify database(".mysql_error().")";}
      }//end if user exists
      
      if ($errorMsg==""){
      header ("Location: sopregistered.php");
      
$subject = "Your operator account activation at $siteurl";

if ($_POST['emailtype']=="text"){
$charset="Content-type: text/plain; charset=iso-8859-1\r\n";
$message = "Thank you for registering at $siteurl
In order to activate your newly created account copy and paste the link below in your browser:

$siteurl/actop.php?UID=$userId

Once you activate your membership you will recieve a mail with your login information.

Thanks!
The Webmaster
This is an automated response, please do not reply!";

} else if($_POST['emailtype']=="html"){

$charset="Content-type: text/html; charset=iso-8859-1\r\n";
$message = "Thank you for registering at $siteurl
In order to activate your newly created account copy and paste the link below in your browser:

<a href='$siteurlactop.php?UID=$userId'>$siteurlactop.php?$userId</a>

Once you activate your membership you will recieve a mail with your login information.

Thanks!
The Webmaster
This is an automated response, please do not reply!";

}else {
echo"Email Session variable not set";
}

mail($_SESSION['email'], $subject, $message,
     "MIME-Version: 1.0\r\n".
     $charset.
     "From:$registrationemail\r\n".
     "Reply-To:$registrationemail\r\n".
     "X-Mailer: PHP/" . phpversion() );
      
      
      }
      
}
else
{
$errorMsg="Please fill all the required fields.";
}
?>
<html>
<head>
<title>User Registration</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
-->
</style>
<link href="../styles.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.style4 {color: #CCCCCC}
body {
      background-color: #000000;
}
.style1 {color: #FFFFFF}
.style2 {color: #666666}
.style5 {color: #999999}
.style6 {font-size: 10px}
-->
</style>
</head>


<TABLE BORDER="0" align="center" CELLPADDING="0" CELLSPACING="0">
  <TR>
    <TD COLSPAN="7"><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="720" height="201">
        <param name="movie" value="../movie.swf">
        <param name="quality" value="high">
        <embed src="../movie.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="720" height="201"></embed></object></TD>
  </TR>
  <TR>
    <TD colspan="7"> <table width="400" border="0" align="center">
        <TR>
          <td><a href="/index.php"><IMG SRC="../images/header_2.gif" WIDTH="122" BORDER="0" HEIGHT="30"></a></td>
          <TD><a href="/user.php"><IMG SRC="../images/header_3.gif" WIDTH="78" BORDER="0" HEIGHT="30"></a></TD>
          <TD><a href="/registration/model_agree.php"><IMG SRC="../images/header_4.gif" BORDER="0" width="125" height="30"></a></TD>
          <TD><a href="/login.php"><IMG SRC="../images/header_6.gif" WIDTH="60" BORDER="0" HEIGHT="30"></a></TD>
          <TD><a href="/faq.php"><IMG SRC="../images/header_7.gif" WIDTH="44" BORDER="0" HEIGHT="30"></a></TD>
        </TR>
      </table></TD>
  </TR>
</TABLE>
<table width="720" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="52"><span class="big_title style4">Studio Operators  registration Form</span><br>      
      <span class="small_title style4">As a Studio operator you will be able to add Models to your account, watch their actvity and earn money as they chat with our memebers. </span><span class="small_title"><br>
    <span class="error">
    <?php if ( isset($errorMsg) && $errorMsg!=""){ echo $errorMsg; } ?>
    </span>      </span></td>
  </tr>
</table>
<form action="operator.php" method="post" enctype="multipart/form-data" name="form1" target="_self">
  <table width="720" border="0" align="center" cellpadding="4" cellspacing="0">
    <tr bgcolor="#9A0000">
      <td colspan="3"><table width="80%" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
          <td class="form_header_title">Step 1: User Information </td>
        </tr>
      </table></td>
    </tr>
    <tr>
      <td colspan="3" class="form_definitions">Login information. Your user will be a unique user.</td>
    </tr>
    <tr>
      <td width="150" align="right" class="form_definitions">
        <? if(isset($_POST['UserName']) && $_POST['UserName']==""){
              echo "<font color=red>Username*</font>";
              } else{
              echo"Username";
        }?></td>
      <td><input name="UserName"  value="<? if (isset($_POST['UserName'])){ echo $_POST['UserName']; }  ?>" type="text" id="UserName" size="24" maxlength="24"></td>
      <td width="296">&nbsp;</td>
    </tr>
    <tr>
      <td align="right" class="form_definitions">
        <? if(isset($_POST['Password1']) && $_POST['Password1']==""){
              echo "<font color=red>Password*</font>";
              } else{
              echo"Password*";
        }?>        </td>
      <td><input name="Password1" type="password" id="Password1" size="24" maxlength="24"></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td align="right" class="form_definitions">
        <? if(isset($_POST['Password2']) && $_POST['Password2']==""){
              echo "<font color=red>Password*</font>";
              } else{
              echo"Password*";
        }?>        </td>
      <td><input name="Password2" type="password" id="Password2" size="24" maxlength="24"></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td align="right" class="form_definitions">
        <? if(isset($_POST['Email']) && $_POST['Email']==""){
              echo "<font color=red>E-mail*</font>";
              } else{ echo"E-mail*";}
        ?>        </td>
      <td><input name="Email" value="<? if (isset($_POST['Email'])){ echo $_POST['Email']; }  ?>" type="text" id="Email" size="24" maxlength="50"></td>
      <td><span class="form_informations">Your email will not be visible to members and will not be discolsed to other parties. </span></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr bgcolor="#930300">
      <td colspan="3"><table width="80%" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td class="form_header_title">Step 2: Personal information</td>
          </tr>
      </table></td>
    </tr>
    <tr align="left">
      <td colspan="3" class="form_definitions"><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="140" height="24">
        <param name="movie" value="topsecret.swf">
        <param name="quality" value="high">
        <embed src="topsecret.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="140" height="24"></embed>
      </object>
This informations are kept confidential and never displayed o disclose to others <br>
(internal use only).</td>
    </tr>
    <tr>
      <td align="right" class="form_definitions"><? if(isset($_POST['Name']) && $_POST['Name']==""){
              echo "<font color=red>Full Name*</font>";
              } else{ echo"Full Name*";}
                ?>        </td>
      <td><input name="Name" value="<? if (isset($_POST['Name'])){ echo $_POST['Name']; }  ?>" type="text" id="Name" size="24" maxlength="24"></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td align="right" class="form_definitions">Country*</td>
      <td width="250">
        <select name="Country" id="Country">
          <?
              include ("../dbase.php");
include ("../settings.php");
            $result = mysql_query('SELECT * FROM countries ORDER BY name');
          while($row = mysql_fetch_array($result)) {
            echo"<option value='$row[id]'";
            if (isset($_POST['Country']) && $_POST['Country']==$row['id']){
            echo "selected";
            }
            
            echo ">$row[name]</option>";
            }
             
             
              ?>
               
        </select>
        </td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td align="right" class="form_definitions"><? if(isset($_POST['State']) && $_POST['State']==""){
              echo "<font color=red>State*</font>";
              } else{ echo"State*";}
                ?>        </td>
      <td><input name="State" value="<? if (isset($_POST['State'])){ echo $_POST['State']; } ?>" type="text" id="State" size="24" maxlength="24"></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td align="right" class="form_definitions">
        <? if(isset($_POST['City']) && $_POST['City']==""){
              echo "<font color=red>City*</font>";
              } else{ echo"City*";}
                ?>        </td>
      <td><input name="City" value="<? if (isset($_POST['City'])){ echo $_POST['City']; } ?>" type="text" id="City" size="24" maxlength="24"></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td align="right" class="form_definitions">
        <? if(isset($_POST['ZipCode']) && $_POST['ZipCode']==""){
              echo "<font color=red>Zip Code*</font>";
              } else{ echo"Zip Code*";}
                ?>        </td>
      <td><input name="ZipCode" value="<? if (isset($_POST['ZipCode'])){ echo $_POST['ZipCode']; }  ?>" type="text" id="ZipCode" size="24" maxlength="24"></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td align="right" class="form_definitions">
        <? if(isset($_POST['phone']) && $_POST['phone']==""){
              echo "<font color=red>Phone Number*</font>";
              } else{ echo"Phone Number*";}
                ?>
      </td>
      <td><input name="phone" value="<? if (isset($_POST['phone'])){ echo $_POST['phone']; }  ?>" type="text" id="phone" size="24" maxlength="24"></td>
      <td class="form_informations"> (999) 999-9999 </td>
    </tr>
    <tr>
      <td align="right" class="form_definitions">
        <? if(isset($_POST['Adress']) && $_POST['Adress']==""){
              echo "<font color=red>Street Adress*</font>";
              } else{ echo"Street Adress*";}
                ?>        </td>
      <td><textarea name="Adress" cols="24" rows="5" id="Adress"><? if (isset($_POST['Adress'])){echo $_POST['Adress']; } ?></textarea></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td align="right"><span class="form_definitions">
        <? if(isset($_POST['company']) && $_POST['company']==""){
              echo "<font color=red>Company*</font>";
              } else{ echo"Company*";}
                ?>
      </span></td>
      <td><input name="company" value="<? if (isset($_POST['company'])){ echo $_POST['company']; }  ?>" type="text" id="company" size="24" maxlength="24"></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td align="right"><span class="form_definitions">
        <? if(isset($_POST['taxid']) && $_POST['taxid']=="" &&  $_POST['Country']==60){
              echo "<font color=red>Tax Id number (if US company)*</font>";
              } else{ echo"Tax Id number (if US company)*";}
                ?>
      </span></td>
      <td><input name="taxid" value="<? if (isset($_POST['taxid'])){ echo $_POST['taxid']; }  ?>" type="text" id="taxid" size="24" maxlength="24"></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr bgcolor="#970102">
      <td colspan="3"><table width="80%" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td><span class="form_header_title">Step 3: Recieve Money Info </span></td>
          </tr>
      </table></td>
    </tr>
    <tr align="left">
      <td colspan="3" class="form_definitions">This information will beused in order to send you the money. Money is sent once a month on the 24.</td>
    </tr>
    <tr>
      <td align="right" class="form_definitions">Payment Method</td>
      <td><select name="PMethod" id="PMethod">
          <option value="wu">Western Union</option>
          <option value="wt">Wire Transfer</option>
        </select></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td align="right" class="form_definitions">Payment Information</td>
      <td><textarea name="PInfo" cols="24" rows="5" id="PInfo"><? if (isset($_POST['PInfo'])){ echo $_POST['PInfo']; } ?></textarea></td>
      <td>&nbsp;</td>
    </tr>
    <tr align="left" bgcolor="#970102">
      <td colspan="3"><table width="80%" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td><span class="form_header_title">Step 4: Complete your Studio Operator subscription </span></td>
          </tr>
      </table></td>
    </tr>
    <tr>
      <td colspan="3" align="right"><div align="left"><span class="form_definitions">Your account is automatically created and you can start chatting live right away. </span></div></td>
    </tr>
    <tr>
      <td colspan="3" class="form_definitions"><? if(!isset($_POST['checkbox'])) { echo "<font color=red>You must agree with the terms:</font><br>";
}?>
          <input name="checkbox" type="checkbox" value="checkbox" <? if( isset($_POST['checkbox']) && $_POST['checkbox']=="checkbox"){echo "checked";}?>>
        I Agree the Terms and Conditions. <a href="../terms.php" target="_blank" class="left">Read
        the Terms and Conditions here. </a><br>
<br>
Send registration emails as::
<input name="emailtype" type="radio" value="text" checked>
Plain text
<input name="emailtype" type="radio" value="html">
Html</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input type="submit" name="Submit" value=" I Agree the Terms and Conditions"></td>
      <td>&nbsp;</td>
    </tr>
  </table>
  <p>&nbsp;</p>
</form>
<table width="720" border="0" align="center" cellpadding="0" cellspacing="0" class="form_definitions">
   <tr>
    <td align="center" bgcolor="#000000"><span class="style2">-------------------------------------------------------------------------------------------------------------------</span></td>
  </tr>
  </table>
</body>
</html>
0
Comment
Question by:acicalla
  • 5
  • 4
9 Comments
 

Author Comment

by:acicalla
ID: 16867402
When I hit submit it's not entering the data into the database. It has entered one record. But in the process of fixing that issue the page quit submitting to were I just keep getting returned to my original form.
0
 

Author Comment

by:acicalla
ID: 16867969
also the error from the form is please fill all required fields, even though they are all filled.
0
 
LVL 49

Expert Comment

by:Roonaan
ID: 16876650
Hi,

You are using $_POST['idtax'] while you have <input name="taxid" ../>

As suggestion I would also change
if($_POST['UserName'] != "" .. etc

into

if(!empty($_POST['UserName']) && !empty($_POST['Password1']) && !empty($_POST['Passwprd2'])

Alternatively you can use this:
$required = array('UserName','Password1','Password2');
$failed = 0;
foreach($required as $field) {
  if(empty($_POST[$field])) $failed++;
}

if($failed == 0) {
}

Also you would have to change your output to use htmlspecialchars:

<input name="Name" value="<?php if(!empty($_POST['Name'])) { echo htmlspecialchars($_POST['Name']);}?>"

Kind regards

-r-
0
 

Author Comment

by:acicalla
ID: 16878465
ok, the form is submitting and updating the database if I make the idtax. taxid change.  
Even though it updated the database it did not send me to sopregistered.php after the database was updated like it should. The sopregistered.php file is in the same directory.

If I make the other change you suggested
if(!empty($_POST['UserName']) && !empty($_POST['Password1']) && !empty($_POST['Passwprd2'])
it breaks the code on line 8.  


 
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 49

Expert Comment

by:Roonaan
ID: 16878483
The if(!empty() structure was a partial example, not a full line. You have to make sure that you have an additional closing anchor at the end:

if( !empty($_ POST['UserName']) && !empty($_POST['Password1']) && .... && !empty($_POST['taxid']) ) {
  //code.
}

As to your question on the header redirect, I am not fully sure which earlier line might be preventing the redirect.

Try starting your code with:
<?php
  error_reporting(E_ALL);
  ini_set('display_errors',1);
  session_start();

Kind regards,

-r-
0
 

Author Comment

by:acicalla
ID: 16878987
I entered that previous line like this

if(!empty($_POST['UserName']) && !empty($_POST['Password1']) && !empty($_POST['Passwprd2']) && !empty($_POST['Email'])&& !empty($_POST['Name'])&& !empty($_POST['country'])&& !empty($_POST['State'])&& !empty($_POST['City'])&& !empty($_POST['Zipcode'])&& !empty($_POST['Address'])&& !empty($_POST['phone'])&& !empty($_POST['company'])&& !empty($_POST['checkbox']) && !($_POST['Country']==60 && !empty($_POST['taxid'])){

When I got the error.


also I entered this
error_reporting(E_ALL);
  ini_set('display_errors',1);


and I don't any error back. It just updates the account sends the email and returns back to the same page.
0
 
LVL 49

Accepted Solution

by:
Roonaan earned 500 total points
ID: 16880127
I don't see reasons why your header redirect should not work.

Try what happens when you put in an additional exit():
header ("Location: sopregistered.php");
exit();

-r-
0
 

Author Comment

by:acicalla
ID: 16882130
Thank you for the help!!! That last exit fixed the redirect as well.
0
 
LVL 49

Expert Comment

by:Roonaan
ID: 16883249
Yes, but is the email still being send? The email sending code is executed after the header-redirect isn't it?

-r-
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now