Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php] Parse error: syntax error, unexpected
UszaTek
post
Post #1





Grupa: Zarejestrowani
Postów: 46
Pomógł: 0
Dołączył: 15.07.2019

Ostrzeżenie: (0%)
-----


Cały kod;

Kod
<?php
    $conn = mysqli_connect("xxxxl", "mxxxxst", "Mxxx2$", "mxxxst");
    
    if($conn === false)
    {
        die("ERROR: Could not connect. " .mysqli_connect_error());
    }

    $query="SELECT * FROM stat";
    $result=mysqli_query($conn, $query);
          
    function validation_sql($c, $sql)
    {
        if(mysqli_query($c, $sql))
    {
        echo "<h3>data stored in a database successfully. "
            . " Please browse your localhost php my admin"
            . " to view the updated data</h3>";

        echo nl2br("$TemperaturePot1\n $TemperaturePot2\n $TemperaturePot3\n $TemperaturePot4\n $HumidityPot1\n $HumidityPot2\n $HumidityPot3\n $HumidityPot4\n $TemperatureWaterPot1\n $TemperatureWaterPot2\n $TemperatureWaterPot3\n $TemperatureWaterPot4\n $pHPot1\n $pHPot2\n $pHPot3\n $pHPot4");
            return 'true';
    }
    else
    {
        echo "ERROR: Hush! Sorry $sql. "
            .mysqli_error($c);
                return 'false';
        }
    }

    $sql = "INSERT INTO `stat` (TemperaturePot1,  TemperaturePot2, TemperaturePot3, TemperaturePot4, HumidityPot1, HumidityPot2, HumidityPot3, HumidityPot4, TemperatureWaterPot1, TemperatureWaterPot2, TemperatureWaterPot3, TemperatureWaterPot4, pHPot1, pHPot2, pHPot3, pHPot4) VALUES (11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26)";
        if(isset($_POST['passed_exam']))
        {
            echo validation_sql($conn, $sql);
        }
        
    while ($row = mysqli_fetch_row($result))
    {
        printf("%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s", $row[0], $row[1], $row[2], $row[3], $row[4], $row[5], $row[6], $row[7], $row[8], $row[9], $row[10], $row[11], $row[12], $row[13], $row[14], $row[15]);
    }

    $TemperaturePot1 = (int) filter_input(INPUT_POST, 'TemperaturePot1', FILTER_SANITIZE_NUMBER_INT);
    $sql="update stat set TemperaturePot1 = " . $TemperaturePot1 . " where id=1;";
        echo validation_sql($conn, $sql);
    
    $TemperaturePot2 = (int) filter_input(INPUT_POST, 'TemperaturePot2', FILTER_SANITIZE_NUMBER_INT);
    $sql="update stat set TemperaturePot2 = " . $TemperaturePot2 . " where id=1;";
        echo validation_sql($conn, $sql);
        
    $TemperaturePot3 = (int) filter_input(INPUT_POST, 'TemperaturePot3', FILTER_SANITIZE_NUMBER_INT);
    $sql="update stat set TemperaturePot3 = " . $TemperaturePot3 . " where id=1;";
        echo validation_sql($conn, $sql);
        
    $TemperaturePot4 = (int) filter_input(INPUT_POST, 'TemperaturePot4', FILTER_SANITIZE_NUMBER_INT);
    $sql="update stat set TemperaturePot4 = " . $TemperaturePot4 . " where id=1;";
        echo validation_sql($conn, $sql);
        
    $HumidityPot1 = (int) filter_input(INPUT_POST, 'HumidityPot1', FILTER_SANITIZE_NUMBER_INT);
    $sql="update stat set HumidityPot1 = " . $HumidityPot1 . " where id=1;";
        echo validation_sql($conn, $sql);
    
    $HumidityPot2 = (int) filter_input(INPUT_POST, 'HumidityPot2', FILTER_SANITIZE_NUMBER_INT);
    $sql="update stat set HumidityPot2 = " . $HumidityPot2 . " where id=1;";
        echo validation_sql($conn, $sql);
        
    $HumidityPot3 = (int) filter_input(INPUT_POST, 'HumidityPot3', FILTER_SANITIZE_NUMBER_INT);
    $sql="update stat set HumidityPot3 = " . $HumidityPot3 . " where id=1;";
        echo validation_sql($conn, $sql);
    
    $HumidityPot4 = (int) filter_input(INPUT_POST, 'HumidityPot4', FILTER_SANITIZE_NUMBER_INT);
    $sql="update stat set HumidityPot4 = " . $HumidityPot4 . " where id=1;";
        echo validation_sql($conn, $sql);
        
    $TemperatureWaterPot1 = (int) filter_input(INPUT_POST, 'TemperatureWaterPot1', FILTER_SANITIZE_NUMBER_INT);
    $sql="update stat set TemperatureWaterPot1 = " . $TemperatureWaterPot1 . " where id=1;";
        echo validation_sql($conn, $sql);
        
    $TemperatureWaterPot2 = (int) filter_input(INPUT_POST, 'TemperatureWaterPot2', FILTER_SANITIZE_NUMBER_INT);
    $sql="update stat set TemperatureWaterPot2 = " . $TemperatureWaterPot2 . " where id=1;";
        echo validation_sql($conn, $sql);
        
    $TemperatureWaterPot3 = (int) filter_input(INPUT_POST, 'TemperatureWaterPot3', FILTER_SANITIZE_NUMBER_INT);
    $sql="update stat set TemperatureWaterPot3 = " . $TemperatureWaterPot3 . " where id=1;";
        echo validation_sql($conn, $sql);
        
    $TemperatureWaterPot4 = (int) filter_input(INPUT_POST, 'TemperatureWaterPot4', FILTER_SANITIZE_NUMBER_INT);
    $sql="update stat set TemperatureWaterPot3 = " . $TemperatureWaterPot3 . " where id=1;";
        echo validation_sql($conn, $sql);
        
    $pHPot1 = (int) filter_input(INPUT_POST, 'pHPot1', FILTER_SANITIZE_NUMBER_INT);
    $sql="update stat set pHPot1 = " . $pHPot1 . " where id=1;";
        echo validation_sql($conn, $sql);
        
    $pHPot2 = (int) filter_input(INPUT_POST, 'pHPot2', FILTER_SANITIZE_NUMBER_INT);
    $sql="update stat set pHPot2 = " . $pHPot2 . " where id=1;";
        echo validation_sql($conn, $sql);
        
    $pHPot3 = (int) filter_input(INPUT_POST, 'pHPot3', FILTER_SANITIZE_NUMBER_INT);
    $sql="update stat set pHPot3 = " . $pHPot3 . " where id=1;";
        echo validation_sql($conn, $sql);
        
    $pHPot4 = (int) filter_input(INPUT_POST, 'pHPot4', FILTER_SANITIZE_NUMBER_INT);
    $sql="update stat set pHPot4 = " . $pHPot4 . " where id=1;";
        echo validation_sql($conn, $sql);

    $sql = <<< 'SQL' SELECT `TemperaturePot1`, `TemperaturePot2`, `TemperaturePot3`, `TemperaturePot4`, `HumidityPot1`, `HumidityPot2`, `HumidityPot3`, `HumidityPot4`, `TemperatureWaterPot1`, `TemperatureWaterPot2`, `TemperatureWaterPot3`, `TemperatureWaterPot4`, `pHPot1`, `pHPot2`, `pHPot3`, `pHPot4` FROM `stat` SQL;
    $sql = <<< 'SQL' UPDATE `stat` SET `TemperaturePot1` = ?, `TemperaturePot2` = ?, `TemperaturePot3` = ?, `TemperaturePot4` = ?, `HumidityPot1` = ? , `HumidityPot2` = ?, `HumidityPot3` = ?, `HumidityPot4` = ?, `TemperatureWaterPot1` = ?, `TemperatureWaterPot2` = ?, `TemperatureWaterPot3` = ?, `TemperatureWaterPot4` = ?, `pHPot1` = ?, `pHPot2` = ?, `pHPot3` = ?, `pHPot4` = ? LIMIT 1; SQL;

    $stmt = mysqli_prepare($conn, $sql);
    mysqli_stmt_bind_param
    (
        $stmt, 'iiiiiiiiiiiiiiii', $TemperaturePot1, $TemperaturePot2, $TemperaturePot3, $TemperaturePot4, $HumidityPot1, $HumidityPot2, $HumidityPot3, $HumidityPot4, $TemperatureWaterPot1, $TemperatureWaterPot2, $TemperatureWaterPot3, $TemperatureWaterPot4, $pHPot1, $pHPot2, $pHPot3, $pHPot4
    );
    mysqli_stmt_execute($stmt);
    
    $res = mysqli_query($conn, $sql);

    while($foo = mysqli_fetch_row($res))
    {
        echo $foo[0];
    }

    $rows = mysqli_fetch_all($result, MYSQLI_NUM);    
?>


Kod
Parse error: syntax error, unexpected '<' in /usr/home/UszaTek/domains/uszatek.ct8.pl/public_html/settings.php on line 106


Linia 106:
Kod
$sql = <<< 'SQL' SELECT `TemperaturePot1`, `TemperaturePot2`, `TemperaturePot3`, `TemperaturePot4`, `HumidityPot1`, `HumidityPot2`, `HumidityPot3`, `HumidityPot4`, `TemperatureWaterPot1`, `TemperatureWaterPot2`, `TemperatureWaterPot3`, `TemperatureWaterPot4`, `pHPot1`, `pHPot2`, `pHPot3`, `pHPot4` FROM `stat` SQL;


Ten post edytował UszaTek 27.12.2021, 09:51:31
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
trueblue
post
Post #2





Grupa: Zarejestrowani
Postów: 6 809
Pomógł: 1828
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


Ostrzeżenie wyraźnie wskazuje gdzie szukać błędu.

1. W jakim celu przypisujesz do zmiennej $sql składnię SELECT, a potem INSERT?
2. W elementach formularza, a dokładnie w atrybucie value nie umieszcza się znaczników HTML.
3. Sprawdź ile zmiennych bindujesz do INSERT.

Takie rzeczy mógłbyś sam wyłapywać gdybyś poświęcił więcej czasu na analizę kodu i czytanie dokumentacji.

Ten post edytował trueblue 29.12.2021, 14:10:24
Go to the top of the page
+Quote Post
UszaTek
post
Post #3





Grupa: Zarejestrowani
Postów: 46
Pomógł: 0
Dołączył: 15.07.2019

Ostrzeżenie: (0%)
-----


Cytat(trueblue @ 29.12.2021, 13:43:09 ) *
Ostrzeżenie wyraźnie wskazuje gdzie szukać błędu.

1. W jakim celu przypisujesz do zmiennej $sql składnię SELECT, a potem INSERT?
2. W elementach formularza, a dokładnie w atrybucie value nie umieszcza się znaczników HTML.
3. Sprawdź ile zmiennych bindujesz do INSERT.

Takie rzeczy mógłbyś sam wyłapywać gdybyś poświęcił więcej czasu na analizę kodu i czytanie dokumentacji.


1. Dopiero zaczynam zabawe w php i zastosowałem tak ponieważ mi doradzali.

2. To w jaki sposób mogę odczytać dane z bazy?

Kod
value=<? echo $rows[1] ?>>
Go to the top of the page
+Quote Post

Posty w temacie
- UszaTek   [php] Parse error: syntax error, unexpected   27.12.2021, 09:50:50
- - Neutral   Składnia heredoc, nowdoc; zobacz przykłady. Może ...   27.12.2021, 18:06:02
- - UszaTek   Kod$sql = <<< 'SQL' SELEC...   28.12.2021, 04:23:51
- - viking   A third way to delimit strings is the heredoc synt...   28.12.2021, 06:14:44
- - Neutral   Tak jak Viking dodał. Po operatorze trzech znaków...   28.12.2021, 15:49:18
|- - UszaTek   Cytat(Neutral @ 28.12.2021, 15:49:18 ...   28.12.2021, 16:10:09
- - Neutral   Włącz w Notepad++ wyświetlanie białych znaków, tab...   28.12.2021, 17:09:59
- - viking   [PHP] pobierz, plaintext $sql = <<<SQL...   28.12.2021, 18:09:11
|- - UszaTek   Cytat(viking @ 28.12.2021, 18:09:11 )...   28.12.2021, 18:47:18
- - Neutral   Musisz włączyć wyświetlanie niewidzialnych znaków....   28.12.2021, 20:12:20
|- - UszaTek   Cytat(Neutral @ 28.12.2021, 20:12:20 ...   28.12.2021, 20:23:56
- - viking   Na zrzucie po raz kolejny widać że uparcie wymyśla...   28.12.2021, 20:31:43
- - Neutral   Prawa strona wydaje się być OK. Wymaż wszystkie t...   28.12.2021, 20:54:53
|- - UszaTek   Cytat(Neutral @ 28.12.2021, 20:54:53 ...   28.12.2021, 21:06:14
- - viking   Nie taka jest składnia heredoc. Uparcie wstawiasz ...   29.12.2021, 09:52:47
- - Neutral   https://www.php.net/manual/en/language.type....syn...   29.12.2021, 10:15:11
- - UszaTek   Teraz mam ostrzezenie; KodWarning: mysqli_fet...   29.12.2021, 12:59:43
- - trueblue   Ostrzeżenie wyraźnie wskazuje gdzie szukać błędu. ...   29.12.2021, 13:43:09
- - UszaTek   Cytat(trueblue @ 29.12.2021, 13:43:09...   29.12.2021, 18:08:48


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 26.12.2025 - 06:12