Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 7 of 7

Thread: Updating MySQL

  1. #1
    Junior Member
    Join Date
    May 2004
    Location
    Cockeysville Maryland (Im serious)
    Posts
    29
    Member #
    6119
    Hi I am new to PHP and MySQL and have been having trouble with a few lines of code.

    These are the lines I have have:

    $vote = $_REQUEST["vote"];

    mysql_query ("update poll set '$vote' = '$vote'+1");


    and I have also tried this:

    mysql_query ("update fritspoll set '$_REQUEST["vote"]' = '$_REQUEST["vote"]'+1");

    I cant get this to update my databases at "vote" how should I rewrite this to work?

    Thanx

  2.  

  3. #2
    Senior Member seanmiller's Avatar
    Join Date
    Sep 2003
    Location
    Glastonbury, UK
    Posts
    868
    Member #
    3263
    Liked
    1 times
    No, you can't do this.. you are trying to update a variable to another variable using a MySQL command...

    What are you trying to do ? Update a table with the number of votes? Please post and I'll set you straight... it is not quite clear at present...

    Sean

  4. #3
    Junior Member
    Join Date
    May 2004
    Location
    Cockeysville Maryland (Im serious)
    Posts
    29
    Member #
    6119
    Sorry
    Im trying to create a poll for my AIM profile so I can only use links and no "advanced" html and no scrips. The links I will have in my profile will link to a page with this script. The links will have ?vote='yes', 'no', or 'maby' and my table has colloms for yes, no, and maby. This script is just supposed to update the values in these cells.

    Thanks

  5. #4
    Senior Member ajaspers's Avatar
    Join Date
    Apr 2003
    Posts
    149
    Member #
    1150
    1) You can't use quotes in column names
    2) You need to do more input validation

    PHP Code:
    $vote $_REQUEST["vote"];
    if(!
    in_array($vote, array("yes""no""maybe"))) die("The valid poll options are 'yes', 'no' and 'maybe'.");

    mysql_query("UPDATE poll SET $vote=$vote + 1"); 

  6. #5
    Junior Member
    Join Date
    May 2004
    Location
    Cockeysville Maryland (Im serious)
    Posts
    29
    Member #
    6119
    That still dosent work.
    All my other code works, it's just these lines that dont work. There is also no error that comes up.
    I have replaced 'vote' with yes, no, and maby and they update fine.

    The other option I have thought about is to use if statements for yes, no, and maby and then not have $vote in the update line.

  7. #6
    Senior Member ajaspers's Avatar
    Join Date
    Apr 2003
    Posts
    149
    Member #
    1150
    Try this for the query line:
    PHP Code:
    mysql_query("UPDATE poll SET $vote=$vote + 1") or die("<pre>" mysql_error() . "</pre>"); 

  8. #7
    Junior Member
    Join Date
    May 2004
    Location
    Cockeysville Maryland (Im serious)
    Posts
    29
    Member #
    6119
    Thanks
    It works!!!


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 03:10 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com