#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    16
    Rep Power
    0

    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
  2. #2
  3. Jealous Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,302
    Rep Power
    9400
    What is the code that gives $MeetingNumber a value?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    16
    Rep Power
    0
    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.
  6. #4
  7. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,316
    Rep Power
    7171
    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

    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
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    16
    Rep Power
    0
    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.
  10. #6
  11. Jealous Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,302
    Rep Power
    9400
    What code do you have now that saves the data?
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    16
    Rep Power
    0
    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);
    ?>
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2009
    Posts
    157
    Rep Power
    89
    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);
     
    ?>
  16. #9
  17. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,316
    Rep Power
    7171
    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.
    PHP FAQ

    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
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    16
    Rep Power
    0
    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

IMN logo majestic logo threadwatch logo seochat tools logo