Jump to content

php form won't submit info.


ethan6

Recommended Posts

Ok, so i have a very simple PHP contact form for submitting info on my website http://itronicsrepair.com/contact.php

 

However, when you click submit, it doesn't actually submit the data.

 

I had this exact same form on my last hosting server, but when i put it on here, it no longer works.  I have double checked that I have included all the includes, etc.

 

Here is the code:

<?php include("configure_contact.php");
if (isset($_POST['submit'])) {

echo $msg;
if (!$pass) {
if (!isset($email))
echo "Error, please re-send $fname" ;

$todayis = date("l, F j, Y, g:i a") ;

$message ="$todayis [EST] \n";
$message .="First Name: $fname \n";
$message .="Last Name: $lname \n";
$message .="Address1: $address1 \n";
$message .="Address2: $address2 \n";
$message .="City: $city \n";
$message .="State: $state \n";
$message .="Zip Code: $zip \n";
$message .="Email: $sendemail \n";
$message .="Phone: $phone \n";
$message .="iPod Generation: $gen \n";
$message .="Comments: $comments \n";

$from = "From: $sendemail\r\n";

if ($email != "")
mail($email, $subject, $message, $from);

?>



<table width="80% align="center">
<tr>
  <td>
   <center><img src="img/tick.jpg"></center>
   <b><p align="center">
    Date Sent: <?php echo $todayis ?>
   <br>
    Sent By: <?php echo $fname ?> ( <?php echo $sendemail ?> )
   <br>
   <br>Thank you, your comment has been submitted.
   <br>
   <a href="index.php"> Return to Main Page </a>
  </td>
</tr>
</table>
<?php exit();}} ?>


<link href="style.txt" rel="stylesheet" type="text/css">
<table width="80%"  border="0" cellpadding="5">
<tr>
  <th align="left" valign="top" scope="col">
   <p align="left" class="stdtxtlocate"><h4></h4>
  </th>
</tr>
<tr>
  <th align="left" valign="top" scope="col">
   <form action="" method="post">
    <table width="80%" border="0" cellpadding="5">

     <tr>
      <?php if ($fnameq == true) { ?><td><div align="left">First Name</div><br><input name="fname" type="text" size="25" maxlength="40" value="<?php echo $_POST['fname']; ?>" class="<?php echo $style1; ?>">
      </td><?php } ?>
      <?php if ($lnameq == true) { ?><td><div align="left">Last Name</div><br><input name="lname" type="text" size="25" maxlength="40" value="<?php echo $_POST['lname']; ?>" class="<?php echo $style2; ?>">
      </td><?php } ?>
     </tr>

     <tr>
      <?php if ($address1q == true) { ?><td><div align="left">Address 1</div><br><input name="address1" type="text" size="25" maxlength="40" value="<?php echo $_POST['address1']; ?>" class="<?php echo $style3; ?>">
      </td><?php } ?>
      <?php if ($address2q == true) { ?><td><div align="left">Address 2</div><br><input name="address2" type="text" size="25" maxlength="40" value="<?php echo $_POST['address2']; ?>" class="<?php echo $style4; ?>">
      </td><?php } ?>
     </tr>

     <tr>
      <?php if ($cityq == true) { ?><td><div align="left">City</div><br><input name="city" type="text" size="25" maxlength="40" value="<?php echo $_POST['city']; ?>" class="<?php echo $style5; ?>">
      </td><?php } ?>
      <?php if ($stateq == true) { ?><td><div align="left">State</div><br><input name="state" type="text" size="25" maxlength="40" value="<?php echo $_POST['state']; ?>" class="<?php echo $style6; ?>">
      </td><?php } ?>
     </tr>

     <tr>
      <?php if ($zipq == true) { ?><td><div align="left">Zip Code</div><br><input name="zip" type="text" size="25" maxlength="40" value="<?php echo $_POST['zip']; ?>" class="<?php echo $style7; ?>">
      </td><?php } ?>
      <?php if ($sendemailq == true) { ?><td><div align="left">Email</div><br><input name="sendemail" type="text" size="25" maxlength="40" value="<?php echo $_POST['sendemail']; ?>" class="<?php echo $style8; ?>">
      </td><?php } ?>
     </tr>

     <tr>
      <?php if ($phoneq == true) { ?><td><div align="left">Phone</div><br><input name="phone" type="text" size="25" maxlength="40" value="<?php echo $_POST['phone']; ?>" class="<?php echo $style9; ?>">
      </td><?php } ?>
      <?php if ($genq == true) { ?><td><div align="left">iPod Generation</div><br><input name="gen" type="text" size="25" maxlength="40" value="<?php echo $_POST['gen']; ?>" class="<?php echo $style10; ?>">
      </td><?php } ?>
     </tr>

     <tr>
     <?php if ($commentsq == true) { ?><td><div align="left">Comments</div><br><textarea name="comments" rows="10" cols="35" class="<?php echo $style11; ?>"><?php echo $_POST['comments']; ?></textarea>
      </td><?php } ?>
     </tr>

     <tr>
     <td><b>Email MUST be valid for a reply.</b><br><input type="submit" name="submit" value="Submit Comments"></td>
      <td> </td>
     </tr>
    </table>
   </form>
  </th>
</tr>
</table>

 

 

Thank you for any help!

 

ps. all of my forms on my site stopped submitting the info after i moved servers.

Link to comment
Share on other sites

Aeroswat has probably pin pointed your problem. What version of PHP did your old and new server have? If you had an older version, the setting register_globals was probably set on, which would make the code work. This setting has been deprecated as of php 5, removed as of 6.

 

http://php.net/manual/en/ini.core.php

 

(search for the register_globals entry for more info)

Link to comment
Share on other sites

Your code replies on a setting called register_globals to be enabled in order for it to work properly, your new server most probably has this setting disabled. register_globals  has been disabled since the release of PHP4.2 (which was released way back in 2002).

 

Basically all you need to do is, instead of using the variable $name_of_from_field to grab the value from one of your form fields, you'd instead use the $_POST superglobal, eg $_POST['msg'] to get the value from the form field named as msg, for the form field named as email you'd use $_POST['email']

Link to comment
Share on other sites

yes that would make sense.

 

I also played around with my code a bit and found out this:

 

when I have this code at the top of the page, it doesn't work, but if i delete it, it does work:

 

<?php
// Include MySQL class
require_once('inc/mysql.class.php');
// Include database connection
require_once('inc/global.inc.php');
// Include functions
require_once('inc/functions.inc.php');
// Start the session
session_start();
?>

 

any ideas why that would be?  I'm guessing something with the session_start() is screwing it up?

Link to comment
Share on other sites

the part that doesn't seem to be working even after i change most vars to $_POST['var'], is the submit button.

 

the button here:

 
<input type="submit" name="submit" value="Submit Comments"></td>

 

doesn't seem to give a value to here:

if (isset($_POST['submit'])) {

 

because what's after the isset doesn't get "triggered".  But I tested, and $_POST['submit'] does have a value after the form is submitted.. so what's up with the isset?

 

thanks again for the help :)

Link to comment
Share on other sites

Add the following lines at the top of your page.

ini_set('display_errors', 1);
error_reporting(E_ALL);

 

It should display any errors

 

I added that to the top and it gave this error:

Parse error: syntax error, unexpected T_STRING in /home/itroni5/public_html/contact.php on line 5

 

.. line 5 is:

require_once('inc/mysql.class.php');

 

which shouldn't be wrong, it's worked fine before.

Link to comment
Share on other sites

Yeah, if I take this top bit off, it seems to work fine.  why would that be?

<?php
// Include MySQL class
require_once('inc/mysql.class.php');
// Include database connection
require_once('inc/global.inc.php');
// Include functions
require_once('inc/functions.inc.php');
?>

Link to comment
Share on other sites

Strange error, I can't see anything wrong with that line. Maybe the error is caused further up. Post lines 1 - 5 here.

 

well it's only when I add that extra "show error" code.

 

And those top lines about includes are what cause the form not to go through.. any ideas why?

Link to comment
Share on other sites

Make sure you copied the two lines properly. I know I accidentally added a quote where it shouldn't be but I did update my post. The correct lines are

Add the following lines at the top of your page.

ini_set('display_errors', 1);
error_reporting(E_ALL);

 

It should display any errors

Link to comment
Share on other sites

Make sure you copied the two lines properly. I know I accidentally added a quote where it shouldn't be but I did update my post. The correct lines are

Add the following lines at the top of your page.

ini_set('display_errors', 1);
error_reporting(E_ALL);

 

It should display any errors

 

thanks, got it :P

 

..i think i'm going to just take out these lines and it seems to work fine then:

// Include MySQL class
require_once('inc/mysql.class.php');
// Include database connection
require_once('inc/global.inc.php');
// Include functions
require_once('inc/functions.inc.php');

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.