我在尝试插入tin mysqli时得到了这个#1064

a64a0gku  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(225)

我尝试将数据输入数据库时出错详细信息:
insert.php,代码为:

<div align ="center" dir="rtl">
  <form dir="rtl"  method="GET" action="update.php">
    <div dir="rtl"class="row">
      <div>
        <label for="fname">  מספר מגמה &nbsp &nbsp &nbsp </label>

        <input type="text" id="fname" readonly name="magma_no" value="<?=($row0['magma_no'] +1)?>">
      </div>
    </div>
	<br>
	    <div dir="rtl"class="row">
      <div>
        <label for="fname">  שם מגמה &nbsp &nbsp &nbsp </label>

        <input type="text" id="fname" name="mgma_name" placeholder="מספר כאן">
      </div>
    </div>
	<br>

	    <div dir="rtl"class="row">
      <div>
        <label for="fname">  הסבר על מגמה  &nbsp &nbsp </label>

        <input type="text" id="fname" name="mgma_details" placeholder="מספר כאן">
      </div>
    </div>
	<br>
	<div  id="buttons" class="row">
      <input style="font-family:David" type="submit" class="btn blue"  value="הוספה למאגר" name="insert">
	      </div>
  </form>
</div>

和update.php

<?php
include "../include/config.php";
if(isset($_GET['insert'])){
    $query      ="SELECT count(*) as 'counter' FROM magma where         
magma_no='".$_GET['magma_no']."'";
$res  = mysqli_query($con,$query);
$rowing     = $res->fetch_array(MYSQLI_BOTH);
if( $rowing['counter'] == 0)
{
$insert="insert into magma (magma_no,mgma_name,mgma_details) VALUES ('".$_GET['magma_no']."','".$_GET['mgma_name']."','".$_GET['mgma_details']."')";
$query=mysqli_query($con,$insert);
if($query==1)
{
    ?>
           <script>alert('הוספה בהצלחה')</script>     
            <meta content="0;../magma.php?succeed" http-equiv="refresh">

    <?php

}else {
    ?>
                <script>alert('ERROR CODE="<?=mysqli_errno($con)?>"') 
</script>
<?php 
echo "<h1 align='center'>".mysqli_error($con)."</h1>";
?>

            <meta content="5;../magma.php?error" http-equiv="refresh">

    <?php

}
}else
{
?>
<script>alert('ERROR CODE=403')</script>
                                    <script>alert('ERROR MODE= מספר משתמש כבר קיים במערכת')</script>

            <meta content="0;insert.php?error" http-equiv="refresh">

<?php
}

}
?>

当我点击提交时,我得到了这个错误
sql语法有错误;请检查与您的mariadb服务器版本对应的手册,以了解在第1行“1”)附近使用的正确语法
有人能帮我把这个错误传过去吗?我试过很多方法
更新1

var_dump($_GET['magma_no'],$_GET['mgma_name'],$_GET['mgma_details']);

字符串(3)“103”字符串(23)”הנדסת חשמל ב'" 字符串(1)“1”

kxxlusnw

kxxlusnw1#

$_GET['mgma_name'] 已经有一个报价了 ' ,您试图在单引号中使用单引号。你得把衣服包起来 $_GET 双引号中的变量如下:

$insert='INSERT INTO magma 
(magma_no,mgma_name,mgma_details) 
VALUES 
("'. $_GET['magma_no'] . '","' . $_GET['mgma_name'] . '","' . $_GET['mgma_details'] . '")';

编辑:
正如马格纳斯所建议的,你绝对应该使用事先准备好的语句。下面是一篇精彩的文章,介绍了mysql的基本用法,包括预处理语句。

相关问题