开发者

MySQL/PHP: Inserting randomized data from html checkboxes into mysql via PHP

I have yet another question regarding the randomization of data!

$gender='';
if(isset($_GET['gender'])) {
$gender=$_GET['gender'];
}
$status_array = $_GET['status'];
foreach ($status_array as $one_status) {
$statussource .= $one_status.", ";
$status = substr($statussource, 0, -2);
}
$age_array = $_GET['age'];
foreach ($age_array as $one_age) {
$agesource .= $one_age.", ";
$age = substr($agesource, 0, -2);
}
$incidentid='';
if(isset($_GET['incidentid'])) {
$incidentid=$_GET['incidentid'];
}

mysql_connect ("$host", "$username", "$password") or die ("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$sql="INSERT INTO $tbl_name (given_name, family_name, gender, status, age, incidentid)
select First10.$gender, Last10.family_name,
(SELECT $gender from gender) AS Gender,
(SELECT * FROM status where status = '$status') AS Status,
(SELECT * FROM age where age = '$age') AS Age,
(SELECT $incidentid from incidentid) AS Incident_ID
from ( select fn.$gender, @fns := @fns + 1 as Sequence
from ( select $gender from fnames where $gender IS NOT NULL order by rand() limit 100) fn,
(select @fns := 0 ) vars ) First开发者_如何学编程10
JOIN
( select ln.family_name, @lns := @lns + 1 as Sequence
from ( select family_name from lastnames order by rand() limit 100 ) ln,
(select @lns := 0 ) vars ) Last10
ON First10.Sequence = Last10.Sequence";
$result=mysql_query($sql);
if($result){
echo "Generated Successfully";
echo "<BR>";
echo "<a href='randomdata.php'>Back to main page</a>";
}

else {
echo "ERROR";
}
mysql_free_result($result);
// close connection
mysql_close();

?>

My qualm here is that I am aiming to generate random names with randomized status and age values for the purpose of testing. The checkboxes are in proper format:

<p>
Status: <BR>
<INPUT TYPE=CHECKBOX name="status[]" value="ali">Alive and Well<BR>
<INPUT TYPE=CHECKBOX name="status[]" value="inj">Injured<BR>
<INPUT TYPE=CHECKBOX name="status[]" value="dec">Deceased<BR>
<INPUT TYPE=CHECKBOX name="status[]" value="unk">Unknown<BR>
<INPUT TYPE=CHECKBOX name="status[]" value="fnd">Found<BR>
<INPUT TYPE=CHECKBOX name="status[]" value="mis">Missing<BR>
</p>

<p>
Age: <BR>
<INPUT TYPE=CHECKBOX name="age[]" value="0-17">Youth (0-17)<BR>
<INPUT TYPE=CHECKBOX name="age[]" value="18+">Adult (18+)<BR>
<INPUT TYPE=CHECKBOX name="age[]" value="NULL">Unknown<BR>

However, I can only seem to receive a response for the status and age if only 1 value is selected from the set of checkboxes. I would like to be able to select multiple checkboxes and receive those values in a randomized format. Please advise.

If you need any clarifications on my question, just ask.


From what I understand, all those values are mutually exclusive. If this is the case, perhaps using a radio button would be more appropriate.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜