Avatar billede zidane5 Nybegynder
08. juli 2011 - 20:41 Der er 6 kommentarer og
1 løsning

Sql fejl ! Hjælp.

Jeg kører med php fusion og har hentet en infusion, men får dog følgende fejlmelding:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1.             

Filen ser således ud:

<?php
/*-------------------------------------------------------+
| PHP-Fusion Content Management System
| Copyright © 2002 - 2008 Nick Jones
| http://www.php-fusion.co.uk/
+--------------------------------------------------------+
| Filename: adm_results.php
| Author: ChSchuetz
+--------------------------------------------------------+
| This program is released as free software under the
| Affero GPL license. You can redistribute it and/or
| modify it under the terms of this license which you
| can read by viewing the included agpl.txt or online
| at www.gnu.org/licenses/agpl.html. Removal of this
| copyright header is strictly prohibited without
| written permission from the original author(s).
+--------------------------------------------------------*/
if (!checkrights("WST")) { redirect("../index.php"); }

if (isset($_POST['save']) && $_POST['save'] == TRUE) {   
    $result1 = dbquery("select * from ".$db_prefix."wst_leagues where league_id=$lid");
    $data1 = dbarray($result1);   
    $md = isset($_POST['match']) ? $_POST['match'] : 0;
    $m_id = isset($_POST['m_id']) ? $_POST['m_id'] : array();
    $tipp1 = isset($_POST['tipp1']) ? $_POST['tipp1'] : array();
    $tipp2 = isset($_POST['tipp2']) ? $_POST['tipp2'] : array();
    $tid = isset($_POST['tid']) ? $_POST['tid'] : array();
    $tid2 = isset($_POST['tid2']) ? $_POST['tid2'] : array();
    for ($i=0; $i<sizeof($m_id); $i++) {
        $result = dbquery("select * from ".$db_prefix."wst_results where league_id=$lid and matchday_id=$md and match_id=$m_id[$i]");
        $data = dbarray($result);
               
        if (!isset($data['team1']))
            if (isnum($tipp1[$i]) && isnum($tipp2[$i]))
                $result = dbquery("insert into ".$db_prefix."wst_results(league_id, matchday_id, match_id, team1, team2) values($lid, $md, $m_id[$i], $tipp1[$i], $tipp2[$i])");
        if (isset($data['team1']))
            if (isnum($tipp1[$i]) && isnum($tipp2[$i]))
                $result = dbquery("update ".$db_prefix."wst_results set team1=$tipp1[$i], team2=$tipp2[$i] where
                league_id=$lid and matchday_id=$md and match_id=$m_id[$i]");
                       
        $result = dbquery("select * from ".$db_prefix."wst_leagues where league_id=$lid");
        $data = dbarray($result);
               
        $conf = dbarray(dbquery("select * from ".$db_prefix."wst_config where league_id=$lid"));
               
        $vicp = $conf['config_vic'];
        $tiep = $conf['config_tie'];
               
        if ($data['tbl_enabled'] == 1) {
            $result = dbquery("select * from ".$db_prefix."wst_teampoints where league_id=$lid and matchday_id=$md and match_id=$m_id[$i] and team_id=$tid[$i]");
            $data = dbarray($result);
            if (!isset($data['points'])) {
                if (isnum($tipp1[$i]) && isnum($tipp2[$i])) {
                    if ($tipp1[$i]> $tipp2[$i]) {
                        $result = dbquery("insert into ".$db_prefix."wst_teampoints(league_id, matchday_id, match_id, team_id, team_win, team_tie, team_lose, score_for, score_against, points)
                        values($lid, $md, $m_id[$i], $tid[$i], 1, 0, 0, $tipp1[$i], $tipp2[$i], $vicp)");
                        $result = dbquery("insert into ".$db_prefix."wst_teampoints(league_id, matchday_id, match_id, team_id, team_win, team_tie, team_lose, score_for, score_against, points)
                        values($lid, $md, $m_id[$i], $tid2[$i], 0, 0, 1, $tipp2[$i], $tipp1[$i], 0)");
                    }
                    if ($tipp1[$i]==$tipp2[$i]) {
                        $result = dbquery("insert into ".$db_prefix."wst_teampoints(league_id, matchday_id, match_id, team_id, team_win, team_tie, team_lose, score_for, score_against, points)
                        values($lid, $md, $m_id[$i], $tid[$i], 0, 1, 0, $tipp1[$i], $tipp2[$i], $tiep)");
                        $result = dbquery("insert into ".$db_prefix."wst_teampoints(league_id, matchday_id, match_id, team_id, team_win, team_tie, team_lose, score_for, score_against, points)
                        values($lid, $md, $m_id[$i], $tid2[$i], 0, 1, 0, $tipp2[$i], $tipp1[$i], $tiep)");
                    }
                    if ($tipp1[$i]< $tipp2[$i]) {
                        $result = dbquery("insert into ".$db_prefix."wst_teampoints(league_id, matchday_id, match_id, team_id, team_win, team_tie, team_lose, score_for, score_against, points)
                        values($lid, $md, $m_id[$i], $tid[$i], 0, 0, 1, $tipp1[$i], $tipp2[$i], 0)");
                        $result = dbquery("insert into ".$db_prefix."wst_teampoints(league_id, matchday_id, match_id, team_id, team_win, team_tie, team_lose, score_for, score_against, points)
                        values($lid, $md, $m_id[$i], $tid2[$i], 1, 0, 0, $tipp2[$i], $tipp1[$i], $vicp)");
                    }
                }
            } else {
                    if (isnum($tipp1[$i]) && isnum($tipp2[$i]))    {
                        if ($tipp1[$i]> $tipp2[$i]) {
                            $result = dbquery("update ".$db_prefix."wst_teampoints set team_win=1, team_tie=0, team_lose=0, score_for=$tipp1[$i], score_against=$tipp2[$i], points=$vicp
                            where league_id=$lid and matchday_id=$md and match_id=$m_id[$i] and team_id=$tid[$i]");
                               
                            $result = dbquery("update ".$db_prefix."wst_teampoints set team_win=0, team_tie=0, team_lose=1, score_for=$tipp2[$i], score_against=$tipp1[$i], points=0
                            where league_id=$lid and matchday_id=$md and match_id=$m_id[$i] and team_id=$tid2[$i]");                           
                        }   
                        if ($tipp1[$i]==$tipp2[$i]) {
                            $result = dbquery("update ".$db_prefix."wst_teampoints set team_win=0, team_tie=1, team_lose=0, score_for=$tipp1[$i], score_against=$tipp2[$i], points=$tiep
                            where league_id=$lid and matchday_id=$md and match_id=$m_id[$i] and team_id=$tid[$i]");
                               
                            $result = dbquery("update ".$db_prefix."wst_teampoints set team_win=0, team_tie=1, team_lose=0, score_for=$tipp2[$i], score_against=$tipp1[$i], points=$tiep
                            where league_id=$lid and matchday_id=$md and match_id=$m_id[$i] and team_id=$tid2[$i]");
                        }
                        if ($tipp1[$i]< $tipp2[$i]) {
                            $result = dbquery("update ".$db_prefix."wst_teampoints set team_win=0, team_tie=0, team_lose=1, score_for=$tipp1[$i], score_against=$tipp2[$i], points=0
                            where league_id=$lid and matchday_id=$md and match_id=$m_id[$i] and team_id=$tid[$i]");
                               
                            $result = dbquery("update ".$db_prefix."wst_teampoints set team_win=1, team_tie=0, team_lose=0, score_for=$tipp2[$i], score_against=$tipp1[$i], points=$vicp
                            where league_id=$lid and matchday_id=$md and match_id=$m_id[$i] and team_id=$tid2[$i]");
                        }
                    }   
            }   
        }
    }

    if ($data1['istoto'] == 1) {                           
        for ($i=0; $i<sizeof($m_id); $i++) {           
            $tt = $toto[$i];
            $result = dbquery("select * from ".$db_prefix."wst_results where league_id=$lid and matchday_id=$md and match_id=$m_id[$i]");
            $data = dbarray($result);
               
            if (!isset($data['toto']))
                $result = dbquery("insert into ".$db_prefix."wst_results(league_id, matchday_id, match_id, toto) values($lid, $md, $m_id[$i], $tt)");
                       
            if (isset($data['toto']))
                $result = dbquery("update ".$db_prefix."wst_results set toto=$tt where
                league_id=$lid and matchday_id=$md and match_id=$m_id[$i]");                   
        }
    }
    $st_wahl = true;
    $st_list = (isset($_POST['match']) && isNum($_POST['match'])) ? $_POST['match'] : 0;
}   
       
// TOTO !!!!!!!!!!!!!
$result_toto = dbquery("select * from ".$db_prefix."wst_leagues where league_id=$lid");
$toto = dbarray($result_toto);   
   
$matchdid = (isset($_GET['md']) && isNum($_GET['md'])) ? $_GET['md'] : 1;
   
       
if ((isset($_POST['st_wahl']) && $_POST['st_wahl'] == TRUE) || isset($matchdid) || isset($md)) {
    $md = (isset($_GET['md']) && isNum($_GET['md'])) ? $_GET['md'] : 1;
    if ((isset($_POST['st_wahl']) && $_POST['st_wahl'] == TRUE))
        $md = (isset($_POST['st_list']) && isNum($_POST['st_list'])) ? $_POST['st_list'] : 0;
    else {
        if (isset($md) && !isset($st_wahl))
            $md=$md;   
        if (isset($matchdid) && !isset($_POST['st_wahl']))
            $md=$matchdid;
               
        if (isset($_GET['md']) && !isset($st_wahl))
            //$md= isNum($_GET['md']) ? $_GET['md'] : 1;   
            $md= $matchdid;   
    }
    include "../inc/md_select.php";   
           
    opentable($locale['wst116']." ".$md.". ".$locale['wst116']);
        echo '<center><form method="post"><table width="100%" align="center" cellpadding="4" cellspacing="1" border="0" class="tbl-border"><tr class="tbl1">';
        echo '<tr class="tbl2"><td align="center">'.$locale['wst130'].'</td><td align="center">'.$locale['wst131'].'</td>
        <td align="center"></td><td align="center">'.$locale['wst132'].'</td><td align="center"></td>
        <td align="center">'.$locale['wst133'].'</td><td align="center" colspan="2">'.$locale['wst134'].'</td>
        <td align="center">'.$locale['wst152'].'</td><td align="center" colspan="2">'.$locale['wst153'].'</td>
        <td align="center">'.$locale['wst209'].'</td></tr>';
        $result = dbquery("select * from ".$db_prefix."wst_matchdays where league_id=$lid and matchday_id=$md order by matchday_datestamp");
        $zeige_calc = 0;  //TOXIC
        while ($data = dbarray($result)) {
            $tid = $data['team1'];        
            echo '<input type="hidden" name="match" value="'.$data['matchday_id'].'">';
            $result2 = dbquery("select * from ".$db_prefix."wst_teams where team_id=$tid");
            $data2 = dbarray($result2);
            $team1_details = dbarray(dbquery("select * from ".$db_prefix."wst_teaminfo where team_id=$tid"));   

            echo '<input type="hidden" name="tid[]" value="'.$tid.'">';
            $tid2 = $data['team2'];
            $result3 = dbquery("select * from ".$db_prefix."wst_teams where team_id=$tid2");
            $data3 = dbarray($result3);
            $team2_details = dbarray(dbquery("select * from ".$db_prefix."wst_teaminfo where team_id=$tid2"));   
            echo '<input type="hidden" name="tid2[]" value="'.$tid2.'">';
               
            $datum = getdate($data['matchday_datestamp']);
            echo '<tr class="tbl1">';
            echo '<td align="center"><input type="hidden" name="m_id[]" value="'.$data['match_id'].'">
            '.date("d.m.Y", $data['matchday_datestamp']).'</td>';       
            echo '<td align="center">'.date("H:i", $data['matchday_datestamp']).'</td>';
            echo '<td align="center">';
            if ($data2['team_logo'] != "") {
                if (file_exists("../img/teams/".$data2['team_logo'])) {
                    if (isset($team1_details['team_id']))
                        echo '<a href="../league.php?act=sh_td&lid='.$lid.'&tid='.$tid.'" title="'.$data2['team_name'].'"><img src="../img/teams/'.$data2['team_logo'].'" height="21" border="0"></a></td>';
                    else {
                        if ($data2['team_website'] != "")
                            echo '<a href="'.$data2['team_website'].'" title="'.$data2['team_name'].'" target="_blank"><img src="../img/teams/'.$data2['team_logo'].'" border="0" height="21"></a></td>';
                        else echo '<img src="../img/teams/'.$data2['team_logo'].'" height="21"></td>';
                    }
                } else echo '<img src="../img/nologo.gif" height="21"></td>';
            }    else echo '<img src="../img/nologo.gif" height="21"></td>';
               
            if (isset($team1_details['team_id']))
                echo '<td align="center"><a href="../league.php?act=sh_td&lid='.$lid.'&tid='.$tid.'" title="'.$data2['team_name'].'">'.$data2['team_name'].'</a></td>';
            else {
                if ($data2['team_website'] != "")
                    echo '<td align="center"><a href="'.$data2['team_website'].'" title="'.$data2['team_name'].'" target="_blank">'.$data2['team_name'].'</a></td>';
                else echo '<td align="center">'.$data2['team_name'].'</td>';   
            }
                   
            echo '<td align="center">';
           
            if ($data3['team_logo'] != "") {
                if (file_exists("../img/teams/".$data3['team_logo'])) {
                    if (isset($team2_details['team_id']))
                        echo '<a href="../league.php?act=sh_td&lid='.$lid.'&tid='.$tid2.'" title="'.$data3['team_name'].'"><img src="../img/teams/'.$data3['team_logo'].'" height="21" border="0"></a></td>';
                    else {
                        if ($data3['team_website'] != "")
                            echo '<a href="'.$data3['team_website'].'" title="'.$data3['team_name'].'" target="_blank"><img src="../img/teams/'.$data3['team_logo'].'" border="0" height="21"></a></td>';
                        else echo '<img src="../img/teams/'.$data3['team_logo'].'" height="21"></td>';
                    }
                } else echo '<img src="../img/nologo.gif" height="21"></td>';
            } else echo '<img src="../img/nologo.gif" height="21"></td>';
                   
            if (isset($team2_details['team_id']))
                echo '<td align="center"><a href="../league.php?act=sh_td&lid='.$lid.'&tid='.$tid2.'" title="'.$data3['team_name'].'">'.$data3['team_name'].'</a></td>';
            else {
                if ($data3['team_website'] != "")
                    echo '<td align="center"><a href="'.$data3['team_website'].'" title="'.$data3['team_name'].'" target="_blank">'.$data3['team_name'].'</a></td>';   
                else echo '<td align="center">'.$data3['team_name'].'</td>';   
            }
                                               
            $mmid = $data['match_id'];
            $result4 = dbquery("select * from ".$db_prefix."wst_results where league_id=$lid and matchday_id=$md and match_id=$mmid");
            $data4 = dbarray($result4);       

            if ($toto['istoto'] == 1) {           
                echo '<td align="center" colspan="2">
                <select name="toto[]">';   
              if ($data4['toto'] == 1)
                    echo '<option value=1 selected>'.$locale['wst137'].'</option>';
                else echo '<option value=1>'.$locale['wst137'].'</option>';
                if ($data4['toto'] == 0)
                    echo '<option value=0 selected>'.$locale['wst138'].'</option>';
                else echo '<option value=0>'.$locale['wst138'].'</option>';
                if ($data4['toto'] == 2)
                    echo '<option value=2 selected>'.$locale['wst139'].'</option>';
                else echo '<option value=2>'.$locale['wst139'].'</option>
                </select></td>';       
            }
           
            if ($toto['istoto'] == 0)    {           
                if (isset($data4['team1']))           
                    echo '<td align="center">'.$data4['team1'].'<input style="display:none" type="text" size="3" maxlength="3" name="tipp1[]" value="'.$data4['team1'].'" class="textbox"></td>';
                else echo '<td align="center"><input type="text" size="3" maxlength="3" name="tipp1[]" class="textbox"></td>';
                if (isset($data4['team2']))
                    echo '<td align="center">'.$data4['team2'].'<input style="display:none" type="text" size="3" maxlength="3" name="tipp2[]" value="'.$data4['team2'].'" class="textbox"></td>';
                else echo '<td align="center"><input type="text" size="3" maxlength="3" name="tipp2[]" class="textbox"></td>';
            }
               
            if (isset($data4['team1'])) {
                if ($data4['calc']==1) {
                    echo '<td align="center"><img src="../symbols/yes.gif"></td>';
                    echo '<td></td>';
                }    else {
                        echo '<td align="center"><img src="../symbols/no.gif"></td>';
                        echo '<td align="center"><a href="league_admin.php?act=calc_points&lid='.$lid.'&md='.$md.'&mid='.$mmid.'" title="'.$locale['wst271'].'"><img src="../symbols/calc.gif" border="0"></a></td>';
                        $zeige_calc = 1; //TOXIC
                }
            } else echo '<td></td><td></td>';
            echo '<td align="center"><a href="league_admin.php?act=del_result&lid='.$lid.'&md='.$md.'&mid='.$mmid.'" title="'.$locale['wst272'].'"><img src="../symbols/delete.png" border="0"></a></td>';
            echo '<td><a href="league_admin.php?act=edt_details&lid='.$lid.'&md='.$md.'&mid='.$mmid.'" title="'.$locale['wst273'].'">'.$locale['wst210'].'</a></td>';
        }
           
        // V1.1 // TOXIC
        if ($zeige_calc) {
            echo '</tr>';
            echo '<tr class="tbl1"><td align="right" colspan="9">'.$locale['wst359'].'</td>';
            echo '<td align="center"><a href="league_admin.php?act=calc_allpoints&lid='.$lid.'&md='.$md.'" title="'.$locale['wst359'].'"><img src="../symbols/calc.gif" border="0"></a></td>';
            echo '<td align="right" colspan="3"></td>';
            // V1.1
        }   
        echo '</tr><tr class="tbl2"><td align="center" colspan="13">
                    <input type="submit" name="save" value="'.$locale['wst140'].'" class="button">
                    </td></tr></table></form></center>';
    closetable();
}
?>
Avatar billede majbom Novice
08. juli 2011 - 21:05 #1
er du sikker på at det er i den fil problemet ligger?
der er jo ingen sql-kald i linje 1...
Avatar billede zidane5 Nybegynder
08. juli 2011 - 21:19 #2
Inde i infusionen er det denne fil det er galt med.. Hvordan ser sql ud ? Kan man overhovedet se det?
Avatar billede Slettet bruger
08. juli 2011 - 22:31 #3
Kunne det være dbquery funktionen som ikke kan lide linjeskift i query-strengen ?
- De mange "insert into"s  ender nemlig netop med en ) før linjeskifterne..
Avatar billede erikjacobsen Ekspert
10. juli 2011 - 01:00 #4
Er det ikke noget gammel kode??

Men fejlen du får er typisk fordi en linie som

  $result1 = dbquery("select * from ".$db_prefix."wst_leagues where league_id=$lid");

giver fejl når $lid er tom. Om det er denne linie ved jeg ikke, man man kan jo starte med at undersøge hvor $lid komer fra.
Avatar billede zidane5 Nybegynder
11. juli 2011 - 15:44 #5
Hvad er det jeg præcist skal gøre? Skal jeg indsætte ) elller hvad?
Avatar billede Slettet bruger
11. juli 2011 - 17:11 #6
Jeg vil foreslå at du prøver at samle de "suspekte" inserts på én linje hver - selvom de bliver lange..

Altså ændrer f.eks.:

$result = dbquery("insert into ".$db_prefix."wst_teampoints*(league_id, matchday_id, match_id, team_id, team_win, team_tie, team_lose, score_for, score_against, points)*
values($lid, $md, $m_id[$i], $tid[$i], 1, 0, 0, $tipp1[$i], $tipp2[$i], $vicp)");

Til:

$result = dbquery("insert into ".$db_prefix."wst_teampoints (league_id, matchday_id, match_id, team_id, team_win, team_tie, team_lose, score_for, score_against, points) values($lid, $md, $m_id[$i], $tid[$i], 1, 0, 0, $tipp1[$i], $tipp2[$i], $vicp)");

De 2 røde stjerner: insæt et mellemrum ved den første og fjern linjeskiftet ved den anden

Der er 3 blokke med lignende 2 inserts i hver - fra omkring linje 40 og frem

NB: Jeg lover ikke noget, men det er jo ret let at prøve af - om det så blot afkræfter min teori..
Avatar billede zidane5 Nybegynder
07. oktober 2011 - 10:40 #7
Jeg fandt desværre aldrig løsningen. takker for i prøvede at hjælpe!
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Computerworld tilbyder specialiserede kurser i database-management

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester