Forum Moderators: coopster
$sql="SELECT count(*) FROM orders WHERE sessionID = $sessionID AND Date = $today";
$result = mysql_query(sql);
if ($result="1") {
$query = "INSERT INTO orders VALUES ('', '$order','$today','$total','','processing','$sessionID')";
}
if ($result = "0") {
$query = "UPDATE orders SET ( order='$order', totalammount=$total) WHERE 'sessionID'=$sessionID ";
}
think i may be tryin to calculate the result of the query wrong...
Although you are correct in the assignment versus comparison difference here, the logic is still incorrect and there are a few other errors. bono, what you need to do is FETCH your data from the result set first. Also, note the bold updates to your original code ...
// AS is what is called an ALIAS; it lets us refer to the column later on ...
$sql="SELECT count(*) AS count FROM orders WHERE sessionID = $sessionID AND Date = $today";
// You forgot the dollar sign to indicate sql is a variable:
$result = mysql_query($sql);
// Here is where you will FETCH the data from the result set,
// notice how we use the ALIAS defined earlier:
$row = mysql_fetch_array($result);
if ($row['count'] == 1) {
$query = "INSERT INTO orders VALUES ('', '$order','$today','$total','','processing','$sessionID')";
}
if ($row['count'] == 0) {
$query = "UPDATE orders SET ( order='$order', totalammount=$total) WHERE sessionID=$sessionID ";
}
Note: if that Date column is truly of DATE type, you may need to enclose it in quotation marks, too.
$sql="SELECT count(*) AS count FROM orders WHERE sessionID = $sessionID AND Date = '$today'";
heres my final code :-)
$sql="SELECT count(*) AS count FROM orders WHERE sessionID = '$sessionID' AND Date = '$today'";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
if ($row['count'] == 0) {
$query = "INSERT INTO orders VALUES ('','$order','$today','$total','','processing','$sessionID')";
echo "ran INSERT";
}
if ($row['count'] == 1) {
$query = "UPDATE orders SET custorder='$order', totalamount='$total' WHERE sessionID='$sessionID' AND Date = '$today'";
echo "ran UPDATE";
}