After successful mysql insert, it echos "Records have been inserted" too many times

poblem

I only want it to say “Records have been inserted” 1 time. Not 100 times.

Please help.

Here is the code


$servername = “localhost”;
$username = “root”;
$password = “”;
$dbname = “data”;

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

$sql = “INSERT INTO data (jobname,promiseddate,customer,zip,city,workdesc,phone1,email,completed)
VALUES (’$jobname’,’”.$date->format(‘Y-m-d’)."’,’$customer’,’$zip’,’$city’,’$workdesc’,’$phone’,’$email’,’’)";

if ($conn->query($sql) === TRUE) {
echo “Records have been inserted”;
} else {
echo "Error: " . $sql . “
” . $conn->error;
}
}

$conn->close();

	   }

simply try

...
if($conn->query($sql)) {
   echo "Inserted";
}else{
 echo "Error";
}
....

Hope it helps.

if you checkout the code that frankbeen has been helping me with you should be able to pull out what you need to only display one insert result

https://www.phphelp.com/t/xml-to-mysql-import-script/30677

Sponsor our Newsletter | Privacy Policy | Terms of Service