Jenny Dithe
12-07-2010, 08:03 AM
Hi,
I know I have asked about multiple updates before but this seems to be due to a different issue.
My INSERT INTO is inserting three times in to my db, and I am not sure why?
My Code is:
<?php
include("dbconnect.php");
function check_input($value){
if (get_magic_quotes_gpc()){
$value=stripslashes($value);
}
if (!is_numeric($value)){
$value = mysql_real_escape_string($value);
}
return $value;
}
foreach ($_POST as $key=>$value){
$_POST[$key]= check_input($value);
}
$sql="UPDATE store SET country ='{$_POST['country']}'
WHERE PId={$_SESSION['Id']}";
echo $sql . '<br />';
mysql_query($sql,$con) or die('Error: ' . mysql_error());
$sql2="INSERT INTO purchases (Id, fullname, pphoto, category, subcategory, body, date)
VALUES
('{$_SESSION['Id']}','{$_SESSION['fullname']}','{$_SESSION['pphoto']}','country','{$_POST['country']}',' ordered from ',NOW())";
echo $sql2 . '<br />';
mysql_query($sql2,$con) or die('Error: ' . mysql_error());
if($_SESSION['country']=='online purchase'){
$sql3="UPDATE countryepurchases SET {$_POST['ccountry']}=='{$_POST['ccountry']}'
WHERE PId={$_SESSION['Id']}";
echo $sql3 . '<br />';
mysql_query($sql3,$con) or die('Error: ' . mysql_error());
}
?>
Now I worked out that there are three
mysql_query($sql3,$con) or die('Error: ' . mysql_error()); which is probably the connection, I have changed my $sql, so they are $sql, $sql2, $sql3 so the same naming can't be a problem.
I originall had
$result=mysql_query($sql) or die('Error: ' . mysql_error());
but I changed that to
mysql_query($sql/2/3,$con) or die('Error: ' . mysql_error()); in case the three $results were creating the same issue.
I know the problem is probably very simple, but I can't work it out?
And everything is echoing out correctly, e.g. only once?
I know I have asked about multiple updates before but this seems to be due to a different issue.
My INSERT INTO is inserting three times in to my db, and I am not sure why?
My Code is:
<?php
include("dbconnect.php");
function check_input($value){
if (get_magic_quotes_gpc()){
$value=stripslashes($value);
}
if (!is_numeric($value)){
$value = mysql_real_escape_string($value);
}
return $value;
}
foreach ($_POST as $key=>$value){
$_POST[$key]= check_input($value);
}
$sql="UPDATE store SET country ='{$_POST['country']}'
WHERE PId={$_SESSION['Id']}";
echo $sql . '<br />';
mysql_query($sql,$con) or die('Error: ' . mysql_error());
$sql2="INSERT INTO purchases (Id, fullname, pphoto, category, subcategory, body, date)
VALUES
('{$_SESSION['Id']}','{$_SESSION['fullname']}','{$_SESSION['pphoto']}','country','{$_POST['country']}',' ordered from ',NOW())";
echo $sql2 . '<br />';
mysql_query($sql2,$con) or die('Error: ' . mysql_error());
if($_SESSION['country']=='online purchase'){
$sql3="UPDATE countryepurchases SET {$_POST['ccountry']}=='{$_POST['ccountry']}'
WHERE PId={$_SESSION['Id']}";
echo $sql3 . '<br />';
mysql_query($sql3,$con) or die('Error: ' . mysql_error());
}
?>
Now I worked out that there are three
mysql_query($sql3,$con) or die('Error: ' . mysql_error()); which is probably the connection, I have changed my $sql, so they are $sql, $sql2, $sql3 so the same naming can't be a problem.
I originall had
$result=mysql_query($sql) or die('Error: ' . mysql_error());
but I changed that to
mysql_query($sql/2/3,$con) or die('Error: ' . mysql_error()); in case the three $results were creating the same issue.
I know the problem is probably very simple, but I can't work it out?
And everything is echoing out correctly, e.g. only once?