+ Reply to Thread
Results 1 to 5 of 5
Like Tree4Likes
  • 2 Post By gdebojyoti.mail96
  • 1 Post By misson
  • 1 Post By essellar

Thread: Problem with "status updates"

  1. #1
    gdebojyoti.mail96 is offline x10Hosting Member gdebojyoti.mail96 is an unknown quantity at this point
    Join Date
    Mar 2011
    Posts
    57

    Lightbulb Problem with "status updates"

    Hello,

    I have created a PHP code for status updates of members of my site.

    It's running perfectly in my computer (localhost; WAMP). But it's not working when I am uploading it in my x10hosting account.

    The code is as follows:

    Code:
    <?php
    
    $pm_ops1 = mysql_connect("localhost","username","password");
    $pm_conn1 = mysql_select_db("databaseName");
        
    
        //Hidden steps to obtain UserID, stored in $userID variable
        
    @$statusCont = htmlentities($_POST["wall"]);  //$_POST["wall"] gets the actual contents of the status update from main.php page using POST method
    @$statusCont = mysql_real_escape_string($statusCont);
    
    
    // START updating database
    
    $pm_query1 = "SELECT max(statusID) FROM statusTable";
    $result1 = mysql_query($pm_query1);
    $output = mysql_fetch_row($result1);
    $output[0]++;
    $statid = $output[0];
    
    $updateStat = mysql_query("INSERT INTO statusTable (statusID, statup, uid, timestamp) VALUES ('".$statid."', '".$statusCont."', '".$userID."', '".date('ymdHis')."')");
    
    // END updating database
    
    mysql_close($pm_ops1);
    
    header("location:main.php");
    
    ?>
    The problem is that, whenever I am entering a new "Status" in the main.php page, the status ID ( $statid ) is not getting incremented. As a result, whenever I am editing/ deleting a particular status, all the status updates (which have the same status ID) are getting updated/ deleted.

    The strange thing is that no such problem arises when I am using the same code in my own computer (localhost; WAMP server).

    Can anyone tell me what is wrong?
    dinomirt96 and karimirt47 like this.

  2. #2
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: Problem with "status updates"

    Instead of incrementing the ID in your script (which could lead to a race condition where two instances of the script executes nearly simultaneously, giving the same ID to two different status updates), declare the statusID column as AUTO_INCREMENT and UNSIGNED.

    Code:
    ALTER TABLE statusTable MODIFY statusID INT UNSIGNED AUTO_INCREMENT NOT NULL;
    Also, the "Table" in "statusTable" is redundant. It should be named simply "statuses".

    Code:
    ALTER TABLE statusTable RENAME TO statuses;
    Lastly, there's no good reason to use the outdated mysql extension for new projects. Use mysqli or PDO and prepared statements.
    Last edited by misson; 08-29-2011 at 04:26 PM.
    gdebojyoti.mail96 likes this.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  3. #3
    gdebojyoti.mail96 is offline x10Hosting Member gdebojyoti.mail96 is an unknown quantity at this point
    Join Date
    Mar 2011
    Posts
    57

    Re: Problem with "status updates"

    Quote Originally Posted by misson View Post
    Instead of incrementing the ID in your script (which could lead to a race condition where two instances of the script executes nearly simultaneously, giving the same ID to two different status updates), declare the statusID column as AUTO_INCREMENT and UNSIGNED.
    It worked. Thanks a lot!

    "Table" in "statusTable" is redundant.
    What does this mean? May I change the table's name to "status_table"?

    Lastly, there's no good reason to use the outdated mysql extension for new projects. Use mysqli or PDO and prepared statements.
    Thanks for the advice. But, unfortunately (for me), I am not familiar with MySQLi or PDO.

    ---------- Post added at 06:47 AM ---------- Previous post was at 06:43 AM ----------

    By the way, I wanted to give a +rep to you, but I was shown this error message:
    You must spread some Reputation around before giving it to misson again.
    What does it mean?
    Last edited by gdebojyoti.mail96; 08-30-2011 at 01:45 AM.

  4. #4
    essellar's Avatar
    essellar is offline Community Advocate essellar has a spectacular aura about
    Join Date
    Feb 2010
    Location
    Toronto, Ontario, CA
    Posts
    1,153

    Re: Problem with "status updates"

    PDO's not difficult to pick up, and the mysql extension is being deprecated (so your software will need to be updated before too long anyway).

    And what misson means is that there's no good reason to include the word "table" in a table name. Each row represents an entity of some sort (in this case, a "status") and the table name should just be the plural of the entities it contains (in this case "statuses" (nested parenthetical comment: don't get cute and use the Latin plural)).
    gdebojyoti.mail96 likes this.
    “Beware of bugs in the above code; I have only proved it correct, not tried it.” --Donald Knuth
    "It was as if its architects were given a perfectly good hammer and gleefully replied, 'neat! With this hammer, we can build a tool that can pound in nails.'" -- Alex Papadimoulis (on TheDailyWTF.com)

  5. #5
    gdebojyoti.mail96 is offline x10Hosting Member gdebojyoti.mail96 is an unknown quantity at this point
    Join Date
    Mar 2011
    Posts
    57

    Re: Problem with "status updates"

    Okay. Thanks for the info.

+ Reply to Thread

Similar Threads

  1. "Status updates"
    By gdebojyoti.mail96 in forum Programming Help
    Replies: 4
    Last Post: 08-28-2011, 05:52 AM
  2. Replies: 4
    Last Post: 01-27-2011, 02:10 PM
  3. Replies: 1
    Last Post: 05-08-2010, 03:17 AM
  4. Unsuspension Status "Unknown" account "jchevin"
    By 200206695 in forum Free Hosting
    Replies: 8
    Last Post: 10-03-2009, 06:37 PM
  5. Replies: 4
    Last Post: 11-27-2007, 06:49 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers