Jump to content

Recommended Posts

Hi everyone!

 

I AM HAVING MAJOR TROUBLE AND REALLY NEED SOME HELP.  I HAVE A FORM THAT ALLOWS THE USER TO CLICK AND BUTTON TO BECOME A FAN OF A BUSINESS. WHEN THE BUTTON IS CLICKED, THE INFORMATION ABOUT THE USER IN SENT TO THE DATABASE AND AN EMAIL IS SENT TO THE BUSINESS SAYING THAT THEY HAVE A NEW FAN.  THE PROBLEM IS WHEN I INCLUDED THE CODE: (isset($_POST['yourfan'])) TO CHECK IF THE BUTTON WAS CLICKED, THE FORM DOES NOT SEND THE EMAIL TO THE BUSINESS BUT WHEN I REMOVE THAT CODE, AN EMAIL IS SENT TO THE BUSINESS WHETHER OR NOT THE BUTTON IS PRESSED.  WHAT DO I DO? I ONLY WANT THE EMAIL SENT WHEN THE IS BUTTON CLICKED. THE FULL CODE IS BELOW, PLEASE HELP!!!  ???:

 

<form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="fan" id="fan">

 

<input name="yourfan" type="image" value="Submit" onClick="<?php

(isset($_POST['yourfan']))

{

$to = $row_Bus['Email'];

            $subject = 'You Have A Fan !';

$body = "blah...blah...blah.... ";

$headers = "From: admin@mysite.com\r\n";

$headers .= "MIME-Version: 1.0\n";

$headers .= "Content-type: text/html; charset=iso-8859-1 \n";

$mail_sent = @mail( $to, $subject, $body, $headers );

}

?>;MM_popupMsg('It\'s official! You are now a fan.')" src="/FANBUT2.png" alt="Become A Fan"/>

                    </label>                 

                    <input type="hidden" name="MM_insert" value="fan" />

                    </form>

Link to comment
https://forums.phpfreaks.com/topic/155389-php-email-problem-and-submit-button/
Share on other sites

Oh ok.

 

well the thing is that the post variable yourfan won't become set unless you.. well.. post the form itself. When the page itself is loaded, the variable $_POST['yourfan'] isn't set, and unless you submit the form to the page again, it won't become set. What i would do, instead of having PHP execute with the onclick event, just set the action to a certain page (like mail.php or something) and put the code you had after onclick in that page.

Hi,

 

I removed the encrypt line and tried putting the code in an external file...mail.php and referred the action to mail.php and it what it did was send the email message but did not insert the information into the database.  Also, it also went to a page that does not exist, eg: /mail.php/profile-2.php?BusID=xxxx  I DON'T know what to do....i have been trying everything for days now and nothing works the way I need it....PLEASE HELP!!  :'(

Okay..... the mail.php is:

 

<body> <?php 
If (isset($_POST['yourfan']))
{
$to = $row_Bus['Email'];
$subject = 'You Have A Fan !';
$body = "blah...blah...blah.... ";
$headers = "From: admin@mysite.com\r\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1 \n";
$mail_sent = @mail( $to, $subject, $body, $headers ); 
} 
?>;MM_popupMsg('It\'s official! You are now a fan.')" src="/FANBUT2.png" alt="Become A Fan"/>
	</label>				
	<input type="hidden" name="MM_insert" value="fan" />
</body>
</html>

 

THE FORM CODE IS:

 

//INSERT FAN---------------------------------------------------------------------------------------------
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "fan")) {
$Fdate = date ("M. d, y");
$FANdate = $Fdate ;
  $insertSQL = sprintf("INSERT INTO BusFans (FanID, FanUname, FirstName, LastName, FanCity, FanState, FanBus, FanBusID, BusName, BusPict, BUsername, NumberFans, BusID, Category, Date, FanPict) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['memID'], "int"),
                       GetSQLValueString($_POST['username'], "text"),
                       GetSQLValueString($_POST['FirstName'], "text"),
                       GetSQLValueString($_POST['LastName'], "text"),
                       GetSQLValueString($_POST['FanCity'], "text"),
                       GetSQLValueString($_POST['FanState'], "text"),
	       GetSQLValueString($_POST['FanBus'], "text"),
		GetSQLValueString($_POST['FanBusID'], "text"),
                       GetSQLValueString($_POST['BusName'], "text"),
	 GetSQLValueString($_POST['buspict'], "text"),
		 GetSQLValueString($_POST['buser'], "text"),
	GetSQLValueString($_POST['number'], "text"),
                       GetSQLValueString($_POST['BusID'], "int"),
                       GetSQLValueString($_POST['category'], "text"),
		GetSQLValueString($FANdate, "text"),
                       GetSQLValueString($_POST['FanPict'], "text"));

  mysql_select_db($database_BUSPROFILES, $BUSPROFILES);
  $Result1 = mysql_query($insertSQL, $BUSPROFILES) or die(mysql_error());

  $insertGoTo = "/busprofile-2.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

<!--START OF FORM-->
                  <form action="mail.php<?php echo $editFormAction; ?>" method="POST" name="fan" id="fan">
                    <label>
                    <input name="username" type="hidden" id="username" value="<?php echo $row_User['Username']; ?>" />
                    <input name="memID" type="hidden" id="memID" value="<?php echo $row_User['MemID']; ?>" />
                    <input name="FirstName" type="hidden" id="FirstName" value="<?php echo $row_User['FirstName']; ?>" />
                    <input name="LastName" type="hidden" id="LastName" value="<?php echo $row_User['LastName']; ?>" />
                    <input name="BusName" type="hidden" id="BusName" value="<?php echo $row_Profile['BusName']; ?>" />
                    <input name="BusID" type="hidden" id="BusID" value="<?php echo $row_Profile['BusID']; ?>" />
                    <input name="FanPict" type="hidden" id="FanPict" value="<?php echo $row_User['MemPict']; ?>" />
                    <input name="FanCity" type="hidden" id="FanCity" value="<?php echo $row_User['City']; ?>" />
                    <input name="FanState" type="hidden" id="FanState" value="<?php echo $row_User['State']; ?>" />
                    <input name="category" type="hidden" id="category" value="<?php echo $row_Profile['Category']; ?>" />
                    <input name="buspict" type="hidden" id="buspict" value="<?php echo $row_Profile['BusImage']; ?>" />
                    <input name="FanBusID" type="hidden" id="FanBusID" value="<?php echo $row_UserProfile['BusID']; ?>" />
                    <input name="FanBus" type="hidden" id="FanBus" value="<?php echo $row_UserProfile['BusName']; ?>" />
                    <input name="buser" type="hidden" id="buser" value="<?php echo $row_Profile['Username']; ?>" />
                    <input name="number" type="hidden" id="number" value="1" />
                    <input name="BusEmail" type="hidden" id="BusEmail" value="<?php echo $row_Profile['Email']; ?>" />
<input name="yourfan" type="image" value="Submit" onClick="MM_popupMsg('It\'s official! You are now a fan.')" src="IMAGES/FANBUT2.png" alt="Become A Fan"/>
                      </label>                   
<input type="hidden" name="MM_insert" value="fan" />
                    </form>

 

Please note: I have also tried making the action just: action"mail.php" without the "echo $editFormAction" and it didn't work either.

 

Thanks in advance.

ok... first things

<body> <?php 
   If (isset($_POST['yourfan']))
   {
   $to = $row_Bus['Email'];
   $subject = 'You Have A Fan !';
$body = "blah...blah...blah.... ";
$headers = "From: admin@mysite.com\r\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1 \n";
   $mail_sent = @mail( $to, $subject, $body, $headers ); 
   } 
   ?>;MM_popupMsg('It\'s official! You are now a fan.')" src="/FANBUT2.png" alt="Become A Fan"/>
      </label>            
      <input type="hidden" name="MM_insert" value="fan" />

get rid of the stuff after the PHP... i dont even understand why it would still be there...

 

based on what you have on your form page your mail page should be something like

  If (isset($_POST['yourfan']))
   {
   $to = $_POST['BusEmail'];//or whatever the post variable which holds the target email
   $subject = 'You Have A Fan !';
$body = "blah...blah...blah.... ";
$headers = "From: admin@mysite.com\r\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1 \n";
   $mail_sent = @mail( $to, $subject, $body, $headers ); 
   } 
   ?>

 

As far as the action... i dont even understand where the variable you are using is coming from.

 

I would really suggest you learn a lot more about PHP before continuing with this project, as from what i've seen it doesnt seem like you understand it very well (no offense)

 

let me know if that helps. I hope it does

Thanks for the advice.....actually, it's my fault, the mail code I sent you was incorrect.  My actual code is exactly what you have.  I don't know why I copied the other stuff to the end of the php code.....just a mistake.  So with my mail.php being perfect...is there any advice as to why I might still be having a problem? After submitting the page it goes to: mail.

mail.php/busprofile-2.php?BusID=xxxxx

and it sends the email but does not insert the data.

from the code in the original post it looks like your trying to use php & javascript .....does your code still look like this?

<form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="fan" id="fan">
<input name="yourfan" type="image" value="Submit" onClick="<?php    
              if(isset($_POST['yourfan']))
               {
                  $to = $row_Bus['Email'];
                   $subject = 'You Have A Fan !';
                  $body = "blah...blah...blah.... ";
                  $headers = "From: admin@mysite.com\r\n";
                  $headers .= "MIME-Version: 1.0\n";
                  $headers .= "Content-type: text/html; charset=iso-8859-1 \n";
                  $mail_sent = mail( $to, $subject, $body, $headers ); 
         }//nothing echos inside your php....just a note... :-P
         ?>MM_popupMsg('It\'s official! You are now a fan.')"  src="/FANBUT2.png" alt="Become A Fan"/>
                                          </label>                   
                    <input type="hidden" name="MM_insert" value="fan" />
                    </form>

 

to make it more readable do this...

 

<?php    
              if(isset($_POST['yourfan']))
               {
                  $to = $row_Bus['Email'];
                   $subject = 'You Have A Fan !';
                  $body = "blah...blah...blah.... ";
                  $headers = "From: admin@mysite.com\r\n";
                  $headers .= "MIME-Version: 1.0\n";
                  $headers .= "Content-type: text/html; charset=iso-8859-1 \n";
                  $mail_sent = mail( $to, $subject, $body, $headers ); 
         }//nothing echos inside your php....just a note... :-P
         ?>
<form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="fan" id="fan">
<input name="yourfan" type="image" value="Submit" onClick="MM_popupMsg('It\'s official! You are now a fan.')" src="/FANBUT2.png" alt="Become A Fan"/>
                                          </label>                   
                    <input type="hidden" name="MM_insert" value="fan" />
                    </form>

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.