问题描述
出于某种原因,我的代码没有更新mySQL数据库,但它不报告任何错误。
register.php (表单)
pre $ < form class =register_formaction =action.php?do = registermethod =post >
团队名称*:< input type =textname =teamnamerequired />
Team Region *:< input type =textname =teamregionmaxlength =4required />
Team Leader *:< input type =textname =teamleadermaxlength =16required />
团队成员:< input type =textname =teammembers/>
< input name =register_submittype =submitvalue =Register/>
< / form>
action.php
<?php
$ con = mysqli_connect(192.185。#。###,######## _ reg,# ######, #########);
if(mysqli_connect_errno()){echo无法连接到MySQL:。 mysqli_connect_error();}
$ action = $ _GET ['do'];
if($ action ==register){
$ teamname = $ _POST [teamname];
$ teamregion = $ _POST [teamregion];
$ teamleader = $ _POST [teamleader];
$ teammembers = $ _POST [teammembers];
$ result = mysqli_query($ con,INSERT INTO teams(teamname,region,teamleader,teammembers,wins,loses)
VALUES(。$ teamname。,。$ teamregion。, 。$ teamleader。,。$ teammembers。,0,0););
}
?>
任何想法为何无法正常工作?
下面是一个准备好的语句的工作示例,它们通常用来代替 query
$ b
action.php
$ con = new mysqli ('localhost','root','','dachi');如果(mysqli_connect_errno()){
printf(连接失败:%s \ n,mysqli_connect_error());
exit();
}
if(isset($ _ GET ['do'])&&& $ _GET ['do'] ===register){
$ teamname = $ _POST [teamname];
$ teamregion = $ _POST [teamregion];
$ teamleader = $ _POST [teamleader];
$ teammembers = $ _POST [teammembers];
$ wins = 0;
$失去= 0;
$ stmt = $ con> prepare(INSERT INTO`teams`(`teamname`,`region`,`teamleader`,`teammembers`,`wins`,`loses`)VALUES )(,,,,,??????);
$ stmt-> bind_param('ssssii',$ teamname,$ teamregion,$ teamleader,$ teammembers,$ wins,$ loses);
$ stmt-> execute();
$ stmt-> close();
}
register.php
< form class =register_formaction =action.php?do = registermethod =post>
团队名称*:< input type =textname =teamnamerequired />
Team Region *:< input type =textname =teamregionmaxlength =4required />
Team Leader *:< input type =textname =teamleadermaxlength =16required />
团队成员:< input type =textname =teammembers/>
< input name =register_submittype =submitvalue =Register/>
< / form>
For some reason my code isn't updating mySQL database, but it isn't reporting any errors.
register.php (form)
<form class="register_form" action="action.php?do=register" method="post">
Team Name*: <input type="text" name="teamname" required />
Team Region*: <input type="text" name="teamregion" maxlength="4" required />
Team Leader*: <input type="text" name="teamleader" maxlength="16" required />
Team Members: <input type="text" name="teammembers" />
<input name="register_submit" type="submit" value="Register" />
</form>
action.php
<?php
$con=mysqli_connect("192.185.#.###","########_reg","#######","#########");
if (mysqli_connect_errno()) {echo "Failed to connect to MySQL: " . mysqli_connect_error();}
$action = $_GET['do'];
if($action=="register") {
$teamname = $_POST["teamname"];
$teamregion = $_POST["teamregion"];
$teamleader = $_POST["teamleader"];
$teammembers = $_POST["teammembers"];
$result = mysqli_query($con, "INSERT INTO teams (teamname, region, teamleader, teammembers, wins, loses)
VALUES (" . $teamname . "," . $teamregion . "," . $teamleader . "," . $teammembers . ",0,0);");
}
?>
Any ideas why this isn't working correctly?
Here's a working sample with prepared statements, that are "better" to use generally instead of query
action.php
$con = new mysqli('localhost', 'root', '', 'dachi');
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
if (isset($_GET['do']) && $_GET['do'] === "register") {
$teamname = $_POST["teamname"];
$teamregion = $_POST["teamregion"];
$teamleader = $_POST["teamleader"];
$teammembers = $_POST["teammembers"];
$wins = 0;
$loses = 0;
$stmt = $con->prepare("INSERT INTO `teams` (`teamname`,`region`,`teamleader`,`teammembers`,`wins`,`loses`) VALUES (?,?,?,?,?,?)");
$stmt->bind_param('ssssii', $teamname, $teamregion, $teamleader, $teammembers, $wins, $loses);
$stmt->execute();
$stmt->close();
}
register.php
<form class="register_form" action="action.php?do=register" method="post">
Team Name*: <input type="text" name="teamname" required />
Team Region*: <input type="text" name="teamregion" maxlength="4" required />
Team Leader*: <input type="text" name="teamleader" maxlength="16" required />
Team Members: <input type="text" name="teammembers" />
<input name="register_submit" type="submit" value="Register" />
</form>
这篇关于不更新SQL数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!