Updating sql data through PHP - php

Good day!
I am having a problem in showing the data that I need to Update.
For example: I have a field - NAME. And user input "John Travolta" on it and enter to save it in SQL. Then to update it, he will click the update and a textbox will appear with the name "John Travolta" with it.
The problem is I am only getting "John" and the "Travolta" does not appear on the text box.
My code is as follows:
<input name="event" type="text" id="event" size="69" value=<?php print stripslashes($row_array['event'])?>>
What can i do in order for the whole name to appear in the textbox?
Thank you in advance.

You need to put quotes before and after the PHP line so HTML can parse it as a string.
otherwise you will end with value=John Travolta when you want value="John Travolta"

Use that code:
<input name="event" type="text" id="event" size="69" value="<?php print stripslashes($row_array['event']);?>">

Related

PHP keep input type=date value after form submit

i want to keep my input type=date value after onchange form submit
Current HTML code
<input type="date" id="Date" name="Date" placeholder="Date" value=”<?php echo $_POST['Date'];?>” onchange="this.form.submit();">
So after onchange, I want the value of the date remain same. I tried many ways but it didn't work. Thanks for helping
Please check with this, I am seeing issue with quote as well in your HTML, so copy below code to see.
<input type="date" id="Date" name="Date" placeholder="Date" value="<?php echo isset($_REQUEST['Date'])?date("Y-m-d",strtotime($_REQUEST['Date'])):'';?>" onchange="this.form.submit();">
You're not using standard double quotes ", but a curly variant, which are not part of the HTML standard:
value=”<?php echo $_POST['Date'];?>”
Replacing those curly quotes by straight ones will fix your problem.

PHP - HTML - Get multiple checkbox value without making it become array

I have read through many questions and do my searches for hours, but i still cannot find the solution to what i exactly want.
<form method="POST">
<input type="checkbox" name="fruit" value="0" />No Preference
<input type="checkbox" name="fruit" value="1" />Apple
<input type="checkbox" name="fruit" value="2" />Orange
<input type="checkbox" name="fruit" value="3" />Banana
</form>
print_r($_POST);
I already did validation to checkbox value 0 to 1,2,3 so they will inverse and i did it using looping javascript search for the element name. The problem is, i have to use the element name without changing it become array name. (e.g Fruit => Fruit[] ). So i need to use this element name to retrieve all checked information inputted by the customer. I've seen this can be done in ASP, but i could not figure how they do as it's long time ago already.
My question is, could any one figure how to do this without changing the element name into array format (e.g Fruit => Fruit[] ) ? T.T
Any help will be appreciated. Thank you..
As you already figured, when you submit the same name multiple times, the latest one will overwrite former ones. A solution is to set up a hidden field
<input type="hidden" value="" name="foobar_as_array">
and use jQuery or plain JS to concat your values into that field on submit
<form ... onSubmit=$('#foobar_as_array').value(...concatenate them...);">
I changed the validation using this line :
var GenBox = eval("document.forms['SubmitSearchAll']['" + oCheckBox+"[]']");
and it helps me alot. Now it is solved.
Thanks everyone for contributing.

Inserting PHP variable into Html5 "Placeholder" attribute

I tried the following, and it shows an empty text area, the value isn't displayed:
<input type="textarea" class="class1" name="name1" placeholder="<?= $val1?>" />
Any thoughts on what should be done so it will work?
Update: It is now working, the value was empty, therefore text area didn't show anything. The code can be used safely.
<input type="textarea" class="class1" name="name1" placeholder="<?php echo $val1; ?>" />
There is no such input type attribute as textarea.
Do you mean:
<textarea class="class1" name="name1" placeholder="<?php echo $val1; ?>"></textarea>
if $val1 is not null, i think the problem is short tag (<?= ?>).
You can override this config, at the top of file, put this line to enable short tag:
ini_set('short_open_tag',1);
Make sure that $val1 actually contains a non-empty value. If it does, your code should create a non-empty placeholder attribute.
Check whether the variable is empty (as #Asaph suggested in his comment).
Entered a value and now it is working just fine.

two values for one name in input

I have one input (type radio) that I want to insert it 2 values, something like that:
<input type="radio" name="name" value1="value1" value2="value2" />
And after draw each value seperated with PHP.
There is a way to do it? (And no.. I dont want to insert input with type="hidden")
Thank you.
Well, not the way I would do it, but you could use a delimiter for your value(s)
<input type="radio" value="Value1|Value2" name="two_values" />
Then, in PHP, just list($value1,$value2) = explode('|', $_POST['two_values']);
EDIT
As #user387302 said, you would obviously be limited to not having any values containing your delimiter, for example value="One|PipedVariable|andAnother" would not work to extract two values of "One|PipedValue" and "andAnother"
Why not do:
<input type="radio" name="name" value="value1#value2" />
and then split on "#" (or any other symbol) server-side?
If I understand your question correctly, can you set the value of your radio to something like "value1-value2" and then in your php just seperate value1 from value2 with explode(). You could use any other seperator other than '-' too.
Edit
based on your exmaple:
<input type="radio" name="name" value="value1-value2"/>
Can't do it.
You need either a hidden input (which you say you don't want) or use value="value1,value2" and then explode in the PHP script.
Use this :
<input type="radio" name="name[]" value1="value1" />
<input type="radio" name="name[]" value1="value2" />
returns array

How to send multiple related values from my html form to server via $_POST?

I was going to use jQuery to clone the input field when I click a button to make another field, but I was thinking of doing:
Page One, Page Two, Page Three <- then send that as one $_POST to the server and have it take each page and break on the "," comma then for each insert in to my POSTS table.
Any idea on how I would do that? Would I use explode()? Then inside a foreach() run a query for each item in the field.
So if there were 5 pages typed in separated by commas, it would run five times using the foreach().
for each(){
EXECUTE SQL HERE
}
Does that sound like it would be the best way of going about it?
If you set the name attribute of the input element to the name of an array, e.g. foo[], you'll be able to access it as such when processing the $_POST vars, e.g.
<input name="foo[]" type="text"/>
<input name="foo[]" type="text"/>
becomes two iterations of:
foreach ($_POST['foo'] as $foo) {
// process $foo
}
explode and foreach sound good.
But as Click Upvote indicated: is it for pagination? 'cause then there could be a betetr way to achieve this.
You can do the following:
<input type="text" name="list[]" />
<input type="text" name="list[]" />
<input type="text" name="list[]" />
<input type="text" name="list[]" />
Everytime you need a new input box you can do
$(some_element).append( '<input type="text" name="list[]" />' );
or sth similar with jQuery.
Then you have an array instead of a single value in your PHP $_GET or $_POST variable. So you can use $_POST['list'] in foreach.
I was thinking, I can type in:
Home, Products, About, Contact
Into a input field, then my php can break it apart using the comma and insert each of those page titles in my PAGES table.
Run the SQL within the foreach.
Thoughts?

Categories