Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [php] Parse error: syntax error, unexpected
UszaTek
post 27.12.2021, 09:50:50
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
Neutral
post 27.12.2021, 18:06:02
Post #2





Grupa: Zarejestrowani
Postów: 286
Pomógł: 46
Dołączył: 10.01.2016

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


Składnia heredoc, nowdoc; zobacz przykłady.

Może spację wywal i od nowej linii pisz.
  1. $a=<<<"sqlcde"
  2. Mystr.
  3. >>>;


Ten post edytował Neutral 27.12.2021, 18:07:48
Go to the top of the page
+Quote Post
UszaTek
post 28.12.2021, 04:23:51
Post #3





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

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


Kod
$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;
    >>>;

Tak też nie działa

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


Ten post edytował UszaTek 28.12.2021, 04:24:54
Go to the top of the page
+Quote Post
viking
post 28.12.2021, 06:14:44
Post #4





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
Dołączył: 30.08.2006

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


A third way to delimit strings is the heredoc syntax: <<<. After this operator, an identifier is provided, then a newline


--------------------
Go to the top of the page
+Quote Post
Neutral
post 28.12.2021, 15:49:18
Post #5





Grupa: Zarejestrowani
Postów: 286
Pomógł: 46
Dołączył: 10.01.2016

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


Tak jak Viking dodał.

Po operatorze trzech znaków mniejszości musi być nowa linia.

@nospor jest świetny w grze, znajdź sto różnic. Nie ma sobie równych, można się od niego uczyć, naprawdę.
Kod
$a=<<<"CC" x
z
>>>;

while(ALL_STUFF) {
  if(Line.#1 not found #Newline) {
    Error();
    output="... unexpected '<<'...";
  }
}
Go to the top of the page
+Quote Post
UszaTek
post 28.12.2021, 16:10:09
Post #6





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

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


Cytat(Neutral @ 28.12.2021, 15:49:18 ) *
Tak jak Viking dodał.

Po operatorze trzech znaków mniejszości musi być nowa linia.

@nospor jest świetny w grze, znajdź sto różnic. Nie ma sobie równych, można się od niego uczyć, naprawdę.
Kod
$a=<<<"CC" x
z
>>>;

while(ALL_STUFF) {
  if(Line.#1 not found #Newline) {
    Error();
    output="... unexpected '<<'...";
  }
}


Mój kod:

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


I jest bez zmian
Go to the top of the page
+Quote Post
Neutral
post 28.12.2021, 17:09:59
Post #7





Grupa: Zarejestrowani
Postów: 286
Pomógł: 46
Dołączył: 10.01.2016

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


Włącz w Notepad++ wyświetlanie białych znaków, tabulacje, spacje, inne.

Usuń wcięcia przed i po.

Dobrze:
  1. $sql=<<<
  2. Bbjhhj
  3. Jj
  4. >>>;


Źle:
  1. $sql=<<<|spacja|
  2. Bbjhhj
  3. Jj
  4. >>>;


Ten post edytował Neutral 28.12.2021, 17:10:31
Go to the top of the page
+Quote Post
viking
post 28.12.2021, 18:09:11
Post #8





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
Dołączył: 30.08.2006

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


  1. $sql = <<<SQL
  2.   SELECT
  3.   `TemperaturePot1`,
  4.   `TemperaturePot2`,
  5.   `TemperaturePot3`,
  6.   `TemperaturePot4`,
  7.   `HumidityPot1`,
  8.   `HumidityPot2`,
  9.   `HumidityPot3`,
  10.   `HumidityPot4`,
  11.   `TemperatureWaterPot1`,
  12.   `TemperatureWaterPot2`,
  13.   `TemperatureWaterPot3`,
  14.   `TemperatureWaterPot4`,
  15.   `pHPot1`,
  16.   `pHPot2`,
  17.   `pHPot3`,
  18.   `pHPot4`
  19.   FROM `stat`
  20. SQL;


Na przyszłość zajrzyj do dokumentacji a nie zgadujesz.


--------------------
Go to the top of the page
+Quote Post
UszaTek
post 28.12.2021, 18:47:18
Post #9





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

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


Cytat(viking @ 28.12.2021, 18:09:11 ) *
  1. $sql = <<<SQL
  2.   SELECT
  3.   `TemperaturePot1`,
  4.   `TemperaturePot2`,
  5.   `TemperaturePot3`,
  6.   `TemperaturePot4`,
  7.   `HumidityPot1`,
  8.   `HumidityPot2`,
  9.   `HumidityPot3`,
  10.   `HumidityPot4`,
  11.   `TemperatureWaterPot1`,
  12.   `TemperatureWaterPot2`,
  13.   `TemperatureWaterPot3`,
  14.   `TemperatureWaterPot4`,
  15.   `pHPot1`,
  16.   `pHPot2`,
  17.   `pHPot3`,
  18.   `pHPot4`
  19.   FROM `stat`
  20. SQL;


Na przyszłość zajrzyj do dokumentacji a nie zgadujesz.


Teraz takie coś pokazuje:

Kod
Parse error: Invalid indentation - tabs and spaces cannot be mixed in /usr/home/UszaTek/domains/uszatek.ct8.pl/public_html/settings.php on line 107


linia 107:

Kod
SELECT


Ten post edytował UszaTek 28.12.2021, 18:52:49
Go to the top of the page
+Quote Post
Neutral
post 28.12.2021, 20:12:20
Post #10





Grupa: Zarejestrowani
Postów: 286
Pomógł: 46
Dołączył: 10.01.2016

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


Musisz włączyć wyświetlanie niewidzialnych znaków.

Notepad++

¶¶¶sunrise, sunrise
[TAB]sunset, sunset

Musisz

¶¶¶sunrise, sunrise
¶¶¶sunset, sunset
Go to the top of the page
+Quote Post
UszaTek
post 28.12.2021, 20:23:56
Post #11





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

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


Cytat(Neutral @ 28.12.2021, 20:12:20 ) *
Musisz włączyć wyświetlanie niewidzialnych znaków.

Notepad++

¶¶¶sunrise, sunrise
[TAB]sunset, sunset

Musisz

¶¶¶sunrise, sunrise
¶¶¶sunset, sunset


Tak mi teraz pokazuje w notepad:

Go to the top of the page
+Quote Post
viking
post 28.12.2021, 20:31:43
Post #12





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
Dołączył: 30.08.2006

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


Na zrzucie po raz kolejny widać że uparcie wymyślasz własną składnię i ją forsujesz.


--------------------
Go to the top of the page
+Quote Post
Neutral
post 28.12.2021, 20:54:53
Post #13





Grupa: Zarejestrowani
Postów: 286
Pomógł: 46
Dołączył: 10.01.2016

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


Prawa strona wydaje się być OK.

Wymaż wszystkie tabulacje, pomarańczowe strzałki.
I dwukrotnie walnij dwie spacyjki wszędzie.

Przemęczysz to, przemyślisz.biggrin.gif
Go to the top of the page
+Quote Post
UszaTek
post 28.12.2021, 21:06:14
Post #14





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

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


Cytat(Neutral @ 28.12.2021, 20:54:53 ) *
Prawa strona wydaje się być OK.

Wymaż wszystkie tabulacje, pomarańczowe strzałki.
I dwukrotnie walnij dwie spacyjki wszędzie.

Przemęczysz to, przemyślisz.biggrin.gif


Kod
Parse error: syntax error, unexpected '>>' (T_SR),




Robiłem bez spacji, z jedną spacja , dwie spacje i błąd ten sam.

Kod
Parse error: Invalid body indentation level (expecting an indentation level of at least 2) in /usr/home/UszaTek/domains/uszatek.ct8.pl/public_html/settings.php on line 107




Ten post edytował UszaTek 28.12.2021, 21:12:33
Go to the top of the page
+Quote Post
viking
post 29.12.2021, 09:52:47
Post #15





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
Dołączył: 30.08.2006

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


Nie taka jest składnia heredoc. Uparcie wstawiasz wymyśloną przez siebie składnię i dziwisz się potem że nie działa. Dałem ci już przykład jak to wygląda poprawnie.


--------------------
Go to the top of the page
+Quote Post
Neutral
post 29.12.2021, 10:15:11
Post #16





Grupa: Zarejestrowani
Postów: 286
Pomógł: 46
Dołączył: 10.01.2016

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


https://www.php.net/manual/en/language.type....syntax.heredoc

Przeczytaj.

Wyrzuć ">>>;", zamykasz przez tag.
Go to the top of the page
+Quote Post
UszaTek
post 29.12.2021, 12:59:43
Post #17





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

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


Teraz mam ostrzezenie;

Kod
Warning: mysqli_fetch_row() expects parameter 1 to be mysqli_result, bool given in /usr/home/UszaTek/domains/uszatek.ct8.pl/public_html/settings.php on line 157


Linia 157;

Kod
while($foo = mysqli_fetch_row($res))


Oraz nie wyświetla liczb z bazy.



Kod
<form action="settings.php" method="post">
                    <label for="s1">Temperature: </label>
                        <div class="ui-spinner">
                            <input type="text" id="s1" name="TemperaturePot1" class="ui-spinner-box" autocomplete="off" value=<? echo '<p>'.$rows[1].'</p>'; ?>>
                            <button class="ui-spinner-up" type="button">▲</button>
                            <button class="ui-spinner-down" type="button">▼</button>
                        </div>
                </form>
Go to the top of the page
+Quote Post
trueblue
post 29.12.2021, 13:43:09
Post #18





Grupa: Zarejestrowani
Postów: 6 761
Pomógł: 1822
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 29.12.2021, 18:08:48
Post #19





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

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

 



RSS Wersja Lo-Fi Aktualny czas: 28.04.2024 - 03:17