SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict Johana Solendhal's Avatar
    Join Date
    Aug 2004
    Location
    Land of the free
    Posts
    252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can you help with some simple calculations amigos?

    Here's what I'm trying to do: The user inputs a value in the field, and the submits the form. A query is performed in order to find a match in the id column, and if a match is found, the value of the points column is incremented by 1, if no match is found, a return message : No match was found is performed.

    This is what I have managed to come up with, gives me all sort of errors of course, and it really doesn't do what I want it too. :

    My Form
    PHP Code:
     <form action="calc.php" method="post">
      <
    input name="idquery" type="text" size="4" maxlength="4">
      <
    input type="submit" name="Submit" value="Submit">
    </
    form
    Calc.php
    PHP Code:
    <?php 
    include "config.php"
    mysql_connect($config['sql_host'], $config['sql_username'], $config['sql_password']); 
    mysql_select_db($config['sql_database']); 
    $sql mysql_query("SELECT id,points FROM members "); 
    $rmysql_fetch_array($sql);
    if (
    $id == $idquery) { 
    (
    $increment ". $r['points'] .");
    (
    $newvalue "$increment++");
    }
    $query mysql_query("UPDATE members SET points='$newvalue' WHERE id='$id' "); 
    echo 
    "Match found, Incremented +1 to existing value";
    } else {
    echo 
    "Match not found";
     }
    ?>

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    What errors are you getting?

    Try something like:
    PHP Code:
    <?php 
    include "config.php"
    mysql_connect($config['sql_host'], $config['sql_username'], $config['sql_password']); 
    mysql_select_db($config['sql_database']); 
    $sql mysql_query("SELECT id, points FROM members"); 
    $r mysql_fetch_assoc($sql); 
    $num mysql_num_rows($sql);

    if(
    $num == 0) {
    echo 
    "No Match";
    } else {
    $add $r['points']+1;

    $query mysql_query("UPDATE members SET points='$add' WHERE id='$id' "); 
    echo 
    "Match found, Incremented +1 to existing value"

    ?>

    *NOT TESTED!*

    SpikeZ
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    SitePoint Addict Johana Solendhal's Avatar
    Join Date
    Aug 2004
    Location
    Land of the free
    Posts
    252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    HI there and Gracias!

    Your code doesn't give me any errors, but it doesn't seem to what I want it to.

    the idea is for the query to search for a user ID match, and then, if found, increment +1 to the points column in the same database. At the moment it doesn't seem to be adding any value whatsoever!

    PS thank you so much for the help!

  4. #4
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could just do:
    PHP Code:
    <?php
    include "config.php";
    mysql_connect($config['sql_host'], $config['sql_username'], $config['sql_password']);
    mysql_select_db($config['sql_database']);
    $sql "UPDATE members SET points=points+1 WHERE id=".$_POST['idquery'];
    mysql_query($sql) or die(mysql_error());
    if(
    mysql_affected_rows() == 0){
        echo 
    'No Match';
    } else {
        echo 
    'Match Found';
    }
    ?>

  5. #5
    SitePoint Addict Johana Solendhal's Avatar
    Join Date
    Aug 2004
    Location
    Land of the free
    Posts
    252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    mark999, that worked wonderfully!!

    Can I be your Bond girl?


Bookmarks

Posting Permissions

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