mercredi 14 janvier 2015

How to get the checkboxes value in checked order in php

In the registration part there will be some images and it will shuffle automatically in each refresh. user should select one or more images (tick the corresponding checkboxes) and it will stored in database instead of password.It will work correctly and problem is in login page.I want the values of checkboxes in checked order. that means if I checked second checkbox and then first box,then value will get the same order.


here is the code



<?php
include("config.php");
if(isset($_POST['s'])){
$username=$_POST['username'];
if(isset($_POST['chk1']))
{
$t1=implode(',', $_POST['chk1']);
}
echo $t1;
$query=mysql_query("select *from register where username='$username' and password='$t1'");
$res=mysql_num_rows($query);
if($res>0)
{
session_start();
$_SESSION['usr']=$username;
header("location:userhome.php");
}
else
{
echo mysql_error();
}
}
?>

<body>
<form action="" method="post">
<table width="200" border="0">
<th colspan="2" scope="row"><a href="register.php">
<font color="#FF0000">New Registration</font> </a></th>
</tr>
<tr>
<th scope="row">Username</th>
<td><label for="username"></label>
<input type="text" name="username" id="username" /></td>
</tr>
<tr>
<th colspan="2" scope="row"><u>Choose Password</u></th>
</tr>
<tr>
<th scope="row">&nbsp;</th>
<td>&nbsp;</td>
</tr>
</table>
<div align="center">
<?php
$images = array(
'<input name="chk1[]" type="checkbox" value="1" />
<img src="images/images (4).jpg" alt="" width="234" height="212" />',
'<input name="chk1[]" type="checkbox" value="2" />
<img src="images/images (6).jpg" alt="" width="234" height="212" />',
'<input name="chk1[]" type="checkbox" value="3" />
<img src="images/images (5).jpg" alt="" width="234" height="212" />',
'<input name="chk1[]" type="checkbox" value="4" />
<img src="images/drt.jpg" alt="" width="234" height="212" />',
'<input name="chk1[]" type="checkbox" value="5" />
<img src="images/rf.jpg" alt="" width="234" height="212" />',
'<input name="chk1[]" type="checkbox" value="6" />
<img src="images/yu.jpg" alt="" width="234" height="212" />',
'<input name="chk1[]" type="checkbox" value="7" />
<img src="images/ed.jpg" alt="" width="234" height="212" />'
);
shuffle($images); // Randomize images array;
echo $images[0];
echo $images[1];
echo $images[2];
echo $images[3];
echo $images[4];
echo $images[5];
echo $images[6];
?>









Aucun commentaire:

Enregistrer un commentaire