我为这个荒谬的长代码道歉。问题是它不会将代码发送到数据库。什么都没发生,我没有收到任何错误。数据不会发送到数据库。您可以添加多少列是否有限制?我用更少的东西完成了这项工作并且它有效,我不知道问题可能是什么。
<?php
$connection = @mysqli_connect("localhost","root","","RS");
if($connection->connect_error){
die("Connection failed: " . $connection->connect_error);
}
if(isset($_POST['submit'])) {
$username = $_POST['username'];
$joindate = $_POST['joindate'];
$age = $_POST['age'];
$languages = $_POST['languages'];
$oldname = $_POST['oldname'];
$fishing = $_POST['fishing'];
$frontwebdev = $_POST['frontwebdev'];
$backwebdev = $_POST['backwebdev'];
$writing = $_POST['writing'];
$programming = $_POST['programming'];
$art = $_POST['art'];
$se = $_POST['se'];
$smm = $_POST['smm'];
$testing = $_POST['testing'];
$timezone = $_POST['timezone'];
$availability = $_POST['availability'];
$reliability = $_POST['reliability'];
$avatar = $_POST['avatar'];
if ($age == 0 or $age == '') {
$age = NULL;
}
if ($oldname == '') {
$age = NULL;
}
if ($fishing == 0 or $fishing == '') {
$fishing = NULL;
}
if ($frontwebdev == 0 or $frontwebdev == '') {
$frontwebdev = NULL;
}
if ($writing == 0 or $writing == '') {
$writing = NULL;
}
if ($frontwebdev == 0 or $frontwebdev == '') {
$frontwebdev = NULL;
}
if ($programming == 0 or $programming == '') {
$programming = NULL;
}
if ($frontwebdev == 0 or $frontwebdev == '') {
$frontwebdev = NULL;
}
if ($art == 0 or $art == '') {
$art = NULL;
}
if ($se == 0 or $se == '') {
$se = NULL;
}
if ($smm == 0 or $smm == '') {
$smm = NULL;
}
if ($testing == 0 or $testing == '') {
$testing = NULL;
}
if ($timezone == 0 or $timezone == '') {
$timezone = NULL;
}
if ($availability == 0 or $availability == '') {
$availability = NULL;
}
if ($reliability == 0 or $reliability == '') {
$reliability = NULL;
}
if ($avatar == 0 or $avatar == '') {
$avatar = NULL;
}
$sql = "INSERT INTO userinfo (username, joindate, age, languages, oldname, fishing, frontwebdev, backwebdev, writing, programming, art, se, smm, testing, timezone, availability, reliability, avatar) VALUES ('" . $username . "', '" . $joindate . "', '" . $age . "', '" . $languages . "', '" . $oldname . "', '" . $fishing . "', '" . $frontwebdev . "', '" . $backwebdev . "', '" . $writing . "', '" . $programming . "', '" . $art . "', '" . $se . "', '" . $smm . "', '" . $testing . "', '" . $timezone . "', '" . $availability . "', '" . $reliability . "', '" . $avatar . "';";
mysqli_query($connection,$sql);
}
mysqli_close($connection);
?>
HTML
<form method="post" style="text-align: center;">
<table>
<tr>
<td>Username</td><td><input type="text" name="username" style="width: 400px; padding: 3px;" placeholder="Required"><br /><br /><td>
</tr>
<td>Join year</td><td><input type="text" name="joindate" style="width: 400px; padding: 3px;" placeholder="Optional"><br /><br />
<tr>
<td>Age</td><td><input type="text" name="age" style="width: 400px; padding: 3px;" placeholder="Optional"><br /><br />
</tr>
<tr>
<td>Languages</td><td><input type="text" name="languages" style="width: 400px; padding: 3px;" placeholder="Optional"><br /><br />
</tr>
<tr>
<td>Old Name</td><td><input type="text" name="oldname" style="width: 400px; padding: 3px;" placeholder="Optional"><br /><br />
</tr>
<tr>
<td>Fishing skill</td><td><input type="text" name="Fishing" style="width: 400px; padding: 3px;" placeholder="Optional"><br /><br />
</tr>
<tr>
<td>Front web dev skill</td><td><input type="text" name="frontwebdev" style="width: 400px; padding: 3px;" placeholder="Optional"><br /><br />
</tr>
<tr>
<td>Back web dev skill</td><td><input type="text" name="backwebdev" style="width: 400px; padding: 3px;" placeholder="Optional"><br /><br />
</tr>
<tr>
<td>Writing</td><td><input type="text" name="writing" style="width: 400px; padding: 3px;" placeholder="Optional"><br /><br />
</tr>
<tr>
<td>Programming</td><td><input type="text" name="programming" style="width: 400px; padding: 3px;" placeholder="Optional"><br /><br />
</tr>
<tr>
<td>Art</td><td><input type="text" name="art" style="width: 400px; padding: 3px;" placeholder="Optional"><br /><br />
</tr>
<tr>
<td>SE</td><td><input type="text" name="se" style="width: 400px; padding: 3px;" placeholder="Optional"><br /><br />
</tr>
<tr>
<td>Social Media Management</td><td><input type="text" name="smm" style="width: 400px; padding: 3px;" placeholder="Optional"><br /><br />
</tr>
<tr>
<td>Testing</td><td><input type="text" name="testing" style="width: 400px; padding: 3px;" placeholder="Optional"><br /><br />
</tr>
<tr>
<td>Timezone</td><td><input type="text" name="timezone" style="width: 400px; padding: 3px;" placeholder="Optional"><br /><br />
</tr>
<tr>
<td>Availability</td><td><input type="text" name="availability" style="width: 400px; padding: 3px;" placeholder="Required"><br /><br />
</tr>
<tr>
<td>Reliability</td><td><input type="text" name="reliability" style="width: 400px; padding: 3px;" placeholder="Required"><br /><br />
</tr>
<tr>
<td>Url to avatar</td><td><input type="text" name="avatar" style="width: 400px; padding: 3px;" placeholder="Optional"><br /><br />
</tr>
</table>
<input type="submit" name="submit" value="Submit" id="submit"/>
</form>
谢谢。
答案 0 :(得分:0)
“钓鱼技巧”文本框的名称属性为“钓鱼”,您的PHP代码引用$_POST['fishing']
变量名(和像这样的数组索引)区分大小写,因此值不会被设置,并且可能会阻止插入查询完成。更正此问题可能会解决您的问题。
答案 1 :(得分:0)
您需要在SQL结尾处关闭VALUES
括号,而不是分号(&#39; ;
&#39;)
$sql = "INSERT INTO userinfo
(username, joindate, age, languages,
oldname, fishing, frontwebdev, backwebdev,
writing, programming, art, se, smm, testing,
timezone, availability, reliability, avatar)
VALUES ('" . $username . "', '" . $joindate . "',
'" . $age . "', '" . $languages . "',
'" . $oldname . "', '" . $fishing . "',
'" . $frontwebdev . "', '" . $backwebdev . "',
'" . $writing . "', '" . $programming . "',
'" . $art . "', '" . $se . "', '" . $smm . "',
'" . $testing . "', '" . $timezone . "',
'" . $availability . "', '" . $reliability . "',
'" . $avatar . "')";
^
here