SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast boboli's Avatar
    Join Date
    Mar 2003
    Location
    Venice - Italy
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem with a form to UPDATE DB

    Hi all...
    I'm very new to PHP/MySql and I'm trying to solve my problem:
    I have a table name risultati1 (results) with the following fields:
    id_match
    week
    id_c (id of the team playing home)
    id_f (id of the team playing away)
    g_c (points scored by the home team)
    g_f (points scored by the away team)

    every week I have 4 matches and I would like to update all the results together without doing it separately...
    this is the form I have created with a FIX week for trying purposal (it will become a variable)

    PHP Code:
    <? 
    include("dbinfo.inc.php" );
     
    $db mysql_connect("localhost""$dbuser""" ) or die("Problem connecting" ); 
    mysql_select_db("$dbname",$db)or die("Problem selecting database" ); 
    $result mysql_query("SELECT * FROM risultati1 WHERE week='24'",$db); 
     
    echo 
    "<table width='100%' border='1' cellpadding='0' cellspacing='0' bordercolor='#9999CC' class='risultati' background='Images/prova2.jpg'>\n";
                echo 
    "<tr bgcolor='#99CCFF'>\n"
                echo 
    "<td colspan='4'><div align='center'><strong><font color='#000000' face='Arial, Helvetica, sans-serif'>Risultati</font></strong></div></td>\n";
     
    while(
    $myrow mysql_fetch_array($result)) 

    $id_match $myrow["id_match"];
    $week $myrow["week"]; 
    $id_c $myrow["id_c"]; 
    $id_f $myrow["id_f"]; 
    $g_c $myrow["g_c"]; 
    $g_f $myrow["g_f"]; 
    echo 
    "<FORM METHOD=GET ACTION=\"ins_risultati.php\">";
    include(
    "risultati.inc.php" );
    echo 
    "<tr bordercolor='#9999CC'>\n"
    echo 
    "<td width='35%' height='40' align='center'><font class='risultatitabebold'>$id_c</font></td>\n";
    echo 
    "<td width='35% height='40' align='center'><font class='risultatitabebold'>$id_f</font></td>\n";
    echo 
    "<td width='15%' height='40' align='center'><INPUT TYPE=\"TEXT\" NAME=\"g_c\" VALUE=\"$g_c\" SIZE=\"4\"></td>\n";
    echo 
    "<td width='15%' height='40' align='center'><INPUT TYPE=\"TEXT\" NAME=\"g_c\" VALUE=\"$g_f\" SIZE=\"4\"></td>\n";
    }
    echo 
    "</TABLE>\n"
    $id_c=(urlencode($id_c));
    $id_f=(urlencode($id_f));
    echo 
    "<INPUT TYPE=\"HIDDEN\" NAME=\"id_match\" VALUE=$id_match>";
    echo 
    "<INPUT TYPE=\"HIDDEN\" NAME=\"id_c\" VALUE=$id_c>";
    echo 
    "<INPUT TYPE=\"HIDDEN\" NAME=\"id_f\" VALUE=$id_f><BR>";
    echo 
    "<INPUT TYPE=SUBMIT VALUE=\"Inserisci i risultati\">";
    ?>
    and this is the ins_risultati.php file
    PHP Code:
    <? 
    include("dbinfo.inc.php" );
     
    $db mysql_connect("localhost""$dbuser""" ) or die("Problem connecting" ); 
    mysql_select_db("$dbname",$db)or die("Problem selecting database" ); 
    $id_c=(urldecode($id_c));
    $id_f=(urldecode($id_f));
    $sql="UPDATE risultati1 SET g_c='$g_c', g_f='$g_f' WHERE id_match='$id_match'";
    ?>
    obviously it is not inserting the results and if I look at the URL I see only the last match team names and only the g_c variable for 8 times


    pls HELP ME !!!!!!!!!!!!!!!!!!!!!

    Roberto AKA Boboli

  2. #2
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this UPDATE sql instead
    PHP Code:
    <?php
    $sql
    ="UPDATE risultati1 SET g_c='$_GET[g_c]', g_f='$_GET[g_f]' WHERE id_match='$_GET[id_match]'";
    ?>
    You also need to actullay run your query using the mysql_query() function.

    To check if your $sql is correct, try to echo it out, to see if it's as supposed.

    Hope this helps

    -Helge

  3. #3
    SitePoint Enthusiast boboli's Avatar
    Join Date
    Mar 2003
    Location
    Venice - Italy
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Helge
    Try this UPDATE sql instead
    PHP Code:
    <?php
    $sql
    ="UPDATE risultati1 SET g_c='$_GET[g_c]', g_f='$_GET[g_f]' WHERE id_match='$_GET[id_match]'";
    ?>
    You also need to actullay run your query using the mysql_query() function.

    To check if your $sql is correct, try to echo it out, to see if it's as supposed.

    Hope this helps

    -Helge
    Thank you Helge... I'll try once home...
    By the way... How do I echo the page ? And what do you mean with
    "run your query using the mysql_query() function" ???
    Thanx
    Roberto

  4. #4
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by boboli
    By the way... How do I echo the page ?
    Don't you already? Please explain a bit more what you mean.
    Quote Originally Posted by boboli
    And what do you mean with
    "run your query using the mysql_query() function" ???
    In your ins_risultati.php you are not quering your db with the sql. You need to do, as you do in your other file.
    PHP Code:
    <?php
    $sql
    ="UPDATE risultati1 SET g_c='$_GET[g_c]', g_f='$_GET[g_f]' WHERE id_match='$_GET[id_match]'";
    $result mysql_query($sql) or die(mysql_error());
     
    if(
    mysql_affected_rows($result) == -1) {
        echo 
    "The database didn't get updated";
    } else {
       echo 
    "The database got updated successfully";
    }
    ?>
    I also noted something else. You have the same name on two hidden input fields.
    Two fields are named "g_c". That means that second will over overwrite the first one.

    -Helge

  5. #5
    SitePoint Enthusiast boboli's Avatar
    Join Date
    Mar 2003
    Location
    Venice - Italy
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Helge
    Don't you already? Please explain a bit more what you mean.In your ins_risultati.php you are not quering your db with the sql. You need to do, as you do in your other file.
    PHP Code:
    <?php
    $sql
    ="UPDATE risultati1 SET g_c='$_GET[g_c]', g_f='$_GET[g_f]' WHERE id_match='$_GET[id_match]'";
    $result mysql_query($sql) or die(mysql_error());
     
    if(
    mysql_affected_rows($result) == -1) {
        echo 
    "The database didn't get updated";
    } else {
    echo 
    "The database got updated successfully";
    }
    ?>
    I also noted something else. You have the same name on two hidden input fields.
    Two fields are named "g_c". That means that second will over overwrite the first one.

    -Helge
    Thank You Helge...
    1 you mean I should echo the $result ??? (I feel very dummy...)
    2 copy and paste sometimes cause errors...
    3 you are absolutely right... it was in the original file but i did not paste it...
    By the way... to make me feel better... can you make an example with the above code on how to echo the results ??? I will feel really better... maybe I alrewdy know how to do it but my native language is italian and my technical php language is not excellent... Do you mean to add for example after
    PHP Code:
    $result mysql_query($sql) or die(mysql_error());
     
    if(
    mysql_affected_rows($result) == -1) {
        echo 
    "The database didn't get updated";
    } else {
    echo 
    "The database got updated successfully"
    something like

    echo "result is $result<br><p></p>";

    Many Thanx and...I will let you know once I'll modify the page!!!

    Roberto
    Last edited by boboli; Mar 11, 2003 at 12:13.

  6. #6
    SitePoint Enthusiast boboli's Avatar
    Join Date
    Mar 2003
    Location
    Venice - Italy
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is what happen:
    I only update the LAST match (last of 4), the names have a "+" instead of spaces

    Finally this is the URL:

    notebook/LF/ins_risultati.php?g_c=2&g_f=3&g_c=0&g_f=0&g_c=4&g_f=4&g_c=0&g_f=0&id_match=96&id_c=AS%252BPilarella&id_f=Ciao%252BWena


    as you can see I have the 8 scores but only 1 ID_match and one match team names...
    Last edited by boboli; Mar 12, 2003 at 11:45.

  7. #7
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I only update the LAST match (last of 4)
    I think it's because the way you build your form. You are giving the same input name on four matches. That means only the last one get send, because this one has overwritten the three other.

    the names have a "+" instead of spaces
    You don't have to worry about it. It will be removed automaticcaly.

    -Helge


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
  •