I'm trying to make a page on php that dynamically insert some events from my sql database, the problem is, when i put it on a HTML, i can't post the id that i have clicked.
Or it means, when i click on a entire div i need to post it whit the id of an input type hidden...
Any tips?
Here is my code:
<?php
if($_POST){
$sql = mysql_query("SELECT * FROM evento");
while ($evento = mysql_fetch_object($sql)) {
if($_POST["id".$evento->id_evento] == $evento->id_evento){
echo "oi";
}
}
}else{
$sql = mysql_query("SELECT * FROM evento");
while ($evento = mysql_fetch_object($sql)) {
echo "<form action='eventos' method='POST'>
<input type='hidden' name='id' value='".$evento->id_evento."'/>
<div onclick='javascript: this.submit();' id='id' class='col-md-4' >
<div style='white-space: nowrap;text-align: center;min-height:190px'>
<span style='display: inline-block;height: 100%;vertical-align: middle;'></span><img src='".$root."img/upload/eventos/".$evento->img."' style='width:100%; max-height:200px; vertical-align: middle;'>
</div>
<p style='color:#00AEC3;background:#F2F2F4;padding:10px 5px'>" . $evento->titulo . "<br> <span style='color:black'>".date('d/m/Y', strtotime($evento->data_inicio))." à ".date('d/m/Y', strtotime($evento->data_fim))."</span></p>
</div>
</form>";
}
}
?>
The above is not valid PHP code. PHP does not use the . operator, I think you are confusing javascript and PHP. PHP uses the -> operator so it would probably be something like the following (if that class exists)..
However I think you are trying to get at the ID column for the database record and if that is the case the above still will not work because the database record will not be a 3 dimensional object like you are doing with the submit() method. Database results will never have a submit method. Maybe something like the code below will solve your problem.
My FEAR is that you want some javascript code in that onclick handler while also passing the ID through but I have no idea what you are trying to accomplish here other than putting an ID into an onclick handler. For something like that you could do something like this.