Jump to content


Photo

Insert record into MYSQL table as part of PHPmailer script


  • Please log in to reply
7 replies to this topic

#1 eskimowned

eskimowned
  • Members
  • PipPip
  • Member
  • 26 posts

Posted 27 September 2006 - 07:57 AM

I'm currently trying to insert a record into a database as part of the PHPmailer. This is the code I have so far but the insert row doesn't seem to be doing anything.

<?php require_once('../../Connections/Conn1.php'); ?>
<?php
mysql_select_db($database_Conn1, $Conn1);
$query_UpdateCustInfo = "SELECT * FROM Customer";
$UpdateCustInfo = mysql_query($query_UpdateCustInfo, $Conn1) or die(mysql_error());
$row_UpdateCustInfo = mysql_fetch_assoc($UpdateCustInfo);
$totalRows_UpdateCustInfo = mysql_num_rows($UpdateCustInfo);

$company = $_POST['Company'];
$first = $_POST['FirstName'];
$last = $_POST['LastName'];
$event = $_POST['Event'];
$price = $_POST['Price'];

mysql_query("INSERT INTO CUSTOMER (Company, `First Name`, `Last Name`, Event, price) VALUES ('$Company', '$first', '$last', '$event', '$price')");
mysql_close(); 

// Grab our config settings 
require_once($_SERVER['DOCUMENT_ROOT'].'/PHPdocs/phpmailer/config.php'); 

// Grab the FreakMailer class 
require_once($_SERVER['DOCUMENT_ROOT'].'/PHPdocs/phpmailer/MailClass.inc'); 

// instantiate the class 
$mailer = new FreakMailer(); 

// Set the subject 
$mailer->Subject = 'This is a test'; 

$mailer->isHTML(true); 

// Send the E-Mail 
// Body 
$mailer->Body = '<link href="http://www.womeninbusiness.co.uk/Templates/invoice.css" rel="stylesheet" type="text/css" />

<table width="700" border="0">
  <tr>
    <td><span class="normalboldstyle">Women In Business </span><span class="style16"><br />
      <span class="normalboldstyle">Egerton House | 2 Tower Road | Birkenhead | Wirral | CH41 1FN <br />
Telephone 07966 308405 <br />
www.womeninbusiness.co.uk</span></span></td>
    <td colspan="2"><div align="right"><img src="http://www.womeninbusiness.co.uk/images/WIBsphere.jpg" width="188" height="188" alt="WIBlogo" longdesc= /></div></td>
  </tr>
  <tr>
    <td colspan="3"><div align="center" class="largetitlestyle">Invoice</div></td>
  </tr>
  <tr>
    <td class="normalboldstyle">Inv No. </td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><span class="normalboldstyle">COMPANYNAME<br />
NAMES<br />
ADDRESS<br />
POSTCODE<br />
TELEPHONE</span></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td class="normalboldstyle">Course Name </td>
    <td class="normalboldstyle">Number of People </td>
    <td class="normalboldstyle"><div align="right">Cost </div></td>
  </tr>
  <tr>
    <td class="normalboldstyle">&nbsp;</td>
    <td class="normalboldstyle">&nbsp;</td>
    <td class="normalboldstyle"><div align="right">&pound;</div></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td colspan="3"><div align="center"><span class="smalltitlestyle">Payment by BACs to 12-24-81 - a/c no. 06073075 or by cheque payable to Women In Business</span></div></td>
  </tr>
</table>

<h2>WIB HTML test</h2> 
<p>Visit us <a href="http://www.womeninbusiness.co.uk" title="Women In Business">Women In Business.co.uk</a> for a loving community!</p> 

</p>Dear '. $first. '

<p>Sincerely,<br> 
Shauns Web test </p>';

// Add an address to send to. 
$mailer->AddAddress('shaun@designatedassociates.com', 'shaun');

if(!$mailer->Send()) 
{ 
  echo 'There was a problem sending this mail!'; 
} 
else 
{ 
  echo 'Mail sent!';
} 
$mailer->ClearAddresses(); 
$mailer->ClearAttachments(); 
?> 
<?php
mysql_free_result($UpdateCustInfo);
?>


Any help is as ever - greatly appreciated.
Peace

#2 steveclondon

steveclondon
  • Members
  • PipPipPip
  • Advanced Member
  • 161 posts

Posted 27 September 2006 - 08:00 AM


mysql_query("INSERT INTO CUSTOMER (Company, `First Name`, `Last Name`, Event, price) VALUES ('$Company', '$first', '$last', '$event', '$price')");
mysql_close();

you have quoted around the table field names, only quote the values.

if you have the following after your query  it will show what the problem is.   
or die(mysql_error());

#3 eskimowned

eskimowned
  • Members
  • PipPip
  • Member
  • 26 posts

Posted 27 September 2006 - 09:49 AM

Just made those changes, the mail form works fine, but nothing seems to happen with the MYSQL - I get no error message either.

<?php require_once('../../Connections/Conn1.php'); ?>
<?php
mysql_select_db($database_Conn1, $Conn1);
$query_UpdateCustInfo = "SELECT * FROM Customer";
$UpdateCustInfo = mysql_query($query_UpdateCustInfo, $Conn1) or die(mysql_error());
$row_UpdateCustInfo = mysql_fetch_assoc($UpdateCustInfo);
$totalRows_UpdateCustInfo = mysql_num_rows($UpdateCustInfo);

$company = $_POST['Company'];
$first = $_POST['FirstName'];
$last = $_POST['LastName'];
$event = $_POST['Event'];
$price = $_POST['Price'];

mysql_query("INSERT INTO CUSTOMER (Company, First Name, Last Name, Event, price) VALUES ('$Company', '$first', '$last', '$event', '$price')");
mysql_close() or die(mysql_error()); 

// Grab our config settings 
require_once($_SERVER['DOCUMENT_ROOT'].'/PHPdocs/phpmailer/config.php'); 

// Grab the FreakMailer class 
require_once($_SERVER['DOCUMENT_ROOT'].'/PHPdocs/phpmailer/MailClass.inc'); 

// instantiate the class 
$mailer = new FreakMailer(); 

// Set the subject 
$mailer->Subject = 'This is a test'; 

$mailer->isHTML(true); 

// Send the E-Mail 
// Body 
$mailer->Body = '<link href="http://www.womeninbusiness.co.uk/Templates/invoice.css" rel="stylesheet" type="text/css" />

<table width="700" border="0">
  <tr>
    <td><span class="normalboldstyle">Women In Business </span><span class="style16"><br />
      <span class="normalboldstyle">Egerton House | 2 Tower Road | Birkenhead | Wirral | CH41 1FN <br />
Telephone 07966 308405 <br />
www.womeninbusiness.co.uk</span></span></td>
    <td colspan="2"><div align="right"><img src="http://www.womeninbusiness.co.uk/images/WIBsphere.jpg" width="188" height="188" alt="WIBlogo" longdesc= /></div></td>
  </tr>
  <tr>
    <td colspan="3"><div align="center" class="largetitlestyle">Invoice</div></td>
  </tr>
  <tr>
    <td class="normalboldstyle">Inv No. </td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><span class="normalboldstyle">COMPANYNAME<br />
NAMES<br />
ADDRESS<br />
POSTCODE<br />
TELEPHONE</span></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td class="normalboldstyle">Course Name </td>
    <td class="normalboldstyle">Number of People </td>
    <td class="normalboldstyle"><div align="right">Cost </div></td>
  </tr>
  <tr>
    <td class="normalboldstyle">&nbsp;</td>
    <td class="normalboldstyle">&nbsp;</td>
    <td class="normalboldstyle"><div align="right">&pound;</div></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td colspan="3"><div align="center"><span class="smalltitlestyle">Payment by BACs to 12-24-81 - a/c no. 06073075 or by cheque payable to Women In Business</span></div></td>
  </tr>
</table>

<h2>WIB HTML test</h2> 
<p>Visit us <a href="http://www.womeninbusiness.co.uk" title="Women In Business">Women In Business.co.uk</a> for a loving community!</p> 

</p>Dear '. $first. '

<p>Sincerely,<br> 
Shauns Web test </p>';

// Add an address to send to. 
$mailer->AddAddress('shaun@designatedassociates.com', 'shaun');

if(!$mailer->Send()) 
{ 
  echo 'There was a problem sending this mail!'; 
} 
else 
{ 
  echo 'Mail sent!';
} 
$mailer->ClearAddresses(); 
$mailer->ClearAttachments(); 
?> 
<?php
mysql_free_result($UpdateCustInfo);
?>

Cheers in advance for anyones help.

#4 eskimowned

eskimowned
  • Members
  • PipPip
  • Member
  • 26 posts

Posted 27 September 2006 - 10:46 AM

Aha - I get this error now.  ???

Parse error: syntax error, unexpected T_STRING in /hsphere/local/home/designat/womeninbusiness.co.uk/PHPdocs/phpmailer/invoicemail.php on line 15

I checked it, please tell me I've done something daft like left out an ";"

I hope not - a sure fire way to keep my noob status!  :D





#5 eskimowned

eskimowned
  • Members
  • PipPip
  • Member
  • 26 posts

Posted 28 September 2006 - 07:08 AM

Ok - I've checked it and double checked it and I can't see anything amiss. Can someone put me out of my misery? And if your ever in Liverpool I'll buy ya a pint! :D


#6 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 28 September 2006 - 10:41 AM

Try this...

<?php
$sql = "INSERT INTO customer (`Company`, `First Name`, `Last Name`, `Event`, `price`) VALUES ('$Company', '$first', '$last', '$event', '$price')";
$inserted = mysql_query($sql) or die ("Can't execute sql\n\n$sql\n\n" . mysql_error());

if ($inserted == true){
   echo "Insert successful\n";
}
else {
   echo "Insert failed\n";
}
?>

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#7 steveclondon

steveclondon
  • Members
  • PipPipPip
  • Advanced Member
  • 161 posts

Posted 28 September 2006 - 10:45 AM

what is on line 15

#8 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 28 September 2006 - 11:08 AM

Line 15 is this:

mysql_query("INSERT INTO CUSTOMER (Company, First Name, Last Name, Event, price) VALUES ('$Company', '$first', '$last', '$event', '$price')");

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users