为什么我不能使用此代码PHP在我的数据库中插入数据,帮助 [英] Why I cant insert data in my db with this code PHP, help
本文介绍了为什么我不能使用此代码PHP在我的数据库中插入数据,帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用wordpress插件,我想要一个填写表单的表单,数据将被插入到数据库中。
PHP代码:
I'm using a wordpress plugin, and I wanted with a form that would fill out the form and the data would be inserted into the database.
PHP code:
<?php
$servername = "localhost" ;
$username = "root" ;
$password = "" ;
$dbname = "pap" ;
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$instrucao = $conn->prepare("INSERT INTO tickets(problema, eletrecidade, agua, assunto, info) VALUES(?,?,?,?,?)");
if($instrucao == FALSE){
echo "<p>ERRO: dados não inseridos!</p>";
}
else{
$instrucao->bind_param("sssss", $_POST["problema"], $_POST["eletrecidade"], $_POST["agua"], $_POST["assunto"], $_POST["info"]);
$resultado = $instrucao->execute();
if($resultado == TRUE){
echo "<p>Dados inseridos.</p>";
}
else{
echo "<p>ERRO: dados não inseridos!</p>";
}
}
$conn->close();
?>
HTML code:
HTML code:
<form name="registodados" method="POST" action="submit.php">
<fieldset>
<!-- Escolher problema geral -->
<label>Problema Geral</label>
<select name="prob" id="prob">
<option disabled selected hidden>Escolha uma opção...</option>
<option value="luz">Luz</option>
<option value="agua">Agua</option>
<option value="elevador">Elevador</option>
</select>
<!-- Escolher problemas eletrecidade -->
<label>Eletrecidade</label>
<select name="eletrecidade" id="eletrecidade">
<option disabled selected hidden>Escolha uma opção...</option>
<option value="curto circuito">Não há luz</option>
<option value="curto circuito">Curto circuito</option>
</select>
<!--Escolher problemas agua -->
<label>Agua</label>
<select name="agua" id="agua">
<option disabled selected hidden>Escolha uma opção...</option>
<option value="Nao ha agua">Não há água</option>
<option value="Inundacao">Inundação</option>
</select>
<label for="assunto">Assunto:</label>
<input type="text" name="assunto" id="assunto" maxlength=100 placeholder="Assunto">
</fieldset>
<fieldset>
<label for="info">Info:</label>
<textarea type="text" name="info" id="info" maxlength=50 placeholder="Descrição detalhada"></textarea>
</fieldset>
<div>
<input type="reset" value="Limpar">
<input type="submit" value="Submeter">
</div>
</form>
表SQL:
Table SQL:
CREATE TABLE `tickets` (
`problema` varchar(30) NOT NULL,
`eletrecidade` varchar(30) NOT NULL,
`agua` varchar(30) NOT NULL,
`assunto` varchar(30) NOT NULL,
`info` varchar(30) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
我已经尝试了几个在互联网上找到的代码摘录,没有任何作用,如果你可以帮助我,那就是一个项目在学校我没有太多时间。
我尝试过:
我尝试了一些我在互联网上找到的代码,但是没有用,wordpress会不会出现问题?
I've tried several excerpts of code found on the internet and nothing works, if you can help me, it's for a project at school I do not have much time.
What I have tried:
I've tried some code what I found on internet, but doesnt work, will wordpress be bugging?
推荐答案
servername = localhost;
servername = "localhost" ;
用户名 = root;
username = "root" ;
密码 = ;
password = "" ;
这篇关于为什么我不能使用此代码PHP在我的数据库中插入数据,帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文