【发布时间】:2014-03-12 00:22:06
【问题描述】:
我一直在努力解决我的问题。 就是这样,我正在构建一个表单,它将通过我的管理面板将新的在线游戏插入我的网站,一切正常,但后来我添加了游戏类别,所以当我上传游戏时,我可以选择它将是哪个类别页面上传到... 因此,我为每个类别选择了一个单选按钮,并尝试使用 $_POST 方法将我勾选的特定类别的值带到 MySQL,由于某种原因,游戏被上传到 MySQL,而“game_category”下没有空值。 ..
这是我的代码:
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<form method="post" id="insert_form" action="insert_game.php" enctype="multipart/form-data">
<div class="insert_form_title">
<h1>Insert New Game Here</h1>
</div>
<div class="insert_form_inline">
<label class="insert_form_field" for="game_name">Game name:</label>
<input type="text" name="game_name">
</div>
<div class="insert_form_inline">
<label class="insert_form_field" for="game_category">Game category:</label>
<input class="radio" type="radio" name="game_category" value="action"<?php print $action_status; ?>/> <span>Action</span>
<input class="radio" type="radio" name="game_category" value="sports"<?php print $sports_status; ?>/> <span>Sports</span>
</div>
<div class="insert_form_inline">
<label class="insert_form_field" for="game_keywords">Game keywords:</label>
<textarea name="game_keywords" cols="60" rows="15"></textarea>
</div>
<div class="insert_form_inline">
<label class="insert_form_field" for="game_image">Game image:</label>
<input type="file" name="game_image">
</div>
<div class="insert_form_inline">
<label class="insert_form_field" for="game_code">Game code:</label>
<input type="file" name="game_code">
</div>
<div class="insert_form_inline">
<label class="insert_form_field" for="game_file">Game flash file:</label>
<input type="file" name="game_file">
</div>
<div class="insert_form_inline">
<label class="insert_form_field" for="game_desc">Game description:</label>
<textarea name="game_desc" cols="60" rows="15"></textarea>
</div>
<div class="submit">
<input type="submit" name="submit" value="Publish Game Now"></td>
</div>
</form>
</body>
</html>
<?php
include("../includes/connect.php");
$action_status = 'unchecked';
$sports_status = 'unchecked';
if(isset($_POST['submit'])){
$game_name = $_POST['game_name'];
$game_category = $_POST['game_category'];
$game_keywords = $_POST['game_keywords'];
$game_image = $_FILES['game_image']['name'];
$image_tmp = $_FILES['game_image']['tmp_name'];
$game_code = $_FILES['game_code']['name'];
$code_tmp = $_FILES['game_code']['tmp_name'];
$game_file = $_FILES['game_file']['name'];
$file_tmp = $_FILES['game_file']['tmp_name'];
$game_desc = $_POST['game_desc'];
if($game_name=='' or $game_category='' or $game_keywords=='' or $game_image=='' or $game_code=='' or $game_file=='' or $game_desc==''){
echo "<script>alert('Please enter all the fields below!')</script>";
exit();
}
else {
$path = "../games/games_files/$game_name";
mkdir("$path", 0777);
move_uploaded_file($image_tmp,"../images/games_images/$game_image");
move_uploaded_file($code_tmp,"$path/$game_code");
move_uploaded_file($file_tmp,"$path/$game_file");
$insert_query = "insert into games (game_name,game_category,game_keywords,game_image,game_code,game_file,game_desc) values ('$game_name','$game_category','$game_keywords','$game_image','$game_code','$game_file','$game_desc')";
if($game_category == 'action'){
$action_status = 'checked';
}else if($game_category == 'sports'){
$sports_status = 'checked';
}else if(mysql_query($insert_query)){
echo "<script>alert('The Game Uploaded Successfully!')</script>";
echo "<script>window.open('view_games.php','_self')</script>";
}
}
}
?>
<?php } ?>
帮助任何人? :(
【问题讨论】:
-
我不确定什么 value="action" 您的代码的一部分是否可能导致错误,因为该值应该只是“动作”编辑:我只是滚动并看到未选中。好的
-
那么我的代码还有什么问题? :o
-
根据它的编写方式,我不知道这个脚本将如何工作。我建议您将所有 PHP 相关代码放在 HTML 代码之上
-
谢谢 Lepanto,现在就试试,但我认为 php 代码在我的 HTML 代码之上或之下都无关紧要......
-
如何编写脚本很重要。因为您在 HTML 中使用了
<?php print $action_status; ?>,其中$action_status从下面的 PHP 脚本中获取值
标签: php mysql button post radio