View Full Version : Resolved DB insert?

09-18-2009, 07:05 PM
// Check to see if session is not registered, if it is not redirect to .inex.php
// Put this code in first line of every web page that you only want logged-in users to see.
if($_SESSION['logged'] != 1){ header("location:index.php"); }

$con= mysql_connect("localhost", "root", "pass");
die('could not connect to mysql');
mysql_select_db("mydb", $con);
//username variable
$convert= $_SESSION['username'];

$result = mysql_query("SELECT * FROM mail
WHERE username='$convert' AND mnum='1'");

while($row = mysql_fetch_array($result))
$rock = $row['reply'];
$road = $row['reply1'];
$replyinc = $rock + 1;
$replyarc = $road + 1;
print $replyarc . " " . $replyinc;

mysql_query("UPDATE mail SET reply = '$replyinc'
WHERE username = '$convert' AND mnum = '1'");

mysql_query("UPDATE mail SET reply = '$replyarc'
WHERE username = '$convert' AND mnum = '1'");


What this is supposed to do is get a number from the DB and add one to that number, then insert it into the DB. It does add one to the previous number, but it does not re insert the number :(

09-18-2009, 07:28 PM
You have an error in your last query. You're updating the wrong column...both of your updates update column "reply"

In any case, you only need one query to do what you want:

// One query can update those columns for yu
$sql = "update mail set reply=reply+1, reply1=reply1+1 where username = '$convert' and mnum = '1'";
// Quit on any SQL error
mysql_query($sql) or die(mysql_error());