Jump to content

PHP Script double posting to MySql


Daadian

Recommended Posts

Please help !

 

Hi guys, I am literally at my wits end with this and I am almost positive its in my code.

 

This code is from a blackberry app that sends the infor into PHP, that part works flawlessy and was working just fine until I added the code to get the supervisor email from  a different table based off a query.

 

What happens is the information gets posted three times, The first time the emails are triggered and the post happens succefully, both the user and the supervisor get the properly formatted emails.

 

This happens almost immediately, works great. Then almost immediately, the supervisor will get two more emails, with the same information except missing the orignal users email, presumably the user would have gotten two more emails as well if the email address was available. The mysql DB gets all 3 records with the second two missing the user email.

 

Here is my code:

 

<?php
$dbServer1='contractor.emcee.tv';
$dbUser1='******';
$dbPass1='******';
$dbName1='purchaseorders';
$link = mysqli_connect("$dbServer1", "$dbUser1", "$dbPass1") or die("Could not connect post");
mysqli_select_db($link,"$dbName1") or die("Could not select database your_db_name1");
$job = $_GET['jobnumber'];
$vend = $_GET['vendor'];
$cat = $_GET['category'];
$amt = $_GET['amount'];
$note = $_GET['note'];
$email = $_SERVER['HTTP_RIM_DEVICE_EMAIL'];
$sql = mysqli_query($link,"insert po (job,vend,cat,amount,user,notes,date) values ('$job','$vend','$cat','$amt','$email','$note',NOW())");
if (!$sql){	
print("FAILED");
}
else
{	print("SUCCESS");
	$query = "SELECT MAX(id) AS PO from po";
  	$result = mysqli_query($link, $query) Or die(mysqli_error($link)) ;
   	while ($row = mysqli_fetch_assoc($result))
{
$po = $row['PO'];
}
$query2 = "SELECT supervisoremail FROM job WHERE jobnum = $job";
$result2 = mysqli_query($link, $query2)Or die(mysqli_error($link));
while ($row2 =mysqli_fetch_assoc($result2)){
$sup = $row2['supervisoremail'];
}
$subject = "Purchase Order Request";
$supsubject = "FYI Purchase Order Completion";
$body = "Your purchase order request has been completed. \n \n Your PO number is: $po \n \n Job Number:$job \n Vendor:$vend \n Category:$cat \n Amount:$amt \n Items: \n $note \n \n A copy of this email has been sent to your supervisor.";
$supbody = "A purchase order request has been completed. \n \n PO number $po was issued to $email for the following: \n \n Job Number:$job \n Vendor:$vend \n Category:$cat \n Amount:$amt \n Items: \n $note \n \n Please address this if this request is in error.";
mail($email, $subject, $body);
mail($sup, $supsubject, $supbody);
}
?>

 

Link to comment
Share on other sites

I'm too tired to look over it, but here it's readable for someone to help ya.

 

<?php

$dbServer1 = 'contractor.emcee.tv';
$dbUser1 = '******';
$dbPass1 = '******';
$dbName1 = 'purchaseorders';

$link = mysqli_connect("$dbServer1", "$dbUser1", "$dbPass1") or die("Could not connect post");
mysqli_select_db($link, "$dbName1") or die("Could not select database your_db_name1");

$job = $_GET['jobnumber'];
$vend = $_GET['vendor'];
$cat = $_GET['category'];
$amt = $_GET['amount'];
$note = $_GET['note'];
$email = $_SERVER['HTTP_RIM_DEVICE_EMAIL'];
$sql = mysqli_query($link, "insert po (job,vend,cat,amount,user,notes,date) values ('$job','$vend','$cat','$amt','$email','$note',NOW())");

if (!$sql) {
    print("FAILED");
} else {
    print("SUCCESS");
    $query = "SELECT MAX(id) AS PO from po";
    $result = mysqli_query($link, $query) Or die(mysqli_error($link));
    
    while ($row = mysqli_fetch_assoc($result)) {
        $po = $row['PO'];
    }
    
    $query2 = "SELECT supervisoremail FROM job WHERE jobnum = $job";
    $result2 = mysqli_query($link, $query2) Or die(mysqli_error($link));
    
    while ($row2 = mysqli_fetch_assoc($result2)) {
        $sup = $row2['supervisoremail'];
    }
    
    $subject = "Purchase Order Request";
    $supsubject = "FYI Purchase Order Completion";
    $body = "Your purchase order request has been completed. \n \n Your PO number is: $po \n \n Job Number:$job \n Vendor:$vend \n Category:$cat \n Amount:$amt \n Items: \n $note \n \n A copy of this email has been sent to your supervisor.";
    $supbody = "A purchase order request has been completed. \n \n PO number $po was issued to $email for the following: \n \n Job Number:$job \n Vendor:$vend \n Category:$cat \n Amount:$amt \n Items: \n $note \n \n Please address this if this request is in error.";
    mail($email, $subject, $body);
    mail($sup, $supsubject, $supbody);
}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.