Any Ideas why the 2nd and 3rd Query do not work?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nick Truscott

    Any Ideas why the 2nd and 3rd Query do not work?

    <?

    // scoreinput.php - input a match score when match selected from list
    ?>
    <html>
    <head>
    <basefont face="Verdana">
    </head>

    <body>

    <!-- standard page header begins -->
    <p>&nbsp;<p>

    <table width="100%" cellspacing="0" cellpadding="5" >
    <tr>
    <td></td>
    </tr>
    <tr>
    <td bgcolor="Red">< font size="-1" color="White">< b>Cornwall County
    Short Mat Bowling Association : Administration :

    League Results : Edit</b></font></td>
    </tr>
    </table>
    <!-- standard page header ends -->

    <p>

    <?
    // includes
    include("../conf.php");
    include("../functions.php") ;

    // form not yet submitted
    // display initial form with values pre-filled
    if (!$submit)
    {
    // open database connection
    $connection = mysql_connect($ host, $user, $pass) or die ("Unable to
    connect!");

    // select database
    mysql_select_db ($db) or die ("Unable to select database!");

    // generate and execute query
    $query = "SELECT * FROM matches WHERE id = '$id'";
    $result = mysql_query($qu ery) or die ("Error in query: $query. " .
    mysql_error());

    // if a result is returned
    if (mysql_num_rows ($result) > 0)
    {
    // turn it into an object
    $row = mysql_fetch_obj ect($result);

    // print form with values pre-filled
    ?>
    <table cellspacing="5" cellpadding="5" >
    <form action="<? echo $PHP_SELF; ?>" method="POST">
    <input type="hidden" name="id" value="<? echo $row->id; ?>">
    <tr>
    <td valign="top"><b >Date<b></td>
    <td><? echo $row->date; ?></td>
    </tr>
    <tr>
    <td valign="top"><b ><? echo $row->home_team; ?></b></td>
    <td><input size="5" name="home_shot s" value="<? echo
    $row->home_shots; ?>"></td>
    </tr>
    <tr>
    <td valign="top"><b ><? echo $row->away_team; ?></b></td>
    <td><input size="5" name="away_shot s" value="<? echo
    $row->away_shots; ?>"></td>
    </tr>
    <tr>
    <td valign="top"><b >Match Completed</b></td>
    <td><input type="checkbox" name="completed " value="Y"></td>
    </tr>
    <tr>
    <td colspan=2><inpu t type="Submit" name="submit" value="Update"> </td>
    </tr>
    </form>
    </table>
    <?
    }
    // no result returned
    // print graceful error message
    else
    {
    echo "<font size=-1>That match could not be located in our
    database.</font>";
    }
    }
    // form submitted
    // start processing it
    else
    {
    // set up error list array
    $errorList = array();
    $count = 0;

    // check for errors
    // if none found...
    if (sizeof($errorL ist) == 0)
    {
    // open database connection
    $connection = mysql_connect($ host, $user, $pass) or die ("Unable to
    connect!");

    // select database
    mysql_select_db ($db) or die ("Unable to select database!");

    // generate and execute query
    if ($home_shots > $away_shots) {
    $querymatches = "UPDATE matches
    SET home_shots = '$home_shots',
    away_shots = '$away_shots',
    completed = '$completed' WHERE id = '$id'";
    $queryhome = "UPDATE teams
    SET played = played + 1,
    won = won + 1,
    sf = sf + '$home_shots',
    sa = sa + '$away_shots',
    points = points + 2 WHERE team = '$home_team'";
    $queryaway = "UPDATE teams
    SET played = played + 1,
    lost = lost + 1,
    sa = sa + '$home_shots',
    sf = sf + '$away_shots' WHERE team = '$away_team'";
    } elseif ($home_shots < $away_shots) {
    $querymatches = "UPDATE matches
    SET home_shots = '$home_shots',
    away_shots = '$away_shots',
    completed = '$completed' WHERE id = '$id'";
    $queryaway = "UPDATE teams
    SET played = played + 1,
    won = won + 1,
    sa = sa + '$home_shots',
    sf = sf + '$away_shots',
    points = points + 2 WHERE team = '$away_team'";
    $queryhome = "UPDATE teams
    SET played = played + 1,
    lost = lost + 1,
    sf = sf + '$home_shots',
    sa = sa + '$away_shots' WHERE team = '$home_team'";
    } else {
    $querymatches = "UPDATE matches
    SET home_shots = '$home_shots',
    away_shots = '$away_shots',
    completed = '$completed' WHERE id = '$id'";
    $queryhome = "UPDATE teams
    SET played = played + 1,
    drawn = drawn + 1,
    sf = sf + '$home_shots',
    sa = sa + '$away_shots',
    points = points + 1 WHERE team = '$home_team'";
    $queryaway = "UPDATE teams
    SET played = played + 1,
    drawn = drawn + 1,
    sa = sa + '$home_shots',
    sf = sf + '$away_shots',
    points = points + 1 WHERE team = '$away_team'";
    }
    $result1 = mysql_query($qu erymatches) or die ("Error in query:
    $query. " . mysql_error());
    $result2 = mysql_query($qu eryhome) or die ("Error in query: $query.
    " . mysql_error());
    $result3 = mysql_query($qu eryaway) or die ("Error in query: $query.
    " . mysql_error());

    // print result
    echo "<font size=-1>Update successful. <a href=list.php>G o back to
    the main menu</a>.</font>";

    // close database connection
    mysql_close($co nnection);
    }
    else
    {
    // errors occurred
    // print as list
    echo "<font size=-1>The following errors were encountered: <br>";
    echo "<ul>";
    for ($x=0; $x<sizeof($erro rList); $x++)
    {
    echo "<li>$error List[$x]";
    }
    echo "</ul></font>";
    }
    }
    ?>

    <!-- standard page footer begins -->
    <p>
    <table width="100%" cellspacing="0" cellpadding="5" >
    <tr>
    <td align="center"> &nbsp;</td>
    </tr>
    </table>
    <!-- standard page footer ends -->


    </body>
    </html>
  • Aggro

    #2
    Re: Any Ideas why the 2nd and 3rd Query do not work?

    Nick Truscott wrote:
    [color=blue]
    > // scoreinput.php - input a match score when match selected from list[/color]

    Echo your queries to screen and copy-paste them to mysql client. Then
    copy-paste the queries, error messages from MySQL and table structure
    for tables that are used in queries, here and it will make it a lot
    easier for us to help you. Also tell what version of MySQL you are
    using. We might see the errors directly from the queries, so it might be
    enough if you copy-paste those here. But it is easier if you show it all
    at once.

    Comment

    • Nick Truscott

      #3
      Re: Any Ideas why the 2nd and 3rd Query do not work?

      Here is the table structure, I do not get an error message, just the
      2nd and 3rd queries do not run.

      CREATE TABLE `matches` (
      `id` int(11) NOT NULL auto_increment,
      `date` date NOT NULL default '0000-00-00',
      `time` time NOT NULL default '00:00:00',
      `home_team` text NOT NULL,
      `away_team` text NOT NULL,
      `home_shots` int(11) NOT NULL default '0',
      `away_shots` int(11) NOT NULL default '0',
      `league` text NOT NULL,
      `completed` text,
      PRIMARY KEY (`id`)
      ) TYPE=MyISAM;

      CREATE TABLE `teams` (
      `id` int(11) NOT NULL auto_increment,
      `league` text NOT NULL,
      `team` text NOT NULL,
      `played` int(11) NOT NULL default '0',
      `won` int(11) NOT NULL default '0',
      `drawn` int(11) NOT NULL default '0',
      `lost` int(11) NOT NULL default '0',
      `sf` int(11) NOT NULL default '0',
      `sa` int(11) NOT NULL default '0',
      `bonus` int(11) NOT NULL default '0',
      `points` int(11) NOT NULL default '0',
      PRIMARY KEY (`id`)
      ) TYPE=MyISAM;


      Aggro <spammerdream@y ahoo.com> wrote in message news:<SYV2d.121 $pU.42@read3.in et.fi>...[color=blue]
      > Nick Truscott wrote:
      >[color=green]
      > > // scoreinput.php - input a match score when match selected from list[/color]
      >
      > Echo your queries to screen and copy-paste them to mysql client. Then
      > copy-paste the queries, error messages from MySQL and table structure
      > for tables that are used in queries, here and it will make it a lot
      > easier for us to help you. Also tell what version of MySQL you are
      > using. We might see the errors directly from the queries, so it might be
      > enough if you copy-paste those here. But it is easier if you show it all
      > at once.[/color]

      Comment

      • Aggro

        #4
        Re: Any Ideas why the 2nd and 3rd Query do not work?

        Nick Truscott wrote:[color=blue]
        > Here is the table structure, I do not get an error message, just the
        > 2nd and 3rd queries do not run.[/color]

        What do you mean they don't run? Don't they do the result you are
        expecting or are they not called and executed at all?

        If the query returns 0 rows, could you echo it on the screen and
        copy-paste here? You have only shown us the php code which is used to
        generate the queries. It is very very very common that programmer makes
        a mistake while generating the query, for example some value is
        incorrect. That's why it is important that you echo the real query you
        are trying to use to see what the query really looks like. It is also a
        lot easier to see from there what the problem might be.

        If they are not called at all, it is a problem with your php code and
        questions about php should be asked in a different group, like
        comp.lang.php for example.

        Comment

        Working...