If I press on my post button the data of my form will be send to the database but I get 2 Array to string error's. I don't know what I have to change to fix these errors.
Here is also a picture of the data in my database where it is showing arrays.
https://gyazo.com/f7463825b6ae2e44812d5149d55e9011
I hope someone can help me! I am learning :P
Here is my code example.
<html>
<title>HOTEL</title>
<center>
<head>
<h2>
<?php echo "Welkom terug " . $_SESSION["username"] . ""?>
</br>
<a href='logout.php'>Log uit</a></br>
</h2>
<hr>
<h1>Film toevoegen</h1>
<hr>
</head>
<body>
<form method="POST">
<table>
<tr>
<td>Film:</td>
<td><input type="text" name="txtFilm"></td>
</tr>
<tr>
<td>Genre:</td>
<td>
<select name="Genre">
<option value="Actie">Actie</option>
<option value="Fantasie">Fantasie</option>
<option value="Horror">Horror</option>
<option value="Avontuur">Avontuur</option>
<option value="Komedie">Komedie</option>
<option value="Romantiek">Romantiek</option>
<option value="Historisch">Historisch</option>
</select>
</td>
</tr>
<tr>
<td>Film omschrijving:</td>
<td><input type="text" name="txtFilmomschrijving"></td>
</tr>
<tr>
<td>Datum van uitkomst: </td>
<td><input type="date" name="uitkomstdate">
</td>
</tr>
<tr>
<td>Datum uit bioscoop: </td>
<td><input type="date" name="BiosDate">
</td>
</tr>
<tr></tr>
<tr></tr>
<tr></tr>
<tr>
<td>Film draai dagen: </td>
<td>
<input type="checkbox" value="Maandag" name="draaidag[]">Maandag
<input type="checkbox" value="Dinsdag" name="draaidag[]">Dinsdag
<input type="checkbox" value="Woensdag" name="draaidag[]">Woensdag
<input type="checkbox" value="Donderdag" name="draaidag[]">Donderdag
<input type="checkbox" value="Vrijdag" name="draaidag[]">Vrijdag
<input type="checkbox" value="Zaterdag" name="draaidag[]">Zaterdag
<input type="checkbox" value="Zondag" name="draaidag[]">Zondag
</td>
</tr>
<tr>
<td>Film tijd dagen: </td>
<td>
<input type="checkbox" value="12uur" name="tijddagen[]">12:00
<input type="checkbox" value="14uur" name="tijddagen[]">14:00
<input type="checkbox" value="16uur" name="tijddagen[]">16:00
<input type="checkbox" value="18uur" name="tijddagen[]">18:00
<input type="checkbox" value="20uur" name="tijddagen[]">20:00
<input type="checkbox" value="22uur" name="tijddagen[]">22:00
<input type="checkbox" value="24uur" name="tijddagen[]">24:00
</td>
</tr>
<tr>
<td>Zaal: </td>
<td>
<select name="zaal">
<option value="normaal">Normaal</option>
<option value="groot">Groot</option>
</select>
</td>
</tr>
<tr></tr>
<tr></tr>
<tr></tr>
<td></td>
<td>
<input type="submit" value="Film toevoegen" name="btnHuur" />
</td>
</tr>
</table>
</form>
<hr>
<?php
if(isset($_POST['btnHuur']))
{?>
<table>
<th>
<h2>Toegevoegde film:</h2>
</th>
<?php
if(isset($_POST['btnHuur']))
{
?>
<tr>
<td>
<?php echo 'Film: '; ?>
</td>
<td>
<?php echo $_POST['txtFilm']; ?>
</td>
</tr>
<tr>
<td>
<?php echo 'Genre: '; ?>
</td>
<td>
<?php echo $_POST['Genre']; ?>
</td>
</tr>
<tr>
<td>
<?php echo 'Film omschrijving: '; ?>
</td>
<td>
<?php echo $_POST['txtFilmomschrijving'];?>
</td>
</tr>
<tr>
<td>
<?php echo 'Datum van uitkomst: ';?>
</td>
<td>
<?php echo $_POST['uitkomstdate']; ?>
</td>
</tr>
<tr>
<td>
<?php echo 'Datum uit bioscoop: ';?>
</td>
<td>
<?php echo $_POST['BiosDate']; ?>
</td>
</tr>
<tr>
<td>
<?php echo 'Film draai dagen: ';?>
</td>
<td>
<?php
if(!empty($_POST['draaidag']))
{
foreach($_POST['draaidag']as$check)
{
echo " ".$check;
$draaidag = " ".$check;
}
?>
</td>
</tr>
<tr>
<td>
<?php echo 'Film tijd dagen: ';?>
</td>
<td>
<?php
if(!empty($_POST['tijddagen']))
{
foreach($_POST['tijddagen']as$check)
{
echo " ".$check;
$tijddagen = " ".$check;
}
}
?>
</td>
</tr>
<tr>
<td>
<?php echo 'zaal: '; ?>
</td>
<td>
<?php echo $_POST['zaal']; ?>
</td>
</tr>
<?php
}else
{
echo "Geen";
}
include("loginDB.php");
?>
</br>
</br>
</br>
<?php
$film = $_POST['txtFilm'];
$genre = $_POST['Genre'];
$Filmomschrijving = $_POST['txtFilmomschrijving'];
$Datumvanuitkomst = $_POST['uitkomstdate'];//$_POST['selDag'] + '-' + $_POST['selMaand'] + '-' + $_POST['selJaar'];
$Datumuitbioscoop = $_POST['BiosDate'];//$_POST['selDag'] + '-' + $_POST['selMaand'] + '-' + $_POST['selJaar'];
$Filmdraaidagen = $_POST['draaidag'];
$Filmtijddragen = $_POST['tijddagen'];
$Zaal = $_POST['zaal'];
?>
<tr></tr>
<tr>
<td>
<?php
if($film && $genre && $Filmomschrijving && $Datumvanuitkomst && $Filmdraaidagen && $Filmtijddragen && $Zaal)
{
$query = "INSERT INTO films VALUES (0, '$film', '$genre', '$Filmomschrijving', '$Datumvanuitkomst', '$Datumuitbioscoop', '$Filmdraaidagen', '$Filmtijddragen', '$Zaal')";
mysqli_query($db, $query);
echo "Bestelling voltooid!";
}
}
?>
</td>
</tr>
</table>
<hr>
<?php } ?>
</body>
</center>
</html>
There is some mistake in your Php Code,
Html You had define name as Array (draaidag[] && tijddagen[])
<tr>
<td>Film draai dagen: </td>
<td>
<input type="checkbox" value="Maandag" name="draaidag[]">Maandag
<input type="checkbox" value="Dinsdag" name="draaidag[]">Dinsdag
<input type="checkbox" value="Woensdag" name="draaidag[]">Woensdag
<input type="checkbox" value="Donderdag" name="draaidag[]">Donderdag
<input type="checkbox" value="Vrijdag" name="draaidag[]">Vrijdag
<input type="checkbox" value="Zaterdag" name="draaidag[]">Zaterdag
<input type="checkbox" value="Zondag" name="draaidag[]">Zondag
</td>
</tr>
<tr>
<td>Film tijd dagen: </td>
<td>
<input type="checkbox" value="12uur" name="tijddagen[]">12:00
<input type="checkbox" value="14uur" name="tijddagen[]">14:00
<input type="checkbox" value="16uur" name="tijddagen[]">16:00
<input type="checkbox" value="18uur" name="tijddagen[]">18:00
<input type="checkbox" value="20uur" name="tijddagen[]">20:00
<input type="checkbox" value="22uur" name="tijddagen[]">22:00
<input type="checkbox" value="24uur" name="tijddagen[]">24:00
</td>
</tr>
You need to use implode() while accessing from $_POST. to convert it into string.
$Filmdraaidagen = implode("," ,$_POST['draaidag']);
$Filmtijddragen = implode(",",$_POST['tijddagen']);
Related
I use jQuery and PHP for seeing the quantity (Inventory) of a product in the database.
index.php code
<table>
<tr style="background-color:black;color: #fff;text-align: center;">
<td style="width:30%">name</td>
<td style="width:30%">qty</td>
</tr>
<tr>
<td>
<select name="jens_id[]" id="jens_id" required="" >
<option ></option>
<option >1</option>
<option >2</option>
</select>
</td>
<td>
<span class="contentsr" id="contentsr" ></span></td>
</tr>
<tr>
<td>
<select name="jens_id[]" id="jens_id" required="" >
<option ></option>
<option >1</option>
<option >2</option>
</select>
</td>
<td>
<span class="contentsr" id="contentsr" ></span></td>
</tr>
<tr>
<td colspan="8">
<input style="margin-right: 44%" type="submit" id="sumbit" onclick="calc(this) findTotal() allfees()" name="submit" value="submit"/>
</td>
</tr>
</table>
and mojodi_test code is this:
<?php include 'db/db.php'; ?>
<script type="text/javascript">
$(document).ready(function(){
$('#jens_id').change(function() {
if($(this).val() !=''){
$.get('mojodi_data.php',{whats: $(this).val()}, function(data) {
$('#contentsr').html(data);
});
}
});
});
</script>
<?php
if(isset($_GET['whats'] )){
$ids = $_GET['whats'];
$sql=$db->query("SELECT * FROM anbar WHERE jens_id='$ids'");
while($row=$sql->fetch()){
$mojodiha= ($row['kharid'] - $row['forosh']); ?>
<td hidden="" > <input hidden="" name="mojodi" type="text" value="<?php echo $mojodiha ?>" /></td>
<?php echo $mojodiha; ?>qty
<?php } } ?>
This code works for the first row, but not afterwards. other rows qty is empty and only shows the first row's quantity.
I want to insert the checkbox values without submit button but i cant get my checkbox values on my jquery code please get me over this problem which jquery function i have to use to get my values i'm new this script
<?php
date_default_timezone_set('Asia/Kolkata');
$a=date('H');
$b=8;$c=15;
if($b<$a&&$a<=$c)
{
$status='check="unchecked"';
}
else
{
$status = 'disabled="disabled"';
}
?>
<form >
<div align="center">
<table>
<tr>
<td>
<p>S.NO</p>
</td>
<td>
<p>Check Box</p>
</td>
<td>
<p>Activity Name</p>
</td>
</tr>
<tr>
<td>
1
</td>
<td>
<input type="checkbox" class="get_value" value="Bod1" <?php echo $status ?> />
</td>
<td>
<label for="Bod1">BOD1 </label>
</td>
</tr>
<tr>
<td>
2
</td>
<td>
<input type="checkbox" class="get_value"value="Bod2"<?php echo $status ?> />
</td>
<td>
<label for="Bod2">BOD2 </label>
</td>
</tr>
<tr>
<td>
3
</td>
<td>
<input type="checkbox" class="get_value" value="Bod3"<?php echo $status ?>/>
</td>
<td>
<label for="Bod3">BOD3</label>
</td>
</tr>
<tr>
<td>
4
</td>
<td>
<input type="checkbox" class="get_value" value="Bod4" <?php echo $status ?>/>
</td>
<td>
<label for="Bod4">BOD4 </label>
</td>
</tr>
<tr>
<td>
5
</td>
<td>
<input type="checkbox" class="get_value" value="Bod5" <?php echo $status ?> />
</td>
<td>
<label for="Bod5">BOD5 </label>
</td>
</tr>
</div>
</div>
</form>
<script>
$(document).ready( function () {
var languages=[];
//$.each($("input[name='checklist[]']:checked"), function(){
/ alert($(this).val());
// $("input[name='checklist[]']").each( function () {
var checkedvalue=$('.check_list:checked').val();
var checkedvalue=null;
var inputelements=document.getelementbyclassname('check_list');
for(var i=0;inputelements[i];i++){
if(inputelements[i].checked){
checkedvalue=inputelements[i].value;
});
checkedvalue=checkedvalue.toString();
$.ajax({
url:"dummyeodcheckbox.php";
type:"post"
data:{languages:languages};
success:function(data){
var result=result.data;
alert("function called successfully");
}
});
});
});
</script>
check this , hope it will help you. this is your html code
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form method="post" name="form1">
<input type="checkbox" name="checkboxList[]" value="1">value1</input>
<input type="checkbox" name="checkboxList[]" value="2">value2</input>
<input type="checkbox" name="checkboxList[]" value="3">value3</input>
</form>
<script>
$("input[type=checkbox]").on("change", function () {
var ids = [];
$('input[type=checkbox]:checked').each(function () {
ids.push($(this).val());
});
$.ajax({
url: "test.php",
type: "POST",
async: true,
cache: false,
data: ({value: ids}),
dataType: "text",
success: function (data) {
alert(data)
}
});
});
</script>
then create test.php file
<?php
print_r($_POST['value']);
?>
in test.php file make your action.
I am trying to get a filter working for a table. What I would like is checkboxes to filter (hide) rows based on whether they're checked or not and if the value is present in the table cell. I have it somewhat working, but it will only sort one of the checkboxes. Also, if there are multiple values in the table cell being filtered, that row is hidden. Thoughts? Thank you in advance for any help. I'm really struggling with this for some reason!
Here is the code I have been using:
$("input:checkbox").click(function () {
var showAll = true;
$('tr').not('.first').hide();
$('input[type=checkbox]').each(function () {
if ($(this)[0].checked) {
showAll = false;
var status = $(this).attr('rel');
var value = $(this).val();
$('td.' + 'status' + '[rel="' + value + '"]').parent('tr').show();
}
});
if(showAll){
$('tr').show();
}
});
The markup is as follows (please excuse some messiness, its Wordpress)
<div class="grants-filter">
<h3 class="filter-title">Filter Scholarships</h3><br/>
<h3>Year of Study:</h3>
<input type="checkbox" name="chx" rel="status" value="Freshman">Freshman
<input type="checkbox" name="chx" rel="status" value="Sophmore">Sophmore
<input type="checkbox" name="chx" rel="status" value="Junior">Junior
<input type="checkbox" name="chx" rel="status" value="Senior">Senior
<br/><br/><h3>Duration:</h3>
<input type="checkbox" rel="duration" value="Summer">Summer
<input type="checkbox" rel="duration" value="Semester">Semester
<input type="checkbox" rel="duration" value="Full Year or More">Full Year or More
</div>
<div class="grants-listing">
<table border="1" id="table" class="grants-table">
<thead>
<tr class="first">
<th>Title</th>
<th>Description</th>
<th>Field</th>
<th>Duration</th>
<th>Year of Study</th>
<th>Other</th>
<th>Procedure</th>
<th>URL</th>
</tr>
</thead>
<tbody>
<?php
$grargs = array ( 'post_type' => 'scholarship');
$grant_query = new WP_Query( $grargs );
while ( $grant_query -> have_posts() ):
$grant_query -> the_post(); ?>
<tr class="grant-detail">
<td>
<?php the_title(); ?>
</td>
<td><?php echo wp_trim_words(get_the_content(), 25 ); ?></td>
<td class="fields" rel="<?php echo get_field('fields'); ?>"><?php echo the_field('fields'); ?></td>
<td class="duration" rel="<?php echo the_field('desired_duration'); ?>"><?php echo the_field('desired_duration'); ?></td>
<td class="status" rel="<?php echo the_field('year-of-study'); ?>"><?php echo the_field('year-of-study'); ?></td>
<td class="other" rel="<?php echo the_field('other'); ?>"><?php echo the_field('other'); ?></td>
<td class="procedure" rel="<?php echo the_field('procedure'); ?>"><?php echo the_field('procedure'); ?></td>
<td class="url"><?php echo get_field('url'); ?></td>
</tr>
<?php endwhile;
wp_reset_postdata(); //reset the first query
?>
</tbody>
</table>
As I think you just are calling the first checkbox [0]
if ($(this)[0].checked) {
call all by inserting someting like
$('input[type=checkbox]').each(function () {
if (this.checked) {
console.log($(this).val());
}
});
Your code works fine, here is a simplified version
$("input:checkbox").click(function() {
var showAll = true;
$('tr').not('.first').hide();
$('input:checkbox:checked').each(function() {
showAll = false;
var status = $(this).attr('rel');
var value = $(this).val();
$('td.' + 'status' + '[rel="' + value + '"]').parent('tr').show();
});
if (showAll) {
$('tr').show();
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="grants-filter">
<h3 class="filter-title">Filter Scholarships</h3>
<br/>
<h3>Year of Study:</h3>
<input type="checkbox" name="chx" rel="status" value="Freshman">Freshman
<input type="checkbox" name="chx" rel="status" value="Sophmore">Sophmore
<input type="checkbox" name="chx" rel="status" value="Junior">Junior
<input type="checkbox" name="chx" rel="status" value="Senior">Senior
</div>
<div class="grants-listing">
<table border="1" id="table" class="grants-table">
<thead>
<tr class="first">
<th>Title</th>
<th>Description</th>
<th>Fields</th>
<th>Status</th>
<th>Procedure</th>
</tr>
</thead>
<tbody>
<tr class="grant-detail">
<td>
Name
</td>
<td>Description</td>
<td class="fields" rel="Freshman">Freshman</td>
<td class="status" rel="Freshman">Freshman</td>
<td class="procedure" rel="Freshman">Freshman</td>
</tr>
<tr class="grant-detail">
<td>
Name
</td>
<td>Description</td>
<td class="fields" rel="Sophmore">Sopho</td>
<td class="status" rel="Sophmore">Sopho</td>
<td class="procedure" rel="Sophmore">Sopho</td>
</tr>
<tr class="grant-detail">
<td>
Name
</td>
<td>Description</td>
<td class="fields" rel="Junior">Junior</td>
<td class="status" rel="Junior">Junior</td>
<td class="procedure" rel="Junior">Junior</td>
</tr>
</tbody>
</table>
I have my table named i_table with columns:
id name req_qty req_date rcv_qty rec_date
1 metal 1 2014-03-04
2 spring 5 2014-03-04
in my html/php:
<form action="insert.php" method="post">
<?php $resource2=mysql_query("SELECT * FROM i_table",$con);
while($result2=mysql_fetch_array($resource2))
{
?>
<table>
<tr>
<td>
<input type="text" name="id" value="<?php echo $result2['id'];?>"/>
</td>
</tr>
<tr>
<td>
<input type="text" name="name" value="<?php echo $result2['name'];?>"/>
</td>
</tr>
<tr>
<td>
<input type="text" name="rcv[]" value="" />
</td>
</tr>
<tr>
<td>
<input type="date" name="rcv_date[]" value="" />
</td>
</tr>
</table>
<?php };?>
</form>
how can I insert in multiple arrays from an input according to their unique ID from db? pls help me here... huhu
In your form, add the id as the key -
<form action="insert.php" method="post">
<?php $resource2=mysql_query("SELECT * FROM i_table",$con);
while($result2=mysql_fetch_array($resource2))
{
?>
<table>
<tr>
<td>
<input type="text" name="id[<?php echo $result2['id'];?>]" value="<?php echo $result2['id'];?>"/>
</td>
</tr>
<tr>
<td>
<input type="text" name="name[<?php echo $result2['id'];?>]" value="<?php echo $result2['name'];?>"/>
</td>
</tr>
<tr>
<td>
<input type="text" name="rcv[<?php echo $result2['id'];?>]" value="" />
</td>
</tr>
<tr>
<td>
<input type="date" name="rcv_date[<?php echo $result2['id'];?>]" value="" />
</td>
</tr>
</table>
<?php };?>
</form>
Then on your insert.php where you post your form, get the id in your foreach -
<?php
if(isset($_POST['id'])){
foreach($_POST['id'] as $id=>$value){
$sql = "UPDATE `i_table` SET `name` = '".$_POST['name'][$id]."', `rcv_qty` = '".$_POST['rcv'][$id]."', `rec_date` = '".$_POST['name'][$id]."' WHERE `id` = ".$id."";
mysql_query($sql,$con);
}
}
?>
note the foreach() is just an example. You will want to sanitize your data before inserting/updating to prevent sql injection. see How can I prevent SQL injection in PHP?
I am fetching data from database , for each of row data fetched I am creating a radio button against the row. The details of a land-sites are fetched here.
I have a form for booking these land sites, which takes land-site details and name and email of user.
So when a user selects a radio button, the details of land-site should be automatically filled in the form, How to achieve this.
<html>
<body>
<?php
$phase=$_GET["q"];
$sql ="select id, phase,size, facing, sply, status from plot where status='avail' and phase='$phase'";
$ret=mysql_query($sql, $connect);
echo "<form>";
echo"<div style='overflow-y:scroll;height:200px;float:left;' ><table border=1 >
<tr>
<td>select </td><td>phase</td> <td>site no.</td> <td>plot-size</td> <td>face</td> <td>sply</td> <td>status</td>
</tr>" ;
while($row = mysql_fetch_array($ret, MYSQL_ASSOC))
{
echo "<tr>".
"<td><input type='radio' name='book' value='book' onClick=\"whichForm('send_to_one');\" /></td>".
"<td>{$row['phase']} </td>".
"<td>{$row['id']} </td>".
"<td> {$row['size']} </td>".
"<td> {$row['facing']} </td>".
"<td>{$row['sply']} </td> ".
"<td>{$row['status']} </td> ".
"</tr>";
}
echo "</table></div>";
mysql_close($connect);
?>
<div id="send_to_one" style="float:right;padding:30px">
<table>
<tr>
<td>Name :</td><td><input type="text" name="name" value=""/></td>
</tr>
<tr>
<td>Mobile:</td><td><input type="text" name="mobile" value="" /></td>
</tr>
<tr>
<td>Email :</td> <td><input type="text" name="email" value="" /></td>
</tr>
<tr>
<td>Phase : </td> <td><select name="phase" id="phase">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select></td>
</tr>
<tr>
<td>Site :</td> <td> <input type="text" name="site" value="" id="site" /></td>
</tr>
<!--
<tr><td><span id="status"></span></td></tr>
-->
<tr>
<td><input type="radio" name="status" value="blocked" class="radioBtn" onclick="advance.disabled=true" /> block</td>
<td><input type="radio" name="status" value="booked" class="radioBtn" onclick="advance.disabled=false" /> book </td>
</tr>
<tr>
<td>Advance paid </td> <td><input type="text" name="advance" value="" id="textField" /></td>
</tr>
<tr><td><input type="submit" value="submit" /></td> <td> <input type="reset" value="clear all" /> </td></tr>
</table>
<?php echo "</form>"; ?>
</div>
<!-- div ends here -->
</body>
</html>