I'm kinda new at coding using php..
and I have a problem with the expected output of my code below..
For example, at first run..
I will input 'A' on the textfield named 'plate'
when I press the button Park, the output is like this:
Array ([0] => A [1] => [2] => [3] => [4] => [5] => [6] => [7] => [8] => [9] => )
then when I input 'B' then pressed 'Park'....
the output is like this....
Array ([0] => B [1] => [2] => [3] => [4] => [5] => [6] => [7] => [8] => [9] => )
I was kinda expecting the output to be like this..
Array ([0] => A [1] =>B [2] => [3] => [4] => [5] => [6] => [7] => [8] => [9] => )
The problem is that the value that I will input is always saved at the FIRST index of my array everytime I press Park..
I was expecting that when I pressed 'PARK', the value that I will input will be saved to the next index and not overwrite the value of the first index of the array..
our prof has clearly specified that we should not use session when solving this machine problem...is it possible without using sessions?
any ideas?
I would really appreciate it. thank you! (^_^)
here's my code..
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
</head>
<body>
<?php
$arr= array("","","","","","","","","","");
?>
<form method="POST" action="index.php">
Plate #: <input name="plate" type="text" ><br/><br/>
<input name="park" type="submit" value="PARK">
</form>
<?php
if(isset($_POST['park']))
{
$plate= $_POST["plate"];
$flag=0;
for($i=0; $i<10;$i++){
if(($arr[$i]=="") && ($flag==0)){
$arr[$i]= $plate;
$flag=1;
}
}
print_r($arr);
}
?>
</body>
</html>