Jump to content

coding help


jamichelli

Recommended Posts

I've been working on a form off and on for quite a while now and can't seem to get it to submit.  I have another page that has a form with the same coding basics and submits like it's supposed to every time, yet all the other pages will validate but not submit.  I'm about to pull my hair out trying to diagnose the problem.  Is there anyone who would be willing to take a look at my coding to see if they can pinpoint the problem?  Any help on this would be appreciated!

Link to comment
Share on other sites

I was trying to avoid posting the code here as it is quite extensive, but since you asked...

 

<?php
if ($con = mysql_connect("mydb.dbsite.com","dbname","dbpassword")) {
  mysql_select_db("dbname");
} else {
  die('Could not connect: ' . mysql_error());
}

$opMode='gather'; //WHICH SECTION OF SCRIPT TO EXECUTE
$strMsg='';
include('inc_arrays.php');
// GATHER DATA FROM THE FORM
$usrFullName=@$_POST['full_name'];
$usrCity=@$_POST['city'];
$usrAddress1=@$_POST['address1'];
$usrAddress2=@$_POST['address2'];
$usrState=@$_POST['state'];
$usrZip=@$_POST['zip'];
$usrPhone=@$_POST['phone'];
$usrAltPhone=@$_POST['altphone'];
$usrEmail=@$_POST['email'];
$usrAltEmail=@$_POST['altemail'];
$usrTimeToContact=intval(@$_POST['time_to_contact']);
$usrHowFindUs=intval(@$_POST['how_find_us']);

if (isset($_POST['subedit'])) {
  $opMode='gather';
}
if (isset($_POST['subapprove'])) {
  if (mysql_query("INSERT INTO contact_info (full_name, address1, address2, city, state, zip, phone, altphone, email, altemail, time_to_contact, how_find_us) 
VALUES 
('$_POST[full_name]','$_POST[address1]','$_POST[address2]','$_POST[city]','$_POST[state]','$_POST[zip]','$_POST[phone]','$_POST[altphone]','$_POST[email]','$_POST[altemail]','$_POST[time_to_contact]','$_POST[how_find_us]')")) {
  	$opMode='added';
header("Location:http://www.mywebiste.com/endpage.php");
exit;
  } else {
  	$opMode='fail';
  }
}

if (isset($_POST['subdone'])) {
  //NOW WE HAVE TO VALIDATE THE DATA
  $tmp='Please check: ';
  if ($usrFullName!='') {
        if ($usrAddress1!='') {
              if ($usrCity!='') {
                    if (strlen($usrState)==2) {
                  if ($usrZip!='') {
        	        if ($usrPhone!='') {
        		      if ($usrTimeToContact>0) {
        		            if ($usrHowFindUs>0) {
        			          $opMode='verify';
                    	  		} else {$strMsg=$tmp.'How Did You Find Us?';}
        		      } else {$strMsg=$tmp.'Best Time To Contact?';}
        	        } else {$strMsg=$tmp.'Phone';}
                  } else {$strMsg=$tmp.'Zip';}
                    } else {$strMsg=$tmp.'State';}
              } else {$strMsg=$tmp.'City';}
        } else {$strMsg=$tmp.'Address (line 1)';}
  } else {$strMsg=$tmp.'Full Name';}
}

?>
<html>
<head>
  <title>MY WEBSITE | CONTACT INFO</title>
</head>
<body>
<form name="contact" id="contact" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
  <p class="req"><b><?php echo $strMsg; ?></b></p>
<table class="center">
<?php if ($opMode=='gather') { ?>

    <th colspan="8" class="headerlabel"><b>Step 1</b></th>

    <tr>
     <td colspan="2" class="labelcell"><label for="full_name">Full Name</label></td>
     <td colspan="2" class="fieldcell"><input type="text" name="full_name" size="40" tabindex="1" value="<?php echo stripslashes($usrFullName); ?>"></td>
    </tr>
   
    <tr>
     <td colspan="2" class="labelcell"><label for="address1">Address (Line 1)</label></td>
     <td colspan="2" class="fieldcell"><input type="text" name="address1" size="40" tabindex="2" value="<?php echo stripslashes($usrAddress1); ?>"></td>
    </tr>

<tr><td colspan="8">     
<input type="submit" tabindex="13" name="subdone" value="Verify" /></td></tr></table>

<?php } else if ($opMode=='verify') { ?>
<table>
    <th colspan="16" class="headerlabel"><b>Please verify your information below:</b></th>
    
    <tr>
     <td colspan="2" class="labelcell"><label for="full_name">Full Name</label></td>
     <td colspan="2" class="resultscell"><?php echo htmlentities(stripslashes($usrFullName)); ?><input type="hidden" name="full_name" value="<?php echo stripslashes($usrFullName); ?>"></td>
     </tr>
    
    <tr>
    <td colspan="2" class="labelcell"><label for="address1">Address (Line 1)</label></td>
     <td colspan="2" class="resultscell"><?php echo htmlentities(stripslashes($usrAddress1)); ?><input type="hidden" name="address1" value="<?php echo stripslashes($usrAddress1); ?>"></td>
    </tr>

    <tr>
<td colspan="4">    
    <input type="submit" name="subedit" value="Back To Edit" /> or <input type="submit" name="subapprove" value="On To Step 2" />
</td>
    </tr>

<?php } else if ($opMode=='added') { ?>
<p class="submitmessage"><b>Thank You! One Of Our Representatives Will Be Contacting You Shortly!</b></p>
<p class="submitmessage"><input type="button" value="Home" onclick="location.href='http://www.mywebsite.com/home.php'" /></p>
<?php } else if ($opMode=='fail') { ?>
<p class="submitmessage"><b>Internal Error! Your Information Could Not Be Saved, Please Email<a href="mailto:mymail@mywebsite.com?subject=Property and loan info">mymail@mywebsite.com</a></b></p><p class="submitmessage"><b>We Are Sorry For The Inconvenience.</b></p>
<p class="submitmessage"><input type="button" value="Home" onclick="location.href='http://www.mywebsite.com/home.php'" /></p>
<?php } else if ($opMode=='fatal') { ?>
<?php } ?>
</table>
  </form>
</body>

</html>
<?php
  function buildSelect($arr,$sel) {
    $htm='';
    foreach ($arr as $k => $v) {
      $htm.='<option value="'.$k.'"'.($k==$sel ? ' selected' : '').'>'.$v.'</option>';
    }
    return $htm;
  }
?>

I did omit a lot of the code in the form as it's just repetitive and you get the idea.  Any input as to what could be wrong here?  Like I said, I have another form that is even more complicated than this, but using the same coding and it validates and submits just fine...this one, on the other hand, does not submit after validating.  All I get is the "Internal Error!" message and nothing going into my db.  Again, thanks for any input!

Link to comment
Share on other sites

try run this and it should help you debug it,

it'll print all the variables in the $_POST array.

and then it will echo the string you are putting into your database so you can check that its right.

 

also on a side not,

you shouldnt be using the $_POST in the SQL statement, you should put them into variables first and then pull them in... so you can do mysql_real_escape_string etc to them.

 

<?php
if ($con = mysql_connect("mydb.dbsite.com","dbname","dbpassword")) {
  mysql_select_db("dbname");
} else {
  die('Could not connect: ' . mysql_error());
}

$opMode='gather'; //WHICH SECTION OF SCRIPT TO EXECUTE
$strMsg='';
include('inc_arrays.php');
// GATHER DATA FROM THE FORM
$usrFullName=@$_POST['full_name'];
$usrCity=@$_POST['city'];
$usrAddress1=@$_POST['address1'];
$usrAddress2=@$_POST['address2'];
$usrState=@$_POST['state'];
$usrZip=@$_POST['zip'];
$usrPhone=@$_POST['phone'];
$usrAltPhone=@$_POST['altphone'];
$usrEmail=@$_POST['email'];
$usrAltEmail=@$_POST['altemail'];
$usrTimeToContact=intval(@$_POST['time_to_contact']);
$usrHowFindUs=intval(@$_POST['how_find_us']);

if (isset($_POST['subedit'])) {
  $opMode='gather';
}
if (isset($_POST['subapprove'])) {

$sql = "INSERT INTO contact_info (full_name, address1, address2, city, state, zip, phone, altphone, email, altemail, time_to_contact, how_find_us) 
VALUES 
('$_POST[full_name]','$_POST[address1]','$_POST[address2]','$_POST[city]','$_POST[state]','$_POST[zip]','$_POST[phone]','$_POST[altphone]','$_POST[email]','$_POST[altemail]','$_POST[time_to_contact]','$_POST[how_find_us]')";
print_r($_POST);
echo "<br />".$sql;
exit();

  	$opMode='added';
header("Location:http://www.mywebiste.com/endpage.php");
exit;
  } else {
  	$opMode='fail';
  }
}

if (isset($_POST['subdone'])) {
  //NOW WE HAVE TO VALIDATE THE DATA
  $tmp='Please check: ';
  if ($usrFullName!='') {
        if ($usrAddress1!='') {
              if ($usrCity!='') {
                    if (strlen($usrState)==2) {
                  if ($usrZip!='') {
        	        if ($usrPhone!='') {
        		      if ($usrTimeToContact>0) {
        		            if ($usrHowFindUs>0) {
        			          $opMode='verify';
                    	  		} else {$strMsg=$tmp.'How Did You Find Us?';}
        		      } else {$strMsg=$tmp.'Best Time To Contact?';}
        	        } else {$strMsg=$tmp.'Phone';}
                  } else {$strMsg=$tmp.'Zip';}
                    } else {$strMsg=$tmp.'State';}
              } else {$strMsg=$tmp.'City';}
        } else {$strMsg=$tmp.'Address (line 1)';}
  } else {$strMsg=$tmp.'Full Name';}
}

?>
<html>
<head>
  <title>MY WEBSITE | CONTACT INFO</title>
</head>
<body>
<form name="contact" id="contact" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
  <p class="req"><b><?php echo $strMsg; ?></b></p>
<table class="center">
<?php if ($opMode=='gather') { ?>

    <th colspan="8" class="headerlabel"><b>Step 1</b></th>

    <tr>
     <td colspan="2" class="labelcell"><label for="full_name">Full Name</label></td>
     <td colspan="2" class="fieldcell"><input type="text" name="full_name" size="40" tabindex="1" value="<?php echo stripslashes($usrFullName); ?>"></td>
    </tr>
   
    <tr>
     <td colspan="2" class="labelcell"><label for="address1">Address (Line 1)</label></td>
     <td colspan="2" class="fieldcell"><input type="text" name="address1" size="40" tabindex="2" value="<?php echo stripslashes($usrAddress1); ?>"></td>
    </tr>

<tr><td colspan="8">     
<input type="submit" tabindex="13" name="subdone" value="Verify" /></td></tr></table>

<?php } else if ($opMode=='verify') { ?>
<table>
    <th colspan="16" class="headerlabel"><b>Please verify your information below:</b></th>
    
    <tr>
     <td colspan="2" class="labelcell"><label for="full_name">Full Name</label></td>
     <td colspan="2" class="resultscell"><?php echo htmlentities(stripslashes($usrFullName)); ?><input type="hidden" name="full_name" value="<?php echo stripslashes($usrFullName); ?>"></td>
     </tr>
    
    <tr>
    <td colspan="2" class="labelcell"><label for="address1">Address (Line 1)</label></td>
     <td colspan="2" class="resultscell"><?php echo htmlentities(stripslashes($usrAddress1)); ?><input type="hidden" name="address1" value="<?php echo stripslashes($usrAddress1); ?>"></td>
    </tr>

    <tr>
<td colspan="4">    
    <input type="submit" name="subedit" value="Back To Edit" /> or <input type="submit" name="subapprove" value="On To Step 2" />
</td>
    </tr>

<?php } else if ($opMode=='added') { ?>
<p class="submitmessage"><b>Thank You! One Of Our Representatives Will Be Contacting You Shortly!</b></p>
<p class="submitmessage"><input type="button" value="Home" onclick="location.href='http://www.mywebsite.com/home.php'" /></p>
<?php } else if ($opMode=='fail') { ?>
<p class="submitmessage"><b>Internal Error! Your Information Could Not Be Saved, Please Email<a href="mailto:mymail@mywebsite.com?subject=Property and loan info">mymail@mywebsite.com</a></b></p><p class="submitmessage"><b>We Are Sorry For The Inconvenience.</b></p>
<p class="submitmessage"><input type="button" value="Home" onclick="location.href='http://www.mywebsite.com/home.php'" /></p>
<?php } else if ($opMode=='fatal') { ?>
<?php } ?>
</table>
  </form>
</body>

</html>
<?php
  function buildSelect($arr,$sel) {
    $htm='';
    foreach ($arr as $k => $v) {
      $htm.='<option value="'.$k.'"'.($k==$sel ? ' selected' : '').'>'.$v.'</option>';
    }
    return $htm;
  }
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.