Jump to content

[SOLVED] Some PHP Help please


RSprinkel

Recommended Posts

Hi All,

 

I have a online membership website and when a member sends me a payment via money order, check, etc.  I go to an admin form and enter the data into the form saying it was paid.  When I click the submit button it processes the information into the database (MySQL) and what I would like is to be able to have that process actually email that specific member a notice to let them know payment has been received.

 

Here is the process code that I am currently using:

 

<?php

include 'db.php';

$username = $_POST['username'];
$date = $_POST['date'];
$amount = $_POST['amount'];
$paidby = $_POST['paidby'];
$next = $_POST['next'];
$comments = $_POST['comments'];

$username = stripslashes($username);
$date = stripslashes($date);
$amount = stripslashes($amount);
$paidby = stripslashes($paidby);
$comments = stripslashes($comments);

//insert info into dues table
$sql = mysql_query ("INSERT INTO dues (username, date, amount, paidby, next, comments)
VALUES('$username','$date','$amount','$paidby','$next','$comments')") or die (mysql_error());
if(!$sql){
echo 'There has been an error processing your Payment Received. Please contact the webmaster.';
}

mysql_close($connection);

//show user decision page
include 'dues_filed.php';
?>

 

Thanks much in advance.

 

RSprinkel

Link to comment
Share on other sites

Ok with me being a newb at such stuff.  Since there is no email address listed on this form or in that db, would I have to do a cross reference to another db to get that usernames email address for it to send that user an email?

 

Thanks much for your reply.

 

RSprinkel

Link to comment
Share on other sites

after your query just send the email. I use an html e-mail but you can use whatever you like. You would also have to pull the e-mail address from somewhere.

 

<?php
//insert info into dues table
$sql = mysql_query ("INSERT INTO dues (username, date, amount, paidby, next, comments)
VALUES('$username','$date','$amount','$paidby','$next','$comments')") or die (mysql_error());
if(!$sql){
echo 'There has been an error processing your Payment Received. Please contact the webmaster.';
} else {
echo 'Payment status updates<br>';
$bcc = "someemail@somedomain.com";
$to = "";
$subject = "Payment for membership to xxxxxxx";
$headers = "From: <me@mywebspace.com>\r\n";
$headers .= "BCC: $bcc\r\n";

//leave the next 2 lines alone
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

$message = '<html><body>';
$message .= '<table width="753" align="center">';
$message .= '<tr>';
$message .= '<td align="center"><span class="style2">Your payment has been accepted. blah blah blah<br></td>';
$message .= '</tr>';
$message .= '</table>';
$message .= '</body></html>';

if(!mail($to,$subject,$message,$headers)){
echo "could not send e-mail";
} else {
echo "E-mail sent";
}
}

mysql_close($connection);

Link to comment
Share on other sites

Yes, you're going to need to pull their email address from the other database.

 

 

Thanks for your reply

 

 

Ok hmm thats the problem.  I guess I will have to figure that one out.  As the way it is set up it has a drop down list of the members names that I choose from and I am not too sure how to get that data to display on the dues page.

 

These are scripts that have been given to me over the past year and I am trying to modify them to my needs and I am not a real good php editor at this time.

 

Thanks to everyone else who replied with the help.  Very Much Appreciated.  :)

Link to comment
Share on other sites

Ok I can't figure this out.  I have tried a few things with the Dues entry page to pull the email address out of the same database as the user I am entering the dues from and to no avail I am not getting anything.  The email addy is in the same database as the user.

 

Anyways this is the code that I select the user from.

 

 <table cellpadding="10" cellspacing="0" align="center" style="font-size: 8pt">
   <tr>
     <td align="left" valign="top">Username</td>
     <td>Choose a user: <select name="username">
<?php
// assumes database connection already exists
$query = "SELECT username from users";
$result = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query);
while ($row = mysql_fetch_array($result)) {
    echo "<option value='". $row['username']. "'>". $row['username']. "</option>\n";
} // close the loop, dummy
?>
</select></td> 

   <tr>
     <td align="left" valign="top">Date of Receipt<br>("mm/dd/yy")</td>
     <td><input name="date" type="text" id="date" value=""></td>
   </tr>
   <tr>
     <td align="left" valign="top">Amount</td>
     <td><input name="amount" type="text" id="amount" value=""></td>
   </tr>
   <tr>
     <td align="left" valign="top">Payment by</td>
     <td><input name="paidby" type="text" id="paidby" value=""></td>
   </tr>
   <tr>
     <td align="left" valign="top">Next Payment Due</td>
     <td><input name="next" type="text" id="next" value=""></td>
   </tr>
   <tr> 
      <td align="left" valign="top">Comments:</td>
      <td><textarea name="comments" id="comments"></textarea></td>
    </tr>
   <td align="left" valign="top"> </td>
      <td><input type="submit" name="Submit" value="File Payment Received!"></td>
    </tr>
</table>

 

I can't for the life of me figure out how to get the user email addy to display to where I can send an email.  I would like to have the email addy displayed to make sure the email is sent to the proper person.

 

Any help is very much appreciated.

 

Sorry for being such a newb.  :(

 

RSprinkel

Link to comment
Share on other sites

OK what you need to do is select the user you want to edit first then get the information you need to pass on to the insert.

 

<?php
if(isset($_POST['username'])){
$username = $_POST['username'];
// assumes database connection already exists
$query = "SELECT email from users WHERE username = '$username'";
$result = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query);
$row = mysql_fetch_array($result);
$email = $row['email'];
?>
<form method=post action="">
<input type=hidden name=email value="<? echo $email; ?>">
<input type=hidden name=username value="<? echo $username; ?>">
   <tr>
     <td colspan=2 align=center>Entering dues for <? echo $username; ?> with E-Mail address <? echo $email; ?></td>
   </tr>
   <tr>
     <td align="left" valign="top">Date of Receipt<br>("mm/dd/yy")</td>
     <td><input name="date" type="text" id="date" value=""></td>
   </tr>
   <tr>
     <td align="left" valign="top">Amount</td>
     <td><input name="amount" type="text" id="amount" value=""></td>
   </tr>
   <tr>
     <td align="left" valign="top">Payment by</td>
     <td><input name="paidby" type="text" id="paidby" value=""></td>
   </tr>
   <tr>
     <td align="left" valign="top">Next Payment Due</td>
     <td><input name="next" type="text" id="next" value=""></td>
   </tr>
   <tr>
      <td align="left" valign="top">Comments:</td>
      <td><textarea name="comments" id="comments"></textarea></td>
    </tr>
   <td align="left" valign="top"> </td>
      <td><input type="submit" name="Submit" value="File Payment Received!"></td>
    </tr>
</table>
</form>
<?php
} else {
?>
<form method=post action="">
   <tr>
     <td align="left" valign="top">Username</td>
     <td>Choose a user: <select name="username">
<?php
// assumes database connection already exists
$query = "SELECT username from users";
$result = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query);
while ($row = mysql_fetch_array($result)) {
    echo "<option value='". $row['username']. "'>". $row['username']. "</option>\n";
} // close the loop, dummy
?>
</select></td>
   <tr>
    </tr>
   <td align="left" valign="top"> </td>
      <td><input type="submit" name="Submit" value="File Payment Received!"></td>
    </tr>
    </form>
</table>
<?php
}
?>

 

Ray

Link to comment
Share on other sites

Here is the entire code on one page if you want it.

 

<table cellpadding="10" cellspacing="0" align="center" style="font-size: 8pt">
<?php
include 'db.php';
if(isset($_POST['Submit'])){
$username = $_POST['username'];
$date = $_POST['date'];
$amount = $_POST['amount'];
$paidby = $_POST['paidby'];
$next = $_POST['next'];
$comments = $_POST['comments'];
$email = $_POST['email'];

$username = stripslashes($username);
$date = stripslashes($date);
$amount = stripslashes($amount);
$paidby = stripslashes($paidby);
$comments = stripslashes($comments);
//insert info into dues table
$sql = mysql_query ("INSERT INTO dues (username, date, amount, paidby, next, comments)
VALUES('$username','$date','$amount','$paidby','$next','$comments')") or die (mysql_error());
if(!$sql){
echo '<tr><td>There has been an error processing your Payment Received. Please contact the webmaster.</td></tr></table>';
} else {
echo '<tr><td>Payment status updated<br>\n';
$bcc = $email;
$to = "";
$subject = "Payment for membership to xxxxxxx";
$headers = "From: <me@mywebspace.com>\r\n";
$headers .= "BCC: $bcc\r\n";

//leave the next 2 lines alone
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

$message = '<html><body>';
$message .= '<table width="753" align="center">';
$message .= '<tr>';
$message .= '<td align="center"><span class="style2">Your payment has been accepted. blah blah blah<br></td>';
$message .= '</tr>';
$message .= '</table>';
$message .= '</body></html>';

if(!mail($to,$subject,$message,$headers)){
echo "Could not send e-mail</td></tr></table>";
} else {
echo "E-mail sent</td></tr></table>";
}
}

mysql_close($connection);

} else {
  if(isset($_POST['user_select'])){
  $username = $_POST['username'];
  // assumes database connection already exists
  $query = "SELECT email FROM users WHERE username = '$username'";
  $result = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query);
  $row = mysql_fetch_array($result);
  $email = $row['email'];
?>
<form method=post action="">
<input type=hidden name=email value="<? echo $email; ?>">
<input type=hidden name=username value="<? echo $username; ?>">
   <tr>
     <td colspan=2 align=center>Entering dues for <? echo $username; ?> with E-Mail address <? echo $email; ?></td>
   </tr>
   <tr>
     <td align="left" valign="top">Date of Receipt<br>("mm/dd/yy")</td>
     <td><input name="date" type="text" id="date" value=""></td>
   </tr>
   <tr>
     <td align="left" valign="top">Amount</td>
     <td><input name="amount" type="text" id="amount" value=""></td>
   </tr>
   <tr>
     <td align="left" valign="top">Payment by</td>
     <td><input name="paidby" type="text" id="paidby" value=""></td>
   </tr>
   <tr>
     <td align="left" valign="top">Next Payment Due</td>
     <td><input name="next" type="text" id="next" value=""></td>
   </tr>
   <tr>
      <td align="left" valign="top">Comments:</td>
      <td><textarea name="comments" id="comments"></textarea></td>
    </tr>
   <td align="left" valign="top"> </td>
      <td><input type="submit" name="Submit" value="File Payment Received!"></td>
    </tr>
</table>
</form>
<?php
  } else {
?>
<form method=post action="">
<input type=hidden name=user_select value=1 />
   <tr>
     <td align="left" valign="top">Username</td>
     <td>Choose a user: <select name="username">
<?php
  // assumes database connection already exists
  $query = "SELECT username FROM users";
  $result = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query);
    while ($row = mysql_fetch_array($result)) {
    echo "<option value='". $row['username']. "'>". $row['username']. "</option>\n";
    } // close the loop, dummy
?>
</select></td>
   <tr>
    </tr>
   <td align="left" valign="top"> </td>
      <td><input type="submit" value="Enter Dues!"></td>
    </tr>
    </form>
</table>
<?php
  }
}
?>

 

Ray

Link to comment
Share on other sites

Ok I just did a test and did not send or should I say email me as the user the information.

 

This is my email setup at the bottom of the dues_process.php

 

//insert info into dues table
$sql = mysql_query ("INSERT INTO dues (username, date, amount, paidby, next, comments, email)
VALUES('$username','$date','$amount','$paidby','$next','$comments','$email')") or die (mysql_error());
if(!$sql){
echo 'There has been an error processing your Payment Received. Please contact the webmaster.';
}

// Let's mail the user!
$subject = "Your Dues has been received!";
$message = "Dear $username,
I am letting you know that your dues has been received and processed.  Your next dues payment is due on $next
Here is your Payment information received today:
Date Received: $date
Amount Received: $amount
Paid By: $paidby
Comments: $comments



Thanks!
   LowRider
   League Owner/Admin

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

mail($email_address, $subject, $message, "From: Membership<site@email>\nX-Mailer: PHP/" . phpversion());

Link to comment
Share on other sites

it's just a way to make the e-mail look pretty. You can add links to pictures and other stuff by making the e-mail html.

 

try this

 

$message = "<html><body>";
$message .= "<table width=753 align=center>";
$message .= "<tr>";
$message .= "<td>Dear $username,<br>
I am letting you know that your dues has been received and processed.  Your next dues payment is due on $next<br>
Here is your Payment information received today:<br>
Date Received: $date<br>
Amount Received: $amount<br>
Paid By: $paidby<br>
    Comments: $comments<br><br><br>
Thanks!<br /><br />
    LowRider<br />
    League Owner/Admin<br /><br />
This is an automated response, please do not reply!</td>";
$message .= "</tr>";
$message .= "</table>";
$message .= "</body></html>";

Link to comment
Share on other sites

Looks AWESOME!

 

Thank you very very much.

 

Very Much Appreciated.

 

Now one small issue that I see and it is no biggie, but when I click the submit. and I am taking it I get a confirmation page as it shows:

 

Payment status updated

\nE-mail sent

 

 

How do I get rid of the \n before E-Mail sent.

 

I see it here:

echo '<tr><td>Payment status updated<br>\n';

 

And when I try to remove the \n I get the following error:

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/domain/public_html/Join/Admin/dues.php on line 79

 

I mean it isn't a big deal, just curious. 

 

Link to comment
Share on other sites

Can you post the few line before and after, or the whole thing.

 

The \n is a carraige return when writing scripts. That way if you were to right click on a web page and click view source, you will get a properly formatted code. if you do not add the \n you would have one damn long line of code.  Also the \n only works between double quotes and not single quotes.

 

try this

 

echo '<tr><td>Payment status updated<br>';

 

Ray

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.