SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Addict trigger's Avatar
    Join Date
    Jun 2003
    Location
    Eagan
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How do I refer to a key that hasn't been created yet?

    know what I mean? I'm trying to write a script where the results of a form are inserted into a mysql table, and then emailed to people. I got those two things done fine, but now I'm trying to figure out a way to insert the key into the subject of the email. Problem is, I can't use that as a field, becuase it hasn't been defined. I thought of assigning a variable, like $tempkey as NULL, but it wouldn't get changed while performing the INSERT command. Here's the code, and if you get any ideas, please help me out. Ideally I'd like to have a link to the detail of that record right in the email, but getting the key out is 'key' (pun intended.
    <?php
    require_once('../Connections/Connection.php');
    mysql_select_db($database_Connection, $Connection);
    $now = date('m-d-Y H:i');
    $sqlquery = "INSERT INTO tickets (ticketKey,timeStamp,company,companyKey,site,contact,phoneNumber,status,problemWith,issue,fix)
    VALUES ('','$now','$companyName','$companyKey','$siteName','$contact','$PhoneNumber','$status','$problem','$issue','$fix')";
    $results = mysql_query($sqlquery);

    foreach ($emailTo as $value ){
    if ($contactName == 'None'){
    $contact = $contactOther;
    }
    else if ($contactName != 'None'){
    $contact = $contactName;
    }
    $message .= "Company Name: $companyName \n";
    $message .= "Contact: $contact \n";
    $message .= "Site Name: $siteName \n";
    $message .= "Contact Person's Phone Number: $PhoneNumber \n";
    $message .= "Support Level: $supportType \n";
    $message .= "Expiration Date of Support: $supportExpires \n";
    $message .= "Sales Representative: $salesRep \n";
    $message .= "Problem With: $problem \n";
    $message .= "Description of Problem: $issue \n";
    $message .= "Fix: $fix \n";
    mail($value , 'Support Ticket Opened:'$issue //this is where I want the key, $message);
    }
    foreach ($customerEmail as $value){
    if ($contactName == 'None'){
    $contact = $contactOther;
    }
    else if ($contactName != 'None'){
    $contact = $contactName;
    }
    $message .= "Company Name: $companyName \n";
    $message .= "Contact: $contact \n";
    $message .= "Site Name: $siteName \n";
    $message .= "Contact Person's Phone Number: $PhoneNumber \n";
    $message .= "Support Level: $supportType \n";
    $message .= "Expiration Date of Support: $supportExpires \n";
    $message .= "Sales Representative: $salesRep \n";
    $message .= "Problem With: $problem \n";
    $message .= "Description of Problem: $issue \n";
    $message .= "Fix: $fix \n";
    mail($value , 'Support Ticket Opened:'$issue //this is where I want the key, $message);
    }
    $success = "1";
    header ( "Location: http://xxxxxxxxxxxx.php");
    ?>

  2. #2
    Non-Member Icheb's Avatar
    Join Date
    Mar 2003
    Location
    Germany
    Posts
    1,474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use

    PHP Code:
    $bla=mysql_insert_id(); 
    Then $bla contains the id of the last row inserted into the database.
    Is that what you are looking for?

  3. #3
    SitePoint Addict trigger's Avatar
    Join Date
    Jun 2003
    Location
    Eagan
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes, so I'm assuming I'd want to put this before my insert statement, so I don't end up with the row after the row I'd just inserted?

  4. #4
    Non-Member Icheb's Avatar
    Join Date
    Mar 2003
    Location
    Germany
    Posts
    1,474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It is the id of the last row inserted, so you have to use it AFTER the insert.

  5. #5
    SitePoint Addict trigger's Avatar
    Join Date
    Jun 2003
    Location
    Eagan
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I magically hosed my whole code now. What did I do wrong???
    <?php
    if ($contactName == 'None'){
    $contact = $contactOther;
    }
    else if ($contactName != 'None'){
    $contact = $contactName;
    }
    require_once('../Connections/Connection.php');
    mysql_select_db($database_Connection, $Connection);
    $now = date('m-d-Y H:i');
    $sqlquery = "INSERT INTO gsi_tickets (ticketKey,timeStamp,company,companyKey,site,contact,phoneNumber,ticketOwner,status,problemWith,issue,fix)
    VALUES ('','$now','$companyName','$companyKey','$siteName','$contact','$PhoneNumber','$ticketOwner','$status','$problem','$issue','$fix')";
    $results = mysql_query($sqlquery);
    $tempTicketKey = mysql_insert_id();
    foreach ($emailTo as $value ){
    $message .= "Company Name: $companyName \n";
    $message .= "Contact: $contact \n";
    $message .= "Site Name: $siteName \n";
    $message .= "Contact Person's Phone Number: $PhoneNumber \n";
    $message .= "Support Level: $supportType \n";
    $message .= "Expiration Date of Support: $supportExpires \n";
    $message .= "Sales Representative: $salesRep \n";
    $message .= "Problem With: $problem \n";
    $message .= "Description of Problem: $issue \n";
    $message .= "Fix: $fix \n";
    mail($value , 'Support Ticket Opened:'$tempTicketKey:$issue , $message);
    }
    foreach ($customerEmail as $value){
    $message .= "Company Name: $companyName \n";
    $message .= "Contact: $contact \n";
    $message .= "Site Name: $siteName \n";
    $message .= "Contact Person's Phone Number: $PhoneNumber \n";
    $message .= "Support Level: $supportType \n";
    $message .= "Expiration Date of Support: $supportExpires \n";
    $message .= "Sales Representative: $salesRep \n";
    $message .= "Problem With: $problem \n";
    $message .= "Description of Problem: $issue \n";
    $message .= "Fix: $fix \n";
    mail($value , 'Support Ticket Opened:'$tempTicketKey:$issue , $message);
    }
    $success = "1";
    header ( "Location: http://xxxxxxxx.php");
    ?>

  6. #6
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    [hint]
    use [php] code tags to make vb parse it as code.
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  7. #7
    SitePoint Addict trigger's Avatar
    Join Date
    Jun 2003
    Location
    Eagan
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry I couldn't find them

  8. #8
    Non-Member Icheb's Avatar
    Join Date
    Mar 2003
    Location
    Germany
    Posts
    1,474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Now if you only said why you think you "hosed" your "whole code now", I could help you.

  9. #9
    La la la la la bronze trophy lieut_data's Avatar
    Join Date
    Jun 2003
    Location
    Waterloo, ON
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'd guess your mail functions aren't performing string concatenation correctly::

    PHP Code:
    mail($value 'Support Ticket Opened:'$tempTicketKey:$issue $message); 
    Change to

    PHP Code:
    mail($value "Support Ticket Opened:  $tempTicketKey:$issue"$message); 
    Last edited by lieut_data; Jul 18, 2003 at 14:48.
    My name is Steve, and I'm a super-villian.

  10. #10
    Database Jedi MattR's Avatar
    Join Date
    Jan 2001
    Location
    buried in the database shell (Washington, DC)
    Posts
    1,107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Lt. Data, you'd need to enclose it in double quotes if you want PHP to parse the $tempTicketKey and $issue variables!

  11. #11
    La la la la la bronze trophy lieut_data's Avatar
    Join Date
    Jun 2003
    Location
    Waterloo, ON
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by MattR
    Lt. Data, you'd need to enclose it in double quotes if you want PHP to parse the $tempTicketKey and $issue variables!
    Lol, good point -- thanks for catching that!
    My name is Steve, and I'm a super-villian.

  12. #12
    Non-Member Icheb's Avatar
    Join Date
    Mar 2003
    Location
    Germany
    Posts
    1,474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually, not necessarily. Something like this will also do:

    PHP Code:
    mail($value'Support Ticket Opened: '$tempTicketKey .':'$issue$message); 

  13. #13
    SitePoint Addict trigger's Avatar
    Join Date
    Jun 2003
    Location
    Eagan
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks Icheb and lieut_data! I figured it was the concatenation of the strings, I always forget that. I lost access to the internet late on Friday, but changed the code to what Icheb did before I even saw it. I'll catch on to this one day!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •