Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: DB insert?

  1. #1
    Regular Coder cyrus709's Avatar
    Join Date
    Dec 2008
    Posts
    102
    Thanks
    22
    Thanked 5 Times in 5 Posts

    DB insert?

    PHP Code:
    <?php
    // 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. 
             
    session_start(); 
          if(
    $_SESSION['logged'] != 1){ header("location:index.php"); } 

    $conmysql_connect("localhost""root""pass");
     if(!
    $con)
    {
    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
    Last edited by cyrus709; 09-18-2009 at 06:54 PM.
    Last night I lay in bed looking up at the stars in the sky and I thought to myself, where the heck is the ceiling.

  • #2
    Regular Coder bacterozoid's Avatar
    Join Date
    Jun 2002
    Location
    USA
    Posts
    490
    Thanks
    24
    Thanked 35 Times in 35 Posts

    Post

    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:

    PHP Code:
    // 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()); 

  • Users who have thanked bacterozoid for this post:

    cyrus709 (09-18-2009)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •