PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 12th, 2012, 08:37 PM
cdr6800 cdr6800 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 16 cdr6800 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 4 m 22 sec
Reputation Power: 0
PHP-General - Print value of auto increment field in email

Hello:
I have a mysql database with an auto increment field called MeetingNumber. I want to generate an confirmation email that will put this number into the email. When I add a record to the database, it does put a number in the MeetingDate field but I can't figure out how it would show in the email. I tried something like

. "The meeting number is $MeetingNumber\n"

but it just comes out "The meeting number is " But as I said, there is a value to that field in the database. Any help would be much appreciated. Thanks.

cdr6800

Reply With Quote
  #2  
Old October 12th, 2012, 09:12 PM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,700 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 5 h 25 m 44 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
What is the code that gives $MeetingNumber a value?

Reply With Quote
  #3  
Old October 12th, 2012, 10:02 PM
cdr6800 cdr6800 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 16 cdr6800 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 4 m 22 sec
Reputation Power: 0
Quote:
Originally Posted by requinix
What is the code that gives $MeetingNumber a value?


Thanks for the reply.

There is no code that gives it a value. It is an auto incremented field...like ID. Each time a new record is added, it goes up by 1.

Reply With Quote
  #4  
Old October 12th, 2012, 10:16 PM
E-Oreo's Avatar
E-Oreo E-Oreo is offline
Lost in code
Click here for more information.
 
Join Date: Dec 2004
Posts: 7,931 E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)  Folding Points: 945 Folding Title: Novice Folder
Time spent in forums: 2 Months 7 h 49 m 26 sec
Reputation Power: 7053
If you have just inserted the row into the database, there is an insert id function of the database library that you can call to retrieve the value of the row that was just inserted.
__________________
PHP FAQ
How to program a basic, secure login system using PHP

Quote:
Originally Posted by Spad
Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around

Reply With Quote
  #5  
Old October 12th, 2012, 10:24 PM
cdr6800 cdr6800 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 16 cdr6800 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 4 m 22 sec
Reputation Power: 0
Quote:
Originally Posted by E-Oreo
If you have just inserted the row into the database, there is an insert id function of the database library that you can call to retrieve the value of the row that was just inserted.


someone mentioned that...but not sure how to use it. Can you help? Thanks.

Reply With Quote
  #6  
Old October 13th, 2012, 12:19 AM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,700 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 5 h 25 m 44 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
What code do you have now that saves the data?

Reply With Quote
  #7  
Old October 13th, 2012, 07:07 AM
cdr6800 cdr6800 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 16 cdr6800 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 4 m 22 sec
Reputation Power: 0
Quote:
Originally Posted by requinix
What code do you have now that saves the data?


Here is the php file that processes the form that someone fills out:

<?php
require("db.php");
$MeetingNumber = 'MeetingNumber';
$Date = date("m/d/Y");
$Request=$_POST['Request'];
$MeetingTitle=$_POST['MeetingTitle'];
$Choice1MeetingTime=$_POST['Choice1MeetingTime'];
$Choice2MeetingTime=$_POST['Choice2MeetingTime'];
$Choice3MeetingTime=$_POST['Choice3MeetingTime'];
$MeetingLength=$_POST['MeetingLength'];
$NumberAttendees=$_POST['NumberAttendees'];
$OpenOrClosed=$_POST['OpenOrClosed'];
$Moderator1Name=$_POST['Moderator1Name'];
$Moderator1Phone=$_POST['Moderator1Phone'];
$Moderator1Organization=$_POST['Moderator1Organization'];
$Moderator1OtherOrganization=$_POST['Moderator1OtherOrganization'];
$Moderator1Email=$_POST['Moderator1Email'];
$Moderator2Name=$_POST['Moderator2Name'];
$Moderator2Phone=$_POST['Moderator2Phone'];
$Moderator2Organization=$_POST['Moderator2Organization'];
$Moderator2OtherOrganization=$_POST['Moderator2OtherOrganization'];
$Moderator2Email=$_POST['Moderator2Email'];
$MeetingCoordinatorName=$_POST['MeetingCoordinatorName'];
$MeetingCoordinatorPhone=$_POST['MeetingCoordinatorPhone'];
$MeetingCoordinatorOrganization=$_POST['MeetingCoordinatorOrganization'];
$MeetingCoordinatorOtherOrganization=$_POST['MeetingCoordinatorOtherOrganization'];
$MeetingCoordinatorEmail=$_POST['MeetingCoordinatorEmail'];
$CompetingMeeting1=$_POST['CompetingMeeting1'];
$CompetingMeeting2=$_POST['CompetingMeeting2'];
$CompetingMeeting3=$_POST['CompetingMeeting3'];
$SetupChoice1=$_POST['SetupChoice1'];
$SetupChoice2=$_POST['SetupChoice2'];
$c1=$_POST['c1'];
$t1=$_POST['t1'];
$c2=$_POST['c2'];
$t2=$_POST['t2'];
$c3=$_POST['c3'];
$t3=$_POST['t3'];
$c4=$_POST['c4'];
$t4=$_POST['t4'];
$c5=$_POST['c5'];
$t5=$_POST['t5'];
$c6=$_POST['c6'];
$t6=$_POST['t6'];
$c7=$_POST['c7'];
$t7=$_POST['t7'];
$c8=$_POST['c8'];
$t8=$_POST['t8'];
$c9=$_POST['c9'];
$t9=$_POST['t9'];
$c10=$_POST['c10'];
$t10=$_POST['t10'];
$c11=$_POST['c11'];
$t11=$_POST['t11'];
$c12=$_POST['c12'];
$t12=$_POST['t12'];
$c13=$_POST['c13'];
$t13=$_POST['t13'];
$AVTotal=$_POST['AVTotal'];
$AVScholarship=$_POST['AVScholarship'];
$OrderPolycom=$_POST['OrderPolycom'];
$OrderWiFi=$_POST['OrderWiFi'];
$SendCateringMenus=$_POST['SendCateringMenus'];
$CateringContactCoordinator=$_POST['CateringContactCoordinator'];
$MeetingNumber = mysql_insert_id();

//Uploading to database
{

$link = mysql_connect($DBserver, $DBuser, $DBpass);
@mysql_select_db($DBname) or die( "Unable to select database");

$query = "INSERT INTO AVorder VALUES ('$MeetingNumber','$Date','$Request','$MeetingTitle','$Choice1MeetingTime','$Choice2MeetingTime','$C hoice3MeetingTime','$MeetingLength','$NumberAttendees','$OpenOrClosed','$Moderator1Name','$Moderator 1Phone','$Moderator1Organization','$Moderator1OtherOrganization','$Moderator1Email','$Moderator2Name ','$Moderator2Phone','$Moderator2Organization','$Moderator2OtherOrganization','$Moderator2Email','$M eetingCoordinatorName','$MeetingCoordinatorPhone','$MeetingCoordinatorOrganization','$MeetingCoordin atorOtherOrganization','$MeetingCoordinatorEmail','$CompetingMeeting1','$CompetingMeeting2','$Compet ingMeeting3','$SetupChoice1','$SetupChoice2','$c1','$t1','$c2','$t2','$c3','$t3','$c4','$t4','$c5',' $t5','$c6','$t6','$c7','$t7','$c8','$t8','$c9','$t9','$c10','$t10','$c11','$t11','$c12','$t12','$c13 ','$t13','$AVTotal','$AVScholarship','$OrderPolycom','$OrderWiFi','$SendCateringMenus','$CateringCon tactCoordinator')";
mysql_query($query);

mysql_close($link);
}

//Sending email to HMORN
$pfw_header = "From: $MeetingCoordinatorEmail\n"
. "Reply-To: $MeetingCoordinatorEmail\n";
$pfw_subject = "HMORN Meeting Booked";
$pfw_email_to = "cdrossen@cdrmarketing.com";
$pfw_message = "A meeting has been booked on the HMORN website. The meeting coordinator's name is $MeetingCoordinatorName\n"
. "The meeting number is $MeetingNumber\n"
. "To get the full information for this meeting booking, go to www.hmornmeeting.org.\n";
@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;

//send to redirect page after submitting form
$redirect = "http://www.hmornmeeting.org/redirect_meeting.htm";
header("Location:" .$redirect);
?>

Reply With Quote
  #8  
Old October 13th, 2012, 07:13 AM
TASB TASB is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2009
Posts: 148 TASB User rank is Second Lieutenant (5000 - 10000 Reputation Level)TASB User rank is Second Lieutenant (5000 - 10000 Reputation Level)TASB User rank is Second Lieutenant (5000 - 10000 Reputation Level)TASB User rank is Second Lieutenant (5000 - 10000 Reputation Level)TASB User rank is Second Lieutenant (5000 - 10000 Reputation Level)TASB User rank is Second Lieutenant (5000 - 10000 Reputation Level)TASB User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 4 Days 6 h 41 m 7 sec
Reputation Power: 88
Google is helpful.

http://www.w3schools.com/php/func_mysql_insert_id.asp


PHP Code:
<?php
 $con 
mysql_connect("localhost""peter""abc123");
 if (!
$con)
   {
   die(
'Could not connect: ' mysql_error());
   }
 
$db_selected mysql_select_db("test_db",$con);
 
$sql "INSERT INTO person VALUES ('Børge','Refsnes','Sandnes','17')";
 
$result mysql_query($sql,$con);
 echo 
"ID of last inserted record is: " mysql_insert_id();
 
mysql_close($con);
 
?>

Reply With Quote
  #9  
Old October 13th, 2012, 11:08 AM
E-Oreo's Avatar
E-Oreo E-Oreo is offline
Lost in code
Click here for more information.
 
Join Date: Dec 2004
Posts: 7,931 E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)  Folding Points: 945 Folding Title: Novice Folder
Time spent in forums: 2 Months 7 h 49 m 26 sec
Reputation Power: 7053
Your original code was actually not too far off, you just have the call to mysql_insert_id in the wrong place; you have to call it after you execute your INSERT query, otherwise there is no insert id yet. Also you would not include $MeetingNumber in your INSERT query. It is not possible to determine the next insert id, only the last one.

Also your code contains a SQL injection vulnerability.

Reply With Quote
  #10  
Old October 13th, 2012, 11:17 AM
cdr6800 cdr6800 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 16 cdr6800 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 4 m 22 sec
Reputation Power: 0
Quote:
Originally Posted by E-Oreo
Your original code was actually not too far off, you just have the call to mysql_insert_id in the wrong place; you have to call it after you execute your INSERT query, otherwise there is no insert id yet. Also you would not include $MeetingNumber in your INSERT query. It is not possible to determine the next insert id, only the last one.

Also your code contains a SQL injection vulnerability.


Thanks E-Oreo. I did what you said. I am now getting this in the email - The meeting number is 0 everytime an email is sent. Here is what I changed it to:

$link = mysql_connect($DBserver, $DBuser, $DBpass);
@mysql_select_db($DBname) or die( "Unable to select database");

$query = "INSERT INTO AVorder VALUES ('$Date','$Request','$MeetingTitle','$Choice1MeetingTime','$Choice2MeetingTime','$Choice3MeetingTime ','$MeetingLength','$NumberAttendees','$OpenOrClosed','$Moderator1Name','$Moderator1Phone','$Moderat or1Organization','$Moderator1OtherOrganization','$Moderator1Email','$Moderator2Name','$Moderator2Pho ne','$Moderator2Organization','$Moderator2OtherOrganization','$Moderator2Email','$MeetingCoordinator Name','$MeetingCoordinatorPhone','$MeetingCoordinatorOrganization','$MeetingCoordinatorOtherOrganiza tion','$MeetingCoordinatorEmail','$CompetingMeeting1','$CompetingMeeting2','$CompetingMeeting3','$Se tupChoice1','$SetupChoice2','$AV1','$AV1Fee','$AV2','$AV2Fee','$AV3','$AV3Fee','$AV4','$AV4Fee','$AV 5','$AV5Fee','$AV6','$AV6Fee','$AV7','$AV7Fee','$AV8','$AV8Fee','$AV9','$AV9Fee','$AV10','$AV10Fee', '$AV11','$AV11Fee','$AV12','$AV12Fee','$AV13','$AV13Fee','$AVTotalFee','$AVScholarship','$OrderPolyc om','$OrderWiFi','$SendCateringMenus','$CateringContactCoordinator')";
mysql_query($query);
$MeetingNumber = mysql_insert_id();
mysql_close($link);

Thanks...cdr6800

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > PHP-General - Print value of auto increment field in email

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap