gpt4 book ai didi

php - 在第 59 行 C : syntax error, php 中解析错误 :\xampp\htdocs\tempahperalatan\Page2. 意外 T_IF

转载 作者:行者123 更新时间:2023-11-29 18:22:42 27 4
gpt4 key购买 nike

您好,我是一名学习 php 和 sql 的学生,我正在尝试从带有数量的复选框插入数据,但我不确定我的编码,有人可以帮助我吗?第 59 行有错误。

这是我的 php 编码:

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

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}

if(isset($_POST['submit']))
{

$catatan = $_POST['catatan'];

$microphones=$row[microphones];

if ($laptop=='1')
{ $vlaptop="ON";}
else
{ $vlaptop="OFF";}

$amplifiers=$row[amplifiers];
if ($amplifiers=='1')
{
$vamplifiers="ON";
}
else
{
$vamplifiers="OFF";
}

$loudspeakers=$row[loudspeakers];
if ($loudspeakers=='1')
{
$vloudspeakers="ON";
}
else
{
$vloudspeakers="OFF";
}

$mixers=$row[mixers];
if ($mixers=='1')
{
$vmixers="ON";
}
else
{
$vmixers="OFF";
}

$sql= "INSER INTO pasystems (catatan) INTO '$catatan'"


if (mysqli_query($conn, $sql)) { //this is line 59
echo "<script type='text/javascript'>alert('submitted successfully!')</script>";
} else {
echo "<script type='text/javascript'>alert('failed!')</script>" . $sql . "<br>" . mysqli_error($conn);
}


}


mysqli_close($conn);
?>

这是我的表格:

<form action="page2.php" method="POST">


<div class="form-group row text-left">
<label for="example-date-input" class="col-2 col-form-label">Nama Peralatan: </label>
<div class="col-10">

<div class="form-group">
<div class="form-row">
<div class="col-md-2">
<div class="form-check text-left">
<label class="form-check-label">
<input class="form-check-input" name="Microphones" type="checkbox"
<? if ($row[microphones]==1)
{ ?> checked="checked" <? }
?> >
Microphones
</label>
</div>
</div>
<div class="">
<input class="form-control" type="number" value="1" id="example-number-input">
</div>
</div>
</div>

<div class="form-group">
<div class="form-row">
<div class="col-md-2">
<div class="form-check text-left">
<label class="form-check-label">
<input class="form-check-input" name="Amplifiers" type="checkbox"
<? if ($row[lamplifiers]==1)
{ ?> checked="checked" <? }
?> >
Amplifiers
</label>
</div>
</div>
<div class="">
<input class="form-control" type="number" value="1" id="example-number-input">
</div>
</div>
</div>

<div class="form-group">
<div class="form-row">
<div class="col-md-2">
<div class="form-check text-left">
<label class="form-check-label">
<input class="form-check-input" name="Loudspeakers" type="checkbox"
<? if ($row[loudspeakers]==1)
{ ?> checked="checked" <? }
?> >
Loudspeakers
</label>
</div>
</div>
<div class="">
<input class="form-control" type="number" value="1" id="example-number-input">
</div>
</div>
</div>

<div class="form-group">
<div class="form-row">
<div class="col-md-2">
<div class="form-check text-left">
<label class="form-check-label">
<input class="form-check-input" name="Mixers]" type="checkbox"
<? if ($row[mixers]==1)
{ ?> checked="checked" <? }
?> >
Mixers
</label>
</div>
</div>
<div class="">
<input class="form-control" type="number" value="1" id="example-number-input">
</div>
</div>
</div>

</div>
</div>

<div class="form-group row text-left">
<label for="exampleTextarea" class="col-2 col-form-label">Catatan: </label>
<div class="col-10">
<textarea class="form-control" name="catatan" id="exampleTextarea" rows="3"></textarea>
</div>
</div>
<center><button type="submit" name="submit" class="btn btn-info">Submit</button></center>

</form>

我不确定我的编码有什么问题。预先感谢您,非常需要您的帮助。

最佳答案

这里的错误是您的插入语法错误。您缺少 VALUES 关键字,并且拼错了 INSERT 且缺少分号下面的内容应该修复它。

$sql= "INSERT INTO pasystems (catatan) VALUES('$catatan')";

而且上面的代码也不安全。您需要开始使用准备好的语句,因为您正在使用支持它的 api

关于php - 在第 59 行 C : syntax error, php 中解析错误 :\xampp\htdocs\tempahperalatan\Page2. 意外 T_IF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46438594/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com