Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Kindly explain three multiple text box value want to insert into mysql database
<input type="text" name="name1[]" />
<input type="text" name="name2[]" />
<input type="text" name="name3[]" />
i want post this values via loop and insert into mysql
kindly explain below single foreach loop is possible
foreach($_POST['name'],$_POST['name2'],$_POST['name3'] as $key => $value)
{
INSERT INTO (name1, name2, name3)
}
Ok, I answer the question the way I understand it. Here is an example of something similar in logic:
HTML:
<input type="checkbox" name="some_name[]" value="value1" />
<input type="checkbox" name="some_name[]" value="value2" />
<input type="checkbox" name="some_name[]" value="value3" />
This way you form an array of $_POST['some_name']
And then in php you loop through it and insert the data in a MySQL table with a single column name
foreach($_POST['some_name'] as $name)
{
mysqli_query($link, "INSERT INTO `table` VALUES `name` = '$name'");
}
Of cource this is just a descriptive example of what I consider to be the question (as it is not very clear)
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed last month.
Improve this question
I need to make a text that can be edited by user but in some parts I need to make static text for example the date and ....,how to make it ,plz can anyone help me
I have tried the normal input but it did not work as I expected
you can define editable part in page for each section, after type in input with js concatenation all text in main input, and in submit just pass main text to back-end.
like bellow:
<input type="hidden" name="text" id="main-text-id">
<input class="text-part" type="text">
<input class="text-part" type="text">
<input class="text-part" type="hidden"> <!--static part-->
<input class="text-part" type="text">
<input class="text-part" type="hidden"> <!--static part-->
...
and your script :
<script>
const mainText = document.getElementById('main-text-id');
const inputs = document.querySelectorAll('.text-part');
inputs.forEach(input => {
input.addEventListener('input', () => {
mainText.value = Array.from(inputs).map(input => input.value).join(' ');
});
});
</script>
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have a page that is receiving an array from $_GET. Lets say it has 3 values in $_GET['types'] containing: 'good', 'bad', and 'ugly'. Now on this page I am setting up a form and I need to pass this array into the form through an input. Maybe this short piece of code can help demonstrate what I'm trying to do
<form action="dosomething.php" method="get">
<input name="types[]" value="<?php echo $_GET['types']; ?>" />
</form>
How can I accomplish this?
Arrays in string context are simply the literal word Array. You say $_GET['types'] is an array, therefore you're generating this html:
<input ... value="Array">
You should have
<input name="types[]" value="<?php echo implode(',', $_GET['types']); ?>" />
instead.
But note that you'll end up with this html:
<input ... value="foo,bar,baz">
and this in $_GET on the server when the form's submitted:
$_GET['types'] = array(
0 => 'foo,bar,baz'
);
If you want those values as SEPARATE array entries, you'll have to submit multiple input fields:
<input name="types[]" value="foo">
<input name="types[]" value="bar">
etc...
which will give you
$_GET['types'] = array(
0 => 'foo',
1 => 'bar'
etc...
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
How do I Get This HTML 5 Form To Give PHP The Input Data Then Display It On The Screen. I want to collect data in a form. Convert it into a php variable and then echo it out in a way that I can read it.
<form>
First name:<br>
<input type="text" name="name">
</form>
<body>
<pre>
<?php
$taco = htmlspecialchars($_POST["name"]) . '!';
$taco = $_POST;
echo $taco;
?>
</pre>
</body
</html>
How about the following:
<?php
if($_POST) { // check if the page is posted not with a $_GET
foreach($_POST as $field => $value) { // Foreach field
$value = strip_tags($value); // Strip html tags (you can add more)
echo 'Field: '.$field.' has value: '.$value.'<br>'; // output
}
}
?>
<form action="" method="post">
First name: <input type="text" name="first_name">
<input type="submit" value="Display">
</form>
Just put it all in one php file. You can add as many fields as you want.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
i have an if statement as follows
if($_POST['remember']=="on")
i want to know if this is the correct syntax for checking if the checkbox is checked or unchecked?
This code will help you
<input type="checkbox" name="checkbx" <?php if(isset($_POST['remember'])=="on") echo "checked";?> />
OR
<?php if(isset($_POST['remember'])=="on") {?>
<input type="checkbox" name="checkbx" checked="checked" />
<?php }else {?>
<input type="checkbox" name="checkbx" />
<?php }?>
simple check of isset
if(isset($_POST['remember']) && $_POST['remember']=="on")
{
// checkbox remember is checked
}
else
{
// checkbox remember is not checked
}
Use
if (isset($_POST['remember'])) {
// checked
} else {
not checked
}
<input type="checkbox" name="remember" value="YES" />
$remember= ($_POST['remember'] == 'YES')?'YES':'NO';
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
i am crated form,
<td>
<input type="checkbox" name="mode[]" id="mode" value="sweet" />
Sweet<br />
<input type="checkbox" name="mode[]" id="mode" value=" sour" />
Sour<br />
<input type="checkbox" name="mode[]" id="mode" value=" creamy" />
Creamy<br />
<input type="checkbox" name="mode[]" id="mode" value="bland" />
Bland<br />
</td>
and php code is,
for ($i=0; $i<sizeof($mode); $i++)
{
$emode = mysql_real_escape_string($mode[$i]);
$query =<<<EOF
INSERT INTO frutesdetails(fruitname,fruitcolor,seasonfrom,seasonto,fruitetaste,fruitbenefit)
VALUES ('{$fruitname}', '{$category}',
'{$startdate}','{$enddate}','{$emode}','{$fruitbenefit}')
EOF;
$insertresults = mysql_query($query) or die(mysql_error());
}
i got all the record but not in one recod ,if i check 2 check box i get two records in two different row not in single row
If you want it all stored in one record, first remove the for() loop. Then you have a couple options take your pick:
$emode = mysql_real_escape_string(json_encode($mode));
$emode = mysql_real_escape_string(serialize($mode));
$emode = mysql_real_escape_string(implode(',',$mode));
Then you just have decode on the way out.
If I understand your question correctly, your problem is that
your PHP code inserts one row into the database for each checkbox selected, but
you want it to insert one row containing all checkbox selections.
But that's exactly what you're doing in your code - you're looping over $mode and executing your mysql_query call for each element in $mode. If you want all selections in the same row, then let your $emode be some representation of all selections instead of just one of them, and get rid of that for loop.