Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/238.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 异常语法错误?_Php_Html_Mysql_Sql_Phpmyadmin - Fatal编程技术网

Php 异常语法错误?

Php 异常语法错误?,php,html,mysql,sql,phpmyadmin,Php,Html,Mysql,Sql,Phpmyadmin,我尝试编辑/更新表格时出错。这很奇怪,因为我可以很好地将新数据插入数据库,然后再删除。我只在编辑/更新数据时遇到问题 致命错误:未捕获异常“PDOException”,消息为“SQLSTATE[42000]:语法错误或访问冲突:1064您的SQL语法有错误;检查与您的MySQL服务器版本对应的手册,以了解在第64行的C:\Program Files(x86)\Ampps\www\Gats\editargat.php中第6行的“WHERE id='1”附近使用的正确语法 代码如下: <?ph

我尝试编辑/更新表格时出错。这很奇怪,因为我可以很好地将新数据插入数据库,然后再删除。我只在编辑/更新数据时遇到问题

致命错误:未捕获异常“PDOException”,消息为“SQLSTATE[42000]:语法错误或访问冲突:1064您的SQL语法有错误;检查与您的MySQL服务器版本对应的手册,以了解在第64行的C:\Program Files(x86)\Ampps\www\Gats\editargat.php中第6行的“WHERE id='1”附近使用的正确语法

代码如下:

<?php

error_reporting( ~E_NOTICE );

require_once 'dbconn.php';

if(isset($_GET['edit_id'])){
    $id = $_GET['edit_id'];
    $editar = $conn->prepare('SELECT nom, sexe, edat, foto FROM TaulaGats WHERE id=:uid');
    $editar->execute(array(':uid'=>$id));
    $edit_row = $editar->fetch(PDO::FETCH_ASSOC);
    extract($edit_row);
}
else{
    header("Location: index.php");
}


if(isset($_POST['btn_save_updates'])){
    $nom = $_POST['nom'];
    $sexe = $_POST['sexe'];
    $edat = $_POST['edat'];

    $foto = $_FILES['imatge']['name'];
    $carpeta_tmp = $_FILES['imatge']['tmp_name'];
    $imatge_mida = $_FILES['imatge']['size'];

    if($foto){
        $carpetaImatges = 'imatges/';   
        $imatge_ext = strtolower(pathinfo($foto, PATHINFO_EXTENSION)); 
        $extensions_vàlides = array('jpeg', 'jpg', 'png', 'gif'); 
        $pic = rand(1000,1000000).".".$imatge_ext;

        if(in_array($imatge_ext, $extensions_vàlides)){         
            if($imatge_mida < 5000000){
                unlink($carpetaImatges.$edit_row['foto']);
                move_uploaded_file($carpeta_tmp, $carpetaImatges.$pic);
            }
            else{
                $error = "La foto és massa gran.";
            }
        }
        else{
            $error = "Només les extensions JPG, JPEG, PNG & GIF són admeses.";      
        }   
    }
    else{
        $pic = $edit_row['foto'];
    }   

    if(!isset($error)){
        $prepIexec = $conn->prepare('UPDATE TaulaGats 
                                         SET nom=:unom, 
                                             sexe=:usexe,
                                             edat=:uedat,
                                             foto=:ufoto, 
                                       WHERE id=:uid');
        $prepIexec->bindParam(':unom', $nom);
        $prepIexec->bindParam(':usexe', $sexe);
        $prepIexec->bindParam(':uedat', $edat);
        $prepIexec->bindParam(':ufoto', $pic);
        $prepIexec->bindParam(':uid', $id);

        if($prepIexec->execute()){
            header("refresh:1;index.php");
        }
        else{
            $error = "No s'ha pogut editar.";
        }
    }
}

?>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Gats</title>

        <link rel="stylesheet" href="bootstrap/css/bootstrap-theme.min.css">
        <link rel="stylesheet" href="estil.css">
        <link rel="stylesheet" href="estil_2.css">

        <script src="bootstrap/js/bootstrap.min.js"></script>
        <script src="jquery-1.11.3-jquery.min.js"></script>
    </head>
    <body>

        <div class="navbar navbar-default navbar-static-top" role="navigation">
            <div class="container">

                <div class="navbar-header">
                    <a class="navbar-brand" href="index.php" title='Gats disponibles'>Disponibles</a>
                    <a class="navbar-brand" href="reservats.php" title='Gats reservats'>Reservats</a>
                    <a class="navbar-brand" href="adoptats.php" title='Gats adoptats'>Adoptats</a>
                    <a class="navbar-brand" href="acollida.php" title="Cases d'acollida">Acollida</a>
                    <a class="navbar-brand" href="voluntaris.php" title="Llista voluntaris">Voluntaris</a>
                </div>

            </div>
        </div>


        <div class="container">


            <div class="page-header">
                <h1 class="h2">Editar<a class="btn btn-default" href="index.php">Veure llista gats</a></h1>
            </div>

            <div class="clearfix"></div>

            <form method="post" enctype="multipart/form-data" class="form-horizontal">

                <?php
                if(isset($error)){
                ?>
                <div class="alert alert-danger">
                    <?php echo $error; ?>
                </div>
                <?php
                }
                ?>

                <table class="table table-bordered table-responsive">

                    <tr>
                        <td><label class="control-label">Nom</label></td>
                        <td><input class="form-control" type="text" name="nom" value="<?php echo $nom; ?>" /></td>
                    </tr>

                    <tr>
                        <td><label class="control-label">Sexe</label></td>
                        <td><input class="form-control" type="text" name="sexe" value="<?php echo $sexe; ?>" /></td>
                    </tr>

                    <tr>
                        <td><label class="control-label">Edat</label></td>
                        <td><input class="form-control" type="text" name="edat" value="<?php echo $edat; ?>" /></td>
                    </tr>

                    <tr>
                        <td><label class="control-label">Foto</label></td>
                        <td>
                            <p><img src="imatges/<?php echo $foto; ?>" height="150" width="200" /></p>
                            <input class="input-group-edit" type="file" name="imatge" accept="image/*" />
                        </td>
                    </tr>

                    <tr>
                        <td colspan="2"><button type="submit" name="btn_save_updates" class="btn btn-default btn-guardar">
                            Guardar
                            </button>
                        </td>
                    </tr>
                </table>

            </form>
        </div>
    </body>
</html>

服贸总协定
编辑
笔名

您的
:uid
等于
1'
。请删除冒号
foto=:ufoto,其中id=:uid')UPDATE
query中执行此操作之后,我认为您看到了一个问题,应该是
foto=:ufoto其中id=:uid')@Mario WOW man就是这样!!怎么会这么简单哈哈谢谢!不是冒号,是逗号。这里有两种不同的动物哦,我的错误@Fred ii-:)
<?php

require_once 'dbconn.php';

if(isset($_GET['eliminar_id']))
{
    $prepIexec = $conn->prepare('SELECT foto FROM TaulaGats WHERE id =:uid');
    $prepIexec->execute(array(':uid'=>$_GET['eliminar_id']));
    $imatgeRow = $prepIexec->fetch(PDO::FETCH_ASSOC);
    unlink("imatges/".$imatgeRow['foto']);

    $eliminar = $conn->prepare('DELETE FROM TaulaGats WHERE id =:uid');
    $eliminar->bindParam(':uid', $_GET['eliminar_id']);
    $eliminar->execute();

    header("Location: index.php");
}

?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">

    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" />
        <title>Gats</title>

        <link rel="stylesheet" href="estil_index.css">
        <link rel="stylesheet" href="estil.css">
        <link rel="stylesheet" href="bootstrap/css/bootstrap-theme.min.css">
    </head>

    <body>

        <div class="navbar navbar-default navbar-static-top" role="navigation">
            <div class="container">

                <div class="navbar-header">
                    <a class="navbar-brand" href="index.php" title='Gats disponibles'>Disponibles</a>
                    <a class="navbar-brand" href="reservats.php" title='Gats reservats'>Reservats</a>
                    <a class="navbar-brand" href="adoptats.php" title='Gats adoptats'>Adoptats</a>
                    <a class="navbar-brand" href="acollida.php" title="Cases d'acollida">Acollida</a>
                    <a class="navbar-brand" href="voluntaris.php" title="Llista voluntaris">Voluntaris</a>
                </div>

            </div>
        </div>

        <div class="container">

            <div class="page-header">
                <h1>Gats en adopció
                    <a class="btn btn-default" href="afegirgat.php">&nbsp;+ Afegir nou gat </a>
                </h1>
            </div>

            <br />

            <div class="row">
                <?php

                $prepIexec = $conn->prepare('SELECT id, nom, sexe, edat, foto FROM TaulaGats ORDER BY id ASC');
                $prepIexec->execute();

                if($prepIexec->rowCount() > 0)
                {
                    while($row = $prepIexec->fetch(PDO::FETCH_ASSOC))
                    {
                        extract($row);
                ?>
                <div class="col-xs-3">
                    <p class="page-header infoGats_nom"><?php echo $nom ?></p>
                    <p class="infoGats">
                        <?php echo $sexe."&nbsp;/&nbsp;".$edat; ?>
                    </p>
                    <img src="imatges/<?php echo $row['foto']; ?>" class="img-rounded" width="250px" height="200px" />
                    <p class="page-header">
                        <span>
                            <a class="btn btn-info" href="editargat.php?edit_id=<?php echo $row['id']; ?>" title="click per editar"><span class="glyphicon glyphicon-edit"></span> Editar </a>
                            <a class="btn btn-success" href="mouregat.php?moure_id=<?php echo $row['id']; ?>" title="click per moure"><span class="glyphicon glyphicon-edit"></span> Moure </a>
                            <a class="btn btn-danger" href="?eliminar_id=<?php echo $row['id']; ?>" title="click per eliminar" onclick="return confirm('Estàs segur que vols el·liminar aquestes dades?')"><span class="glyphicon glyphicon-remove-circle"></span> El·liminar </a>
                        </span>
                    </p>
                </div>
                <?php
                    }
                }
                else
                {
                ?>
                <div class="col-xs-12">
                    <div class="alert alert-warning">
                        No hi ha gats per adoptar.
                    </div>
                </div>
                <?php
                }

                ?>
            </div>
        </div>

        <script src="bootstrap/js/bootstrap.min.js"></script>

    </body>

</html>