+ Reply to Thread
Results 1 to 9 of 9

Thread: my life, it's ****ed.

  1. #1
    mywebradio12 is offline x10Hosting Member mywebradio12 is an unknown quantity at this point
    Join Date
    Jul 2011
    Posts
    1

    my life, it's ****ed.

    hi all

    why does this piece of code not work :s
    <?php
    mysql_query("UPDATE `articles` SET likes = likes+'".$_SESSION['userid'].",' WHERE id = '".mysql_real_escape_string($_GET['id'])."'") or die('error liking an article lol sorry');
    ?>

    what it needs to do is simple:
    adding "<user id number>," to the existing table row "likes".

    nvm: with the comma to separate the id's.

    Thank you for your time in advance.

    Kind Regards,
    mywebradio12
    Last edited by mywebradio12; 09-22-2011 at 02:55 PM.

  2. #2
    your_death_1994's Avatar
    your_death_1994 is offline x10Hosting Member your_death_1994 is an unknown quantity at this point
    Join Date
    Feb 2011
    Location
    Canada
    Posts
    21

    Re: my life, it's ****ed.

    Do you see any errors when you ran this code?

    and what is the term in bold? if its a variable shouldn't it be $likes or something.
    likes = likes+'".$_SESSION['userid'].",'

    Lol, im learning php, so yeah i don't know a lot.
    Last edited by your_death_1994; 09-22-2011 at 03:49 PM. Reason: typo
    Hey, I'm Razzi!

  3. #3
    bdistler's Avatar
    bdistler is offline x10 Lieutenant bdistler is an unknown quantity at this point
    Join Date
    May 2010
    Location
    Catalina AZ USA
    Posts
    349

    Re: my life, it's ****ed.

    I ASSUME THIS IS A TEST PHP SCRIPT
    AND WILL NOT BE INCORPORATE INTO YOUR SITE
    UNTIL YOU HANDLE ERRORS AND TEST YOUR DATA
    AND RESULTS IN THE APPROPRIATE WAY

    I would do
    PHP Code:
    $tempID mysql_real_escape_string($_GET['id']) 
    then use $tempID in the query

    I would make up the query in a var and use it like
    PHP Code:
    $query "UPDATE `articles` SET likes =....."
    $result mysql_query($query) or die....... 
    then to get the error info replace - starting at die with
    PHP Code:
    ... die ("error liking an article lol sorry<br />\n MySQL error ==>" mysql_errno() . "<== : ==>" mysql_error() . "<== <br />\n\$query ==>" $query "<==<br />\n "); 
    others will be here to tell you to use PDO

  4. #4
    resty_rizal99 is offline x10Hosting Member resty_rizal99 is an unknown quantity at this point
    Join Date
    Apr 2011
    Posts
    2

    Re: my life, it's ****ed.

    how about change your code like this
    PHP Code:
    // Get the current value of likes from articles with a match id of $_GET['id']
    if(!$result mysql_query('SELECT `likes` FROM `articles`  WHERE `id` = "'.mysql_real_escape_string($_GET['id']).'"')) die('Invalid query: ' mysql_error());
    $row mysql_fetch_row($result);
    $likes $row[0];

    // Update articles likes with the value of likes plus value of $_SESSION['userid']
    mysql_query("UPDATE `articles` SET `likes` = '".($likes+$_SESSION['userid'])."' WHERE `id` = '".mysql_real_escape_string($_GET['id'])."'") or die('error liking an article lol sorry'); 

  5. #5
    gomarc's Avatar
    gomarc is offline x10 Elder gomarc is an unknown quantity at this point
    Join Date
    Oct 2007
    Location
    USA
    Posts
    511

    Re: my life, it's ****ed.

    Hello mywebradio12,

    As long as the value of $_SESSION['userid'] is numeric, your query as posted works. Before the query, test this value to ensure its numeric.

    I also suspect that server temporal issues may have affected your results.

    Earlier today, I was having some connection issues with MySQL (my free account server is chopin) but all is working fine now.

    As pointed out by bdistler, you should definitively move away from the old mysql extension. Please read this post by essellar: PHP to begin deprecation of ext/mysql -- start moving your development to PDO now

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

    Re: my life, it's ****ed.

    Additionally:
    • Use [php], [html] or [code] tags (as appropriate) when posting to separate and format code.
    • Don't use die when outputting HTML. You'll get invalid HTML.
    • Columns in relational tables should have scalar (aka "simple" or "atomic") values, not compound values (aka "repeating groups"). A comma-separated list is a compound value. This is a basic property of RDBs called "first normal form". Instead, use a table to represent the relationship:
      Code:
      CREATE TABLE likes (
          `article` INT UNSIGNED NOT NULL,
          `user` INT UNSIGNED NOT NULL,
          UNIQUE KEY (`article`, `user`),
          FOREIGN KEY `article` REFERENCES `articles` (`id`),
          FOREIGN KEY `user` REFERENCES `users` (`id`)
      ) Engine=InnoDB;
      To get the users that like an article, join the "articles" and "users" tables using the "likes" table.
    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.

  7. #7
    theone48's Avatar
    theone48 is offline x10 Sophmore theone48 is an unknown quantity at this point
    Join Date
    Jun 2011
    Posts
    221

    Re: my life, it's ****ed.

    Yikes, this is a temperamental thread. What does death have to do with programming?

    Oh, maybe, 'die' has some alternative cyber meaning for programming function.
    T1 Need Help? Add me to your friend's list & message anytime!
    If you believe this a good post, please click the star icon below. Thanks!
    Remember, help is only a step away in the forums or on Live Chat.

  8. #8
    lemon-tree's Avatar
    lemon-tree is offline x10 Minion lemon-tree has a spectacular aura about
    Join Date
    Nov 2007
    Posts
    1,420

    Re: my life, it's ****ed.

    Quote Originally Posted by theone48 View Post
    Yikes, this is a temperamental thread. What does death have to do with programming?

    Oh, maybe, 'die' has some alternative cyber meaning for programming function.
    The die() function causes the currently running script to end execution. If you don't like that terminology, you can use exit() instead. A quick search of the PHP manual would have told you precisely this.
    Last edited by lemon-tree; 09-28-2011 at 07:54 AM.

  9. #9
    theone48's Avatar
    theone48 is offline x10 Sophmore theone48 is an unknown quantity at this point
    Join Date
    Jun 2011
    Posts
    221

    Re: my life, it's ****ed.

    Quote Originally Posted by lemon-tree View Post
    The die() function causes the currently running script to end execution. If you don't like that terminology, you can use exit() instead. A quick search of the PHP manual would have told you precisely this.
    Thanks, thought it had something to do with programming. Sorry for the stupid question, but I don't even know what 'PHP' is.
    T1 Need Help? Add me to your friend's list & message anytime!
    If you believe this a good post, please click the star icon below. Thanks!
    Remember, help is only a step away in the forums or on Live Chat.

+ Reply to Thread

Similar Threads

  1. x10 4 LIFE =)
    By danthemangm in forum Introductions
    Replies: 4
    Last Post: 11-03-2008, 08:57 AM
  2. Life Bux
    By Mitch in forum Earning Money
    Replies: 0
    Last Post: 06-12-2008, 03:56 PM
  3. You never know where life will take you.
    By port5900 in forum Off Topic
    Replies: 3
    Last Post: 05-12-2008, 11:42 PM
  4. Second Life
    By linglingzero in forum Off Topic
    Replies: 18
    Last Post: 09-03-2007, 11:18 AM
  5. Our Life
    By Chirantha in forum Off Topic
    Replies: 7
    Last Post: 04-19-2006, 08:16 AM

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