Jump to content

Validation using multiple values in value form tag


dessolator

Recommended Posts

Hi, I'm creating a form that will create fixtures for a school games system with php and mysql. I have 3 drop down menus on a form Pupil1, Pupil2 and Game. The form displays data from the mysql database such as Name, House and class in a drop down menu which links to a process form.

 

This is a extract from the drop down menu, (row0 is the students id number, row2 is the students house)

echo"<option style='background: yellow' value='$row[0] $row[4]'>Name: $row[1] $row[2] | Class: $row[3] | House: $row[4]</option>";

 

On the process form I would like to validate that people from the green house can only play people from the yellow house which is the $row[4] in the value section but I don't know how to separate the id which is row0 and the house (row4) in the value tag. I can't find any contains tag such as if 'select1' contatains 'yellow'{do this}, I was wondering if you could help me out, I would really appreciate it.

 

Thanks,

 

ian

Link to comment
Share on other sites

Sorry I haven't had time to tidy it up yet but here is the form:

 

<?php  
$host="localhost"; // Host name
$username="root"; // Mysql username
$password="abc123"; // Mysql password
$db_name="games_db1"; // Database name
$tbl_name="members"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
?>
<form id='form1' name='form1' method='post' action='gameprocessform.php'>
<center>
<b>Arrange a match</b><br/ ><br/ >
<select name='select'>
<?php
//FIRST DROP DOWN
echo "<center>";
//Database - Assigns the below statement into the variable query
$query = "SELECT id, forename, surname, class, house FROM members WHERE house = 'yellow' AND permissions ='3'";
$result = mysql_query($query);
//$row = mysql_fetch_row($result);
while($row = mysql_fetch_array($result))
  {
echo"<option style='background: yellow' value='$row[0] $row[0]'>Name: $row[1] $row[2] | Class: $row[3] | House: $row[4]</option>";
}
echo "</center>";


$query1 = "SELECT id, forename, surname, class, house FROM members WHERE house = 'green' AND permissions ='3'";
$result1 = mysql_query($query1);
echo "<center>";
while($row = mysql_fetch_array($result1))
  {
echo"<option style='background: green' value='$row[0]'>Name: $row[1] $row[2] | Class: $row[3] | House: $row[4]</option>";
}
echo "</center>";
?>
</select>

<br/ >VS<br/ >


<select name='select1'>
<?php
//SECOND DROP DOWN
echo "<center>";
//Database - Assigns the below statement into the variable query
$query2 = "SELECT id, forename, surname, class, house FROM members WHERE house = 'yellow' AND permissions ='3'";
$result2 = mysql_query($query2);
//$row = mysql_fetch_row($result);
while($row = mysql_fetch_array($result2))
  {
echo"<option style='background: yellow' value='$row[0] $row[0]'>Name: $row[1] $row[2] | Class: $row[3] | House: $row[4]</option>";
}
echo "</center>";


$query3 = "SELECT id, forename, surname, class, house FROM members WHERE house = 'green' AND permissions ='3'";
$result3 = mysql_query($query3);
echo "<center>";
while($row = mysql_fetch_array($result3))
  {
echo"<option style='background: green' value='$row[0]'>Name: $row[1] $row[2] | Class: $row[3] | House: $row[4]</option>";
}
echo "</center>";
?>
</select>
</center>  


<?php 
//GAMES DROP DOWN 
$query = "SELECT game FROM games";
$result = mysql_query($query);
?>
<center>
<br/ >GAME<br/ >
<select name='select2'>
<?php
while($row = mysql_fetch_array($result))
  {

echo"<option style='background: blue'  value='$row[0]'>$row[0]</option>";
}
?>
</select>
  
  <br/ ><br/>  
  <input type="submit" value="Submit" />
  </center>
</form>
</body>
</html>

 

 

Here is the process form at the moment:

 

<?php
ob_start();
$host="localhost"; // Host name
$dbusername="root"; // Mysql username
$password="abc123"; // Mysql password
$db_name="games_db1"; // Database name
$tbl_name="members"; // Table name

$first_student= substr($_POST['select'], 0, 99);
$second_student= substr($_POST['select1'], 0, 99);
$game=substr($_POST['select2'], 0, 99);

echo $first_student;
echo "\n";
echo $second_student;
echo "\n";
echo $game;
echo "\n";


if ($first_student == $second_student){
echo "Sorry you must select two different students, one from the yellow house and one from the green house.";
}
else{
echo "Congrats";
}
?>


 

 

 

So basically what I want is to get the select and select1 values from the form and separate the values (ID and House) that are submitted in the value tag so that I can validate that people from the green house can only play people from the yellow house.

 

Hope this clarifies it.

 

 

Thanks,

 

Ian

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.