Jump to content


Photo

Display Index Column after Insert

php query sql

  • Please log in to reply
3 replies to this topic

#1 ncurran217

ncurran217

    Advanced Member

  • Members
  • PipPipPip
  • 81 posts

Posted 23 January 2013 - 03:32 PM

To start off with I am really sorry if the title doesn't necessarily describe what I am trying to accomplish here and really didn't know how to title it.

What I have is a form that user inputs information and then when they hit submit it takes them to the page with the code to insert the information into the sql server database. This page also, will send an email out with the some of the information based on one of the fields the user input information into. When the information is inserted into the database, I have a column named RefNumber, that the column settings for it are as follows:

[RefNumber] [int] IDENTITY(1,1) NOT NULL

I want to have this RefNumber displayed out to the user as well as have it in the emails that are sent out as a confirmation for that the email is associated with. Here is my code that I currently and if any let me know if I need to explain anything more clearly:

<?php
session_start();
if (!(isset($_SESSION['forteid']) && $_SESSION['forteid'] != '')) {
header ("Location: login.php");
exit();
}
?>
<?php
error_reporting(E_ALL ^ E_NOTICE);
include 'includes/db_connect.php';
$CallDispo = $_POST['disposition'];
$NewNotes = str_replace("'", "", "$_POST[notes]");


if (trim($CallDispo) == "Revision" or trim($CallDispo) == "Revision/Save" or trim($CallDispo) == "Revision/Collection" or trim($CallDispo) == "Reinstatement") {
$to = "dawn.okeefe@srb1.com";
$subject = "Revision - $_POST[appnumber]";
$message = "<Table border='1px' cellpadding='5' style='border:1px solid black; text-align: Left;'>
	 <TR style='border:1px solid black; text-align: Left;'><td>ForteID:</td><td>$_POST[ForteID]</td></tr>
	 <TR style='border:1px solid black; text-align: Left;'><td>AppNumber:</td><td>$_POST[appnumber]</td></tr>
	 <TR style='border:1px solid black; text-align: Left;'><td>Date:</td><td>$_POST[date]</td></tr>
	 <TR style='border:1px solid black; text-align: Left;'><td>Contract Number:</td><td>$_POST[Con_Number]</td></tr>
	 <TR style='border:1px solid black; text-align: Left;'><td>Finance Number:</td><td>$_POST[Finance_Num]</td></tr>
	 <TR style='border:1px solid black; text-align: Left;'><td>Phone Number:</td><td>$_POST[Phone_Num]</td></tr>
	 <TR style='border:0px solid black; text-align: Left;'><td></td><td></td></tr>
	 <TR style='border:1px solid black; text-align: Left;'><td>Discount Amount:</td><td>$_POST[Disc_Amount]</td></tr>
	 <TR style='border:1px solid black; text-align: Left;'><td>New Total Cost:</td><td>$_POST[Total_Cost]</td></tr>
	 <TR style='border:1px solid black; text-align: Left;'><td>Total Monthly Payments:</td><td>$_POST[Total_MP]</td></tr>
	 <TR style='border:1px solid black; text-align: Left;'><td>New MP Amount:</td><td>$_POST[New_MP_Amt]</td></tr>
	 <TR style='border:1px solid black; text-align: Left;'><td>New DP Amount:</td><td>$_POST[New_DP_Amt]</td></tr>
	 <TR style='border:0 solid black; text-align: Left;'><td></td><td></td></tr>
	 <TR style='border:1px solid black; text-align: Left;'><td>Notes:</td><td>$NewNotes</td></tr>";
}
elseif (trim($CallDispo) == "Escalation"){
$to = "jeremy.nemens@srb1.com";
$subject = "Escalation - $_POST[appnumber]";
$message = "<Table border='1px' cellpadding='5' style='border:1px solid black; text-align: Left;'>
	 <TR style='border:1px solid black; text-align: Left;'><td>ForteID:</td><td>$_POST[ForteID]</td></tr>
	 <TR style='border:1px solid black; text-align: Left;'><td>AppNumber:</td><td>$_POST[appnumber]</td></tr>
	 <TR style='border:1px solid black; text-align: Left;'><td>Date:</td><td>$_POST[date]</td></tr>
	 <TR style='border:1px solid black; text-align: Left;'><td>Contract Number:</td><td>$_POST[Con_Number]</td></tr>
	 <TR style='border:1px solid black; text-align: Left;'><td>Finance Number:</td><td>$_POST[Finance_Num]</td></tr>
	 <TR style='border:1px solid black; text-align: Left;'><td>Phone Number:</td><td>$_POST[Phone_Num]</td></tr>
	 <TR style='border:0px solid black; text-align: Left;'><td></td><td></td></tr>
	 <TR style='border:1px solid black; text-align: Left;'><td>Notes:</td><td>$NewNotes</td></tr>";
}
elseif (trim($CallDispo) == "Email Contract"){
$to = "jeff.starke@srb1.com";
$subject = "Email Contract - $_POST[appnumber]";
$message = "<Table border='1px' cellpadding='5' style='border:1px solid black; text-align: Left;'>
	 <TR style='border:1px solid black; text-align: Left;'><td>ForteID:</td><td>$_POST[ForteID]</td></tr>
	 <TR style='border:1px solid black; text-align: Left;'><td>AppNumber:</td><td>$_POST[appnumber]</td></tr>
	 <TR style='border:1px solid black; text-align: Left;'><td>Date:</td><td>$_POST[date]</td></tr>
	 <TR style='border:1px solid black; text-align: Left;'><td>Contract Number:</td><td>$_POST[Con_Number]</td></tr>
	 <TR style='border:1px solid black; text-align: Left;'><td>Phone Number:</td><td>$_POST[Phone_Num]</td></tr>
	 <TR style='border:0px solid black; text-align: Left;'><td></td><td></td></tr>
	 <TR style='border:1px solid black; text-align: Left;'><td>Notes:</td><td>$NewNotes</td></tr>";
}
elseif (trim($CallDispo) == "Send Contract/Invoice"){
$to = "nicole.lehew@srb1.com";
$subject = "Send Contract/Invoice - $_POST[appnumber]";
$message = "<Table border='1px' cellpadding='5' style='border:1px solid black; text-align: Left;'>
	 <TR style='border:1px solid black; text-align: Left;'><td>ForteID:</td><td>$_POST[ForteID]</td></tr>
	 <TR style='border:1px solid black; text-align: Left;'><td>AppNumber:</td><td>$_POST[appnumber]</td></tr>
	 <TR style='border:1px solid black; text-align: Left;'><td>Date:</td><td>$_POST[date]</td></tr>
	 <TR style='border:1px solid black; text-align: Left;'><td>Contract Number:</td><td>$_POST[Con_Number]</td></tr>
	 <TR style='border:1px solid black; text-align: Left;'><td>Finance Number:</td><td>$_POST[Finance_Num]</td></tr>
	 <TR style='border:1px solid black; text-align: Left;'><td>Phone Number:</td><td>$_POST[Phone_Num]</td></tr>
	 <TR style='border:0px solid black; text-align: Left;'><td></td><td></td></tr>
	 <TR style='border:1px solid black; text-align: Left;'><td>Notes:</td><td>$NewNotes</td></tr>";
}
$headers = 'From: nick.curran@srb1.com' . "\r\n" .
'Reply-To: nick.curran@srb1.com' . "\r\n" .
'MIME-Version: 1.0' . "\r\n" .
'Content-type: text/html; charset=iso-8859-1' . "\r\n" .
'X-Mailer: PHP/' . phpversion();


//Insert to form data into database
$tsql = "INSERT INTO logs(ForteID, disposition, appnumber, Finance_Num, num_payments, ach_cc, date, notes, Phone_Num, Cancel_Disposition, Con_Number, Post_Date, Total_Cost, Total_MP, New_MP_Amt, New_DP_Amt, Disc_Amount, Callback) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
$parameters = array( $_POST[ForteID], $_POST[disposition], $_POST[appnumber], $_POST[Finance_Num], $_POST[num_payments], $_POST[ach_cc], $_POST[date], $NewNotes, $_POST[Phone_Num], $_POST[Cancel_Disposition], $_POST[Con_Number], $_POST[Post_Date], $_POST[Total_Cost], $_POST[Total_MP], $_POST[New_MP_Amt], $_POST[New_DP_Amt], $_POST[Disc_Amount], $_POST[Callback]);
$stmt = sqlsrv_query($connection, $tsql, $parameters);


// Send Email
if(mail($to, $subject, $message, $headers))
echo "Email sent!<br>";
else
echo "No email to be sent!<br>";


/* Free statement and connection resources. */
sqlsrv_free_stmt( $stmt);
sqlsrv_close( $connection);
header( "refresh:2;url=index.php" );
echo 'Your entry has been saved!';
exit();
?>



Thanks in advance!

#2 ncurran217

ncurran217

    Advanced Member

  • Members
  • PipPipPip
  • 81 posts

Posted 24 January 2013 - 10:47 AM

Well I found a tutorial on how to get what I was looking for.

#3 Jessica

Jessica

    This is not my name.

  • Gurus
  • 8,982 posts
  • LocationDallas, TX
  • Age:26

Posted 24 January 2013 - 10:51 AM

Thanks for posting it here so the next person who has this problem can use your solution!

I'll go ahead and mark this solved for you.


(If I understand the question, the answer is mysql_last_insert_id())

Edited by Jessica, 24 January 2013 - 10:52 AM.

My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.

How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq

Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!

#4 ncurran217

ncurran217

    Advanced Member

  • Members
  • PipPipPip
  • 81 posts

Posted 24 January 2013 - 10:52 AM

Well no one helped me, so thanks!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com