将用户与输入

时间:2015-09-02 18:31:52

标签: php mysql forms input

我正在尝试能够SELECT已选择玩家并将玩家输入到输入字段的用户。我正在设置草稿类型样式页面。所以我需要所有正在起草的用户出现,然后在他们下面13行供玩家使用。然后我希望能够以他们的名字INSERT玩家提交他们,这样当我提交他们时,玩家与该用户和那一行#(选择号码)相关联。截至目前,即使我在此数据库表中有多个用户(playersByUser),也只显示一列输入。然后,当我尝试INSERT并在输入中提交玩家时,没有任何反应。

如果只列出一个用户并且列中有哪些用户,我做错了什么?那我怎么能INSERT该用户的玩家呢?

数据库表

playersByUser
CREATE TABLE `playersByUser` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `userid` int(11) DEFAULT NULL,
 `playername` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
 `ordering` tinyint(4) DEFAULT NULL,
 PRIMARY KEY (`id`),
 KEY `userid` (`userid`),
 CONSTRAINT `playersByUser_ibfk_1` FOREIGN KEY (`userid`) REFERENCES `users` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci

页码..

$stmt = $con->prepare("SELECT up.ordering, u.id, u.username, up.playername 
FROM users AS u 
INNER JOIN playersByUser AS up ON u.id = up.userid 
WHERE u.group IN (3,4,5)
ORDER BY up.ordering");
if ( !$stmt || $con->error ) {
     // Check Errors for prepare
        die('User/Player SELECT prepare() failed: ' . htmlspecialchars($con->error));
    }
if(!$stmt->execute()) {
        die('User/Player SELECT execute() failed: ' . htmlspecialchars($stmt->error));
}
$stmt->bind_result($ordering, $userid, $username, $playername);
if(isset($_POST['Add Player'])){ 
//Variables to post in the bind_param 
$insert_user_id = $_POST['user_id']; 
$insert_player = $_POST['playername']; 
while ($stmt->fetch()) {
    echo $playername;

}
echo $userid;


$stmt2 = $con->prepare("INSERT INTO playersByUser (user_id, playername) VALUES (?, ?)"); 
if ( false===$stmt2 ) { 
    die('Player Insert prepare() failed: ' . htmlspecialchars($con->error)); 
} 
if(!$stmt2->bind_param('is', $insert_user_id, $insert_player)) { 
    // Check errors for binding parameters 
        die('Player Insert bind_param() failed: ' . htmlspecialchars($stmt2->error)); 
    } 
if(!$stmt2->execute()) { 
        die('Player Insert execute() failed: ' . htmlspecialchars($stmt2->error)); 
    } 
} 
$playerArray = array(); 

//$userid => $insert_player 
//);
?>
        <form action="" method="POST"> 
<?php
while($row = mysqli_fetch_array($stmt)) {
    $playersArray[$row['userid']]=$row['playername'];
?>
    <div class="draftResultsWrap"> 
        <div class="inline"> 
        <?php echo "<div>" . $row['firstname'] . " " . $row['lastname'] . "</div>"; ?> 
        </div> 
            <input type="text" name="<?php echo playerArray . $userid; ?>" class="draftBorder" value='1'/> 
            <input type="text" name="<?php echo playerArray; ?>" class="draftBorder" value='2'/> 
            <input type="text" name="<?php echo playerArray; ?>" class="draftBorder" value='3'/> 
            <input type="text" name="<?php echo playerArray; ?>" class="draftBorder" value='4'/> 
            <input type="text" name="<?php echo playerArray; ?>" class="draftBorder" value='5'/> 
            <input type="text" name="<?php echo playerArray; ?>" class="draftBorder" value='6'/> 
            <input type="text" name="<?php echo playerArray; ?>" class="draftBorder" value='7'/> 
            <input type="text" name="<?php echo playerArray; ?>" class="draftBorder" value='8'/> 
            <input type="text" name="<?php echo playerArray; ?>" class="draftBorder" value='9'/> 
            <input type="text" name="<?php echo playerArray; ?>" class="draftBorder" value='10'/> 
            <input type="text" name="<?php echo playerArray; ?>" class="draftBorder" value='11'/> 
            <input type="text" name="<?php echo playerArray; ?>" class="draftBorder" value='12'/> 
            <input type="text" name="<?php echo playerArray; ?>" class="draftBorder" value='13'/> 
        </div> 
<?php 
} 
?> 
            <button type="submit" method="POST" name="Add Player">Submit Changes</button> 
        </form>

0 个答案:

没有答案