gpt4 book ai didi

php - 表单有时仅有效(PHP mySQL)

转载 作者:行者123 更新时间:2023-11-30 00:38:41 27 4
gpt4 key购买 nike

我用谷歌搜索了很多,但找不到我的问题的答案。我创建了一个表单来在我的网站上提交一些信息。问题是它只有时有效,我不知道为什么。你的帮助我会非常感激,我快要疯了。

PHP

 <?php 
require_once("php/verbindung.php");

$partyskill = "";
$partyskill2 = "";
$partylang = "";
$partycount = "";
$drop = "";

$error_count = "";
$error_lang = "";

$freigabe = true;

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

$partyskill = "$_POST[skill]";
$partyskill2 = "$_POST[skill2]";
$partylang = "$_POST[language]";
$partycount = "$_POST[count]";


if (strlen($partycount) == 0) {
$error_count = "<FONT COLOR='#d1a200'>*please select how many players you are looking for</font>";
$freigabe = false;
}

if (strlen($partylang) == 1) {
if($partylang=="1")
{$drop="gb.png";}

elseif($partylang== "2")
{$drop="de.png";}

elseif($partylang== "3")
{$drop="ru.png";}

else {
$error_lang = "<FONT COLOR='#d1a200'>*please select a language</font>";
$freigabe = false;
}
}

else {
$error_lang = "<FONT COLOR='#d1a200'>*please select a language</font>";
$freigabe = false;
}

if ($freigabe == true) {
$sql = "INSERT INTO ".$tblparty;
$sql .= " (skill, skill2, count, language)
VALUES (";
$sql .= "'".$partyskill."', ";
$sql .= "'".$partyskill2."', ";
$sql .= "'".$partycount."', ";
$sql .= "'".$drop."') ";

$query = mysql_query($sql, $verb);

}
}

?>

HTML

 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="new_party" >
<h3>How many players are you searching for?</h3>
<p>
<input type="radio" name="count" value="1"> 1
<input type="radio" name="count" value="2"> 2
<input type="radio" name="count" value="3"> 3
<input type="radio" name="count" value="4"> 4
</p>
<?php echo $error_count; ?><br/>
<h3>What is you prefered language?</h3>
<p>
<input type="radio" name="language" value="1"><img src="images/flags/gb.png"/>
<input type="radio" name="language" value="2"><img src="images/flags/de.png"/>
<input type="radio" name="language" value="3"><img src="images/flags/ru.png"/>
</p>
<?php echo $error_lang; ?><br/>
<h3>What skill are you looking for?</h3>
from:
<select name="skill">
<option value="15">Eagle Master</option>
<option value="16">Legendary Eagle Master</option>
<option value="17">Supreme Master First Class</option>
<option value="18">Global Elite</option>
</select>
to:
<select name="skill2">
<option value="15">Eagle Master</option>
<option value="16">Legendary Eagle Master</option>
<option value="17">Supreme Master First Class</option>
<option value="18">Global Elite</option>
</select>
<input type="submit" value="Send" name="submit"/>
</form>

最佳答案

而不是这样做:

$sql = "INSERT INTO ".$tblparty; 
$sql .= " (skill, skill2, count, language)
VALUES (";
$sql .= "'".$partyskill."', ";
$sql .= "'".$partyskill2."', ";
$sql .= "'".$partycount."', ";
$sql .= "'".$drop."') ";

将其更改为:

$sql = "INSERT INTO `$tblparty` (`skill`, `skill2`, `count`, `language`) 
VALUES ('".$partyskill."', '".$partyskill2."', '".$partycount."', '".$drop."')";

然后删除您的技能列并重新创建它。您还可以尝试重建表。

另外,我建议您切换到mysqli_*使用 prepared statements 的函数或PDO , mysql_* 函数已弃用,并将在未来版本中删除。

关于php - 表单有时仅有效(PHP mySQL),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21964096/

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