Jump to content

Form with radio and Post


Ryflex

Recommended Posts

Hi all,

 

I have a page with 4 textboxes which can be filled out. The thing is I want people to be able to only train 1 type at a time.

Underneath I posted the Form page and the exec page does anyone have and idea??

 

Thnx Ryflex

 

FORM:

<?php
//authentication & database configuration
require_once('auth.php');
require_once('config.php');

//member_ID and city_ID	and greyed out empty declaration				
$member_ID			= $_SESSION['SESS_MEMBER_ID'];
$city_ID			= $_SESSION['SESS_CITY_ID'];
$ro					= "";

//Database connection
$global_dbh			= mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)
				  or die("Could not connect to database");
				  mysql_select_db(DB_DATABASE, $global_dbh)
				  or die("Could not select database");

//get infantry units type = 1
$sql				= "SELECT name, resource_1, resource_2, resource_3, timestamp FROM unittype WHERE type = 1";
$result				= mysql_query($sql) or die("Could not find units");
//get the 4 unit types in the $n[] array
while($data = mysql_fetch_assoc($result))
{
$one[]				= $data[resource_1];
$two[]				= $data[resource_2];
$three[]			= $data[resource_3];
$time[]				= $data[timestamp];

}
//query amount of infantry troops
$sql				= "SELECT * FROM infantry WHERE member_id = '$member_ID'";
$result				= mysql_query($sql) or die("Could not find amount of troops");
//get amount of infantry troops
while($data = mysql_fetch_assoc($result))
{
$n[]				= $data[name];
$training[]			= $data[training];
$timestamp[]		= $data[timestamp];
$amount[]			= $data[amount];
}
//check if a training is underway
$sql					= "SELECT * FROM infantry WHERE member_id = '$member_ID' AND training = 1";
$trcurr					= mysql_fetch_array( mysql_query($sql));
if($trcurr['training'] == 1)
{
$ro						= "READONLY STYLE='color:#999999;background:#DEDEDE'";
}
?>
<html>
<head>
<title>Infantry Training</title>
<link href="loginmodule.css" rel="stylesheet" type="text/css" />
</head>
<body>
<p>You can only train 1 type of infantry at a time.</p>
<form id="create" name="create" method="POST" action="infantry_exec.php">
<table>
<tr>
<td><b><?php echo $n[0]; ?></b></td>
<td><b><input name="<?php echo $n[0]; ?>" type="text" <?php echo $ro; ?> maxlength="10" id="<?php echo $n[0]; ?>" /></b></td>
</tr>
<tr>
<td><b><?php echo $n[1]; ?></b></td>
<td><b><input name="<?php echo $n[1]; ?>" type="text" <?php echo $ro; ?> maxlength="10" id="<?php echo $n[1]; ?>" /></b></td>
</tr>
<tr>
<td><b><?php echo $n[2]; ?></b></td>
<td><b><input name="<?php echo $n[2]; ?>" type="text" <?php echo $ro; ?> maxlength="10" id="<?php echo $n[2]; ?>" /></b></td>
</tr>
<tr>
<td><b><?php echo $n[3]; ?></b></td>
<td><b><input name="<?php echo $n[3]; ?>" type="text" <?php echo $ro; ?> maxlength="10" id="<?php echo $n[3]; ?>" /></b></td>
</tr>
<tr>
<td colspan="2"><center><input type="submit" name="Submit" value="Train!!!" /></center></td>
</tr>
</table>
</form>
</body>
</html>

 

EXEC:

<?php
//authentication & database configuration
require_once('auth.php');
require_once('config.php');

//member_ID and city_ID				
$member_ID			= $_SESSION['SESS_MEMBER_ID'];
$city_ID			= $_SESSION['SESS_CITY_ID'];

//Database connection
$global_dbh			= mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)
				  or die("Could not connect to database");
				  mysql_select_db(DB_DATABASE, $global_dbh)
				  or die("Could not select database");

//query names of infantry troops
$sql				= "SELECT * FROM infantry WHERE member_id = '$member_ID'";
$result				= mysql_query($sql) or die("Could not find amount of troops");
//get names of infantry troops
while($data = mysql_fetch_assoc($result))
{
$n[]				= $data[name];
}
//convert POST to normal variable
$amount				= array(0 => $_POST[$n[0]], 1 => $_POST[$n[1]], 2 => $_POST[$n[2]], 3 => $_POST[$n[3]]);

?>

Link to comment
Share on other sites

Hi sloth456,

 

This is what the Form page shows

 

You can only train 1 type of infantry at a time.

gunner     [textbox]

marine     [textbox]

sniper     [textbox]

special ops  [textbox]

Train!!!

 

The EXEC page only puts the amounts out of the textbox into the database.

In the FORM page I need something that functions like a radio button idea so only one thing can be "trained" at a time.

 

Thnx Ryflex

 

Link to comment
Share on other sites

Hi all,

 

I changed the form with radio buttons but when I get the $_POST[train] it only says: on.

<form id="create" name="create" method="POST" action="infantry_exec.php">
<table>
<tr>
<td><b><?php echo $n[0]; ?></b></td>
<td><b><input name="train" type="radio" value-"<?php echo $n[0]; ?>" /></b></td>
<td rowspan="4"> How many troops do you want to train?<BR><input name="amount" maxlength="10" <?php echo $ro; ?> id="amount"></td>
</tr>
<tr>
<td><b><?php echo $n[1]; ?></b></td>
<td><b><input name="train" type="radio" value="<?php echo $n[1]; ?>" /></b></td>
</tr>
<tr>
<td><b><?php echo $n[2]; ?></b></td>
<td><b><input name="train" type="radio" value="<?php echo $n[2]; ?>" /></b></td>
</tr>
<tr>
<td><b><?php echo $n[3]; ?></b></td>
<td><b><input name="train" type="radio" value="<?php echo $n[3]; ?>" /></b></td>
</tr>
<tr>
<td colspan="2"><center><input type="submit" name="Submit" value="Train!!!" /></center></td>
</tr>
</table>
</form>

 

//convert POST to normal variable
$amount				= $_POST[amount];
$type				= $_POST[train];
echo "$amount <BR> $type";

 

Thnx Ryflex

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.