соответствует версии вашего сервера MariaDB для правильного синтаксиса, используемого рядом с ‘3g, зарядка = 999, диагностика = 299, экран = 2190, вода = 299, камера’ в строке 1

#php #html #mysql

#php #HTML #mysql

Вопрос:

Я получаю следующую ошибку:

 corresponds to your MariaDB server version for the right syntax to use near '3g,charging=999,diagnostic=299 ,screen=2190 ,water=299 ,camera' at line 1
  

я проверил все возможные проблемы, которые могут вызвать эту проблему, но ни одна из них не работает для меня.

Код является html-кодом, который

     <?php
    $servername = "localhost";
    $username = "root";
    $password = "";
    $dbname = "apple";

    // Create connection
    $conn = new mysqli($servername, $username, $password, $dbname);
    // Check connection
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    } 
    $sku = $_GET['sku'];
    $model = $_GET['model'];
    $charging = $_GET['charging'];
    $diagnostic = $_GET['diagnostic'];
    $screen = $_GET['screen'];
    $water = $_GET['water'];
    $camera = $_GET['camera'];
    $earspeaker = $_GET['earspeaker'];
    $frame = $_GET['frame'];
    $headphone = $_GET['headphone'];
    $homebtn = $_GET['homebtn'];
    $mic = $_GET['mic'];
    $network = $_GET['network'];
    $other = $_GET['other'];
    $sensor = $_GET['sensor'];
    $software = $_GET['software'];
    $speaker = $_GET['speaker'];
    $volumebtn = $_GET['volumebtn'];
    $filesdestination = $_GET['filesdestination'];
    //echo $_GET['model'];
    //$sql = "UPDATE table_3 SET lastname='Doe' WHERE id=2";
    /*
    if ($conn->query($sql) === TRUE) {
        echo "Record updated successfully";
    } else {
        echo "Error updating record: " . $conn->error;
    }

    $conn->close();*/
    ?>
    <!DOCTYPE html>
    <html>

    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>Page Title</title>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" type="text/css" media="screen" href="main.css">
        <script src="main.js"></script>
        <style>
            table,
            th,
            td {
                /*border: 1px solid black;*/
                border-collapse: collapse;
                text-align: center;

            }

            th,
            td {
                padding: 5px;
            }

            th {
                text-align: center;
            }
        </style>
    </head>

    <body>
        <center>
            <form action="updatedata.php" method="post" enctype="multipart/form-data">
                <table>

                <tr>
                                <td>
                                    <p for="sku">sku</p>
                                </td>
                                <td> <input type="text" id="sku" placeholder="sku" value="<?php echo $sku ?>" name="sku" required /></td>
                            </tr>
                        <tr>
                                <td>
                                    <p for="the model">The model</p>
                                </td>
                                <td> <input type="text" id="model" value="<?php echo $model ?>" placeholder="phone model" name="model" required /></td>
                            </tr>
                    <tr>
                        <td>
                            <p for="charging">charging</p>
                        </td>
                        <td><input type="text" id="charging" value="<?php echo $charging ?>" placeholder="charging problem repair" name="charging"
                                required /></td>
                    </tr>

                    <tr>
                        <td>
                            <p for="diagnostic">Diagnostic</p>
                        </td>
                        <td> <input type="text" id="diagnostic" value="<?php echo $diagnostic ?>" placeholder="diagnostic" name="diagnostic" required /></td>
                    </tr>

                    <tr>
                        <td>
                            <p for="scren">Screen</p>
                        </td>
                        <td><input type="text" id="screen" value="<?php echo $screen ?>" placeholder="glass touch screen" name="screen" required /></td>
                    </tr>

                    <tr>
                        <td>
                            <p for="water">Water</p>
                        </td>
                        <td> <input type="text" id="water" value="<?php echo $water ?>" placeholder="water damage repair" name="water" required /></td>
                    </tr>

                    <tr>

                        <td>
                            <p for="water">Camera</p>
                        </td>
                        <td> <input type="text" id="camera" value="<?php echo $camera ?>" placeholder="camera repair" name="camera" required /></td>
                    </tr>

                    <tr>
                        <td>
                            <p for="earspeaker">ear speaker</p>
                        </td>
                        <td> <input type="text" id="earspeaker" value="<?php echo $earspeaker ?>" placeholder="ear speaker repair" name="earspeaker"
                                required /></td>
                    </tr>

                    <tr>
                        <td>
                            <p for="frame">Outer cover frame</p>
                        </td>
                        <td> <input type="text" id="frame" value="<?php echo $frame ?>" placeholder="frame and housing replacement" name="frame"
                                required /></td>
                    </tr>

                    <tr>
                        <td>
                            <p for="headphone">headphone jack</p>
                        </td>
                        <td> <input type="text" id="headphone" value="<?php echo $headphone ?>" placeholder="headphone jack repair" name="headphone"
                                required /></td>
                    </tr>

                    <tr>
                        <td>
                            <p for="homebtn">home button</p>
                        </td>
                        <td> <input type="text" id="homebtn" value="<?php echo $homebtn ?>" placeholder="home button repair" name="homebtn" required />
                        </td>
                    </tr>

                    <tr>
                        <td>
                            <p for="mic">Microphone</p>
                        </td>
                        <td> <input type="text" id="mic" value="<?php echo $mic ?>" placeholder="mic repair" name="mic" required /></td>
                    </tr>

                    <tr>
                        <td>
                            <p for="network">Network problem</p>
                        </td>
                        <td> <input type="text" id="network" value="<?php echo $network ?>" placeholder="network repair" name="network" required /></td>
                    </tr>

                    <tr>
                        <td>
                            <p for="other">other problems</p>
                        </td>
                        <td> <input type="text" id="other" value="<?php echo $other ?>" placeholder="other repair" name="other" required /></td>
                    </tr>

                    <tr>
                        <td>
                            <p for="sensor">sensors</p>
                        </td>
                        <td> <input type="text" id="sensor" value="<?php echo $sensor ?>" placeholder="sensor repair" name="sensor" required /></td>
                    </tr>

                    <tr>
                        <td>
                            <p for="software">Software flash</p>
                        </td>
                        <td> <input type="text" placeholder="software flash" value="<?php echo $software ?>" name="software" required /></td>
                    </tr>

                    <tr>
                        <td>
                            <p for="speaker">speaker</p>
                        </td>
                        <td> <input type="text" id="speaker" value="<?php echo $speaker ?>" placeholder="rear speaker repair" name="speaker" required />
                        </td>
                    </tr>

                    <tr>
                        <td>
                            <p for="volumebtn">volume button</p>
                        </td>
                        <td> <input type="text" id="volumebtn" value="<?php echo $volumebtn ?>" placeholder="volume button repair" name="volumebtn"
                                required /></td>
                    </tr>
    <style>
        .responsive {
            max-width: 100%;
      width: 10%;
      max-height: 100%;
      height: 5%;

    }
        </style>

                    <tr>
                    <?php 
                        echo '


                        <img src="'.$filesdestination.'" alt="Nature" class="responsive">




                        '; 
                        ?>
                        <td>
                            <p for="pic">Select the pic</p>
                        </td>

                        <td> <input type="file" id="pic" placeholder="phone model" value="update" name="pic" /></td>
                    </tr>

                    <tr>
                        <td></td>
                        <td><button type="submit" name="submit">upload</button></td>
                    </tr>
                </table>
            </form>
            <h4><a href="seedata.php">See what you add the data</a></h4>
        </center>
    </body>

    </html>
  

php-код является

     <?php

    $servername = "localhost";
    $username = "root";
    $password = "";
    $dbname = "apple";

    // Create connection
    $conn = new mysqli($servername, $username, $password, $dbname);
    // Check connection
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    } 
    if(isset($_POST['submit'])){
        $sku = $_POST['sku'];
        $charging = $_POST['charging'];
        $diagnostic = $_POST['diagnostic'];
        $screen = $_POST['screen'];
        $water = $_POST['water'];
        $camera = $_POST['camera'];
        $earspeaker = $_POST['earspeaker'];
        $frame = $_POST['frame'];
        $headphone = $_POST['headphone'];
        $homebtn = $_POST['homebtn'];
        $mic = $_POST['mic'];
        $network = $_POST['network'];
        $other = $_POST['other'];
        $sensor = $_POST['sensor'];
        $software = $_POST['software'];
        $speaker = $_POST['speaker'];
        $volumebtn = $_POST['volumebtn'];
        $model = $_POST['model'];
        $file = $_FILES['pic'];
        //print_r($file);
        $fileName = $_FILES['pic']['name'];
        $fileTmpName = $_FILES['pic']['tmp_name'];
        $fileSize = $_FILES['pic']['size'];
        $fileError = $_FILES['pic']['error'];
        $fileType = $_FILES['pic']['type'];

        $fileExt = explode('.', $fileName);
        $fileActualExt = strtolower(end($fileExt));

        $allowed = array('jpg', 'jpeg', 'png', 'pdf', 'svg');


        if(in_array($fileActualExt, $allowed)){
            if($fileError === 0){
                if($fileSize < 1000000){
                    $fileNameNew = uniqid('', true).".".$fileActualExt;
                    $fileDestination = 'uploads/'.$fileNameNew;
                    move_uploaded_file($fileTmpName, $fileDestination);
                    //header("Location: appindex.php?uploadsuccess");
                }else 
                echo "Your file is tooooooo big";
            }else {
                echo "There was an error to upload the file";
            }
        }else
        {
            echo "you cannot upload this file type";
        }
    }$sql = "UPDATE table_3 SET sku=$sku,model=$model,charging=$charging,diagnostic=$diagnostic,screen=$screen,
     water=$water,camera=$camera,earspeaker=$earspeaker,frame=$frame,headphone=$headphone,homebtn=$homebtn,
     mic=$mic,network=$network,other=$other,sensor=$sensor,software=$software,speaker=$speaker,volumebtn=$volumebtn,
     filesdestination=$fileDestination WHERE model=$model";
    if ($conn->query($sql) === TRUE) {

        header("Location: index.html?uploadsuccess");

    } else {
        echo "Error: " . $sql . "<br>" . $conn->error;
    }

    $conn->close();
    ?>
  

Ошибка, которую я получаю, является:

 Error: UPDATE table_3 SET sku=iph3,model=Iphone 3g,charging=999,diagnostic=299 ,screen=2190 ,water=299 ,camera=1499 ,earspeaker=1099 ,frame=1799 ,headphone=1200 ,homebtn=999 ,mic=1400 ,network=1600 ,other=1500 ,sensor=999 ,software=999 ,speaker=1400 ,volumebtn=999 ,filesdestination=uploads/5c80a5be538550.58960698.png WHERE model=Iphone 3g
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '3g,charging=999,diagnostic=299 ,screen=2190 ,water=299 ,camera' at line 1
  

Ответ №1:

Попробуйте это и выведите запрос:

 $sql = "UPDATE table_3 SET sku='$sku',model='$model',charging='$charging',diagnostic='$diagnostic',screen='$screen',
 water='$water',camera='$camera',earspeaker='$earspeaker',frame='$frame',headphone='$headphone',homebtn='$homebtn',
 mic='$mic',network='$network',other='$other',sensor='$sensor',software='$software',speaker='$speaker',volumebtn='$volumebtn',
 filesdestination='$fileDestination' WHERE model='$model'";
  

У вас отсутствуют одинарные кавычки для всех значений