I need to pass values from a cell inside my main page to another page.
I have to pass: Monday
9.00
Username
week
year
. Last 3 defined inside an input returned NULL
in my database. First 2 returned 0
. All those values should be known in the main page so the user doesn't have to insert anything.
Username is even printed before in the main page. Input requires some sort of action from the user? If so (which could explain the null
and 0
values) how can I pass values without having to make the user insert something?
Here's the code and some screen describing my situation.
// First cell form to pass data to booking.php
<?php
$week = date("W");
$year = (isset($_GET['year']))?$_GET['year']:date("Y");
$week = (isset($_GET['week']))?$_GET['week']:Date('W');
if($week>52){
$year+= 1;
$week=1;
}elseif($week < 1) {
$year--;
$week = 52;
}
?>
<a href="<?php echo $_SERVER['PHP_SELF'].'?week='.($week-1).'&year='.$year; ?>">Pre Week</a> <!--Settimana Precendete-->
<a href="<?php echo $_SERVER['PHP_SELF'].'?week='.($week+1).'&year='.$year; ?>">Next Week</a> <!--Settimana Prossima-->
<table border="1px" class="WeekLayout">
<tr>
<td>Schedule</td>
<?php
if($week < 10) {
$week = '0'. $week;
}
for($day=1; $day<=7; $day++)
{
$d = strtotime($year."W".$week.$day);
echo "<td>".date('l',$d )."<br>";
echo date('d M Y',$d)."</td>";
}
?>
</tr>
<form action="Booking.php" method="POST" name="BookingForm" id="BookingForm">
<tr class="9">
<td>9.00
</td>
<td class="free" onclick="Change(this)"><a href=""> </a>
<input type="hidden" name="Monday">
<input type="hidden" name="9.00"></td>
<td class="free" onclick="Change(this)"><a href=""></a></td>
<td class="free" onclick="Change(this)"><a href=""></a></td>
<td class="free" onclick="Change(this)"><a href=""></a></td>
<td class="free" onclick="Change(this)"><a href=""></a></td>
<td class="free" onclick="Change(this)"><a href=""></a></td>
<td class="free" onclick="Change(this)"><a href=""></a></td>
</tr>
<tr>
</table>
<input type="hidden" name="$Username">
<input type="hidden" name="$week">
<input type="hidden" name="$year">
<input value="Prenota" type="submit" class="buttonsubmit" id="Prenota">
</form>
</div>
//Connection to database
<?php
$user = 'root';
$password = '';
$db = 'elencoprenotazioni';
$host = 'localhost';
$dblink2 = new mysqli($host, $user, $password, $db)
or die("Connessione non riuscita: " . mysqli_error());
?>
//Prenotation system
<?php
include("Connessione2.php");
session_start();
$Username = $_POST['Username'];
$week = $_POST['week'];
$year = $_POST['year'];
$day = $_POST['day'];
$hour = $_POST['hour'];
$queryinsert = mysqli_query($dblink2, "INSERT INTO calendario (Username, week, year, day, hour) VALUES ('$Username','$week','$year','$day','$hour')");
if($queryinsert)
{
header("location: index.html");
}
mysqli_close();
?>
Doing this way inside my database I only got this:
As you can see I get 0
for values that should be in my main page and null
from values I define inside my form.
Full view of the page:
As you can see from URL week
and year
should be known and Username
is printed just near the logout button.
Why are you using values in name attribute?
Please change these...
<input type="hidden" name="Monday">
<input type="hidden" name="9.00"></td>
<input type="hidden" name="$Username">
<input type="hidden" name="$week">
<input type="hidden" name="$year">
to these first
<input type="hidden" name="day" value="Monday">
<input type="hidden" name="hour" value="9.00"></td>
<input type="hidden" name="Username" name="MyUsername">
<input type="hidden" name="week" name="53">
<input type="hidden" name="year" name="2016">