我一直在努力解決我的問題。 所以在這裏,我正在構建一個表單,通過我的管理面板將新的在線遊戲插入到我的網站,一切工作都很完美,但後來我添加了遊戲類別,所以當我上傳遊戲時,我可以選擇哪個類別的頁面被上傳到... 因此,我爲每個類別選擇了一個單選按鈕,並且試圖使用$ _POST方法將特定類別的值帶到MySQL中,並且出於某種原因,遊戲無需上傳到MySQL在 「game_category」 空值...如何將單選按鈕的值發佈到MySQL
這裏是我的代碼:
<!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 } ?>
幫助的人? :(
我不確定什麼值=「動作」<?php print $ action_status; ?>你的代碼的一部分,它可能會導致錯誤,因爲該值應該只是「行動」編輯:我只是滾動,看到未選中。好吧 – Chitowns24
那麼我的代碼還有什麼問題呢? :o – davidgpilot
我不知道這個腳本將如何基於它被寫入的方式工作。我建議你把所有的PHP相關的代碼上面的HTML代碼 – Lepanto