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 3 years ago.
Improve this question
I want to make a form that after i click submit,it will generate .sql file to insert the value to MySQL database. so I can transfer the value to other server real time.
How to generate SQL file that contain a script to insert value from input form?
we have a lot of outlet, usually we use web app from browser to input database, but there is a problem when the connection is down, so we tried to make the web app running from outlet server and transfer all the input to HO ftp server.
I already create batch file to transfer the file to ftp and will use cronjob to run it automatically, what left is I want to generate SQL file to insert the input data, so I can import the SQL to HO database from ftp server.
Here is the example:
<html>
<body>
<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br> E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
</body>
</html>
It will show name, email, text box and submit button. I want to generate SQL file that insert name and email input when I click submit button. not generate SQL file from MySQL.
Honestly I think this is a bad solution for security reason. FTP is a breakable protocol, but anyway: you can do this by calling the PHP method:
file_put_contents();
So after compose the SQL string to store into the file, you can do something like this:
$dir = 'folderPATH';
$dataToStore = "INSERT INTO table_name (name, email, ...) VALUES ('$name', '$email');"
file_put_contents($dir, $dataToStore);
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I have this project in Laravel and I have this list of emails in a html table ,each row has a checkbox, if I check X checkboxes I want to send a email to all of them.
Not worried about the email procedure but it will be in a php file, what I dont know is how to do the logic, should I encapsulate all of the table in a form with the action going to the php file or should I control this with a jquery ajax call.
Encapsulate the checkbox with a form :
<form action="script.php" method="post">
<input type="checkbox" name="mailadre#gmail.com">
<input type="checkbox" name="otheradre#yahoo.fr">
....
<input type="submit" value="Send Request">
</from>
Only the checked checkboxes will be send by the browser and receive by php. In fact on the php side, on script.php $_POST will be an array containing the checked mail adresses :)
EDIT :
If you don't want to reload the page and get acualized data you will have to use javascript with ajax calls.
You have to include a js script in your html that fetch a php page every x seconds to get the actual amount of orders and replace the value in the browser. This php page job will be only to display this number.
Ajax calls are executed after the browser get the page from the server, they are executed by the browser. As soon as PHP server send the page, it care no more, the only way to interact with it is by the client browser, in this exemple with an Ajax call to an url on the server that will repond only with the total amount of order. So in background of the browser it will require actualized datas to the PHP server.
To be honest JSON is probably the way you should go to be able to send total amount of order + all kind of other actualized infos to include in your page.
It would give you for exemple something like that {totalOrder = 142, lastConnection = "Jean-Philippe", LastOrderDate= "2020-11-18"} if you encode this array on the PHP server side:
$result = [ "totalOrder " => 142,
"lastConnection " => "Jean-Philippe",
"LastOrderDate"=> "2020-11-18"];
header('Content-Type: application/json');
echo json_encode($result);
Then you can easily replace content in your HTML page in javascript with this JSON response from your PHP server.
See detailed exemple here :https://makitweb.com/return-json-response-ajax-using-jquery-php/
Have a nice day.
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 6 years ago.
Improve this question
Okay my question is, how can I request from user when clicks on button to enter his email and receive message with link of my web page?
You cannot do this with just HTML or even with just HTML and javascript.
To send an email, you need to use a back-end script, which is usually PHP (on most shared hosting servers) or asp/.Net (on Microsoft web servers)
Javascript has been made much easier with the jQuery add-in. Here is a link to some free videos about how to use jQuery. Basically, jQuery cuts typing dramatically and makes javascript much easier. All you need to use jQuery is to include the jQuery library between script tags -- place that code just above the closing </body> tag.
Here is some example code using jQuery, just to show what it would look like. This example:
* asks user for email address (but does not validate what they enter)
* creates a form with an element named eml that contains what the user typed
* submits the form to a backend PHP file called sendcontact.php. It is up to you to also write sendcontact.php
$(document).ready(function(){
$('#mybutt').click(function(){
var em = prompt('Enter your email');
$('body').append('<form id="yrForm" action="sendcontact.php" method="post"><input name="eml" value="' +em+ '" ></form>');
$('#yrForm').submit();
});
}); //END document.ready
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<button id="mybutt">Click Me</button>
Now, you need to have another back-end file, sendcontact.php that will receive the data sent via the form, and send an email. Here is an overview of how to do that:
http://tangledindesign.com/how-to-create-a-contact-form-using-html5-css3-and-php/
(You can ignore the entire first part of the above tutorial that deals with creating the contact form. You only need to read about how to receive the information in PHP and send the email.)
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 7 years ago.
Improve this question
I am trying to look for a way to update a column.
Like here:
Database: temptestsite
Table: firstsection
then there is username, heading etc (not a log in type situation).
Say user sends in the username and I want them to be able to change it. How does one UPDATE this specific column. Anything I have tried so far from w3schools inserts a new column. Could someone please make an example of how to do this with PHP?
Like let there be a text box and then a button or a hyperlink next to it saying "update" or "change", whatever user types in that text box, gets updated in the "usernames" column in the database.
Your general process will be:
Check if post data is available
If it is, execute a mysql update call
Build the form
Here is some skeleton code:
<?php
$link = mysqli_connect("myhost","myuser","mypassw","mybd");
$id = $_GET['id'];
if (!empty($_POST)) {
$link->query("UPDATE users SET username = '".$link->real_escape_string($_POST['username'])."' WHERE id = '".$link->real_escape_string($id)."'");
}
$user = mysqli_fetch_assoc($link->query("SELECT * FROM users WHERE id = '".$link->real_escape_string($id)."'"));
?>
<form method="POST">
<input type="text" name="username" value="<?php echo $user['username'] ?>"/>
<input type="submit" value="Update"/>
</form>
There is two update method in rest system,
One of them is PUT , other one is PATCH,
Most frameworks make that request via hidden _method attr, like in laravel
<form method="POST">
<input type="hidden" name="_method" value="PUT"/>
<input type="text" name="column"/>
<input type="submit" value="Update"/>
</form>
PUT is using for changing entire column,
PATCH is just patching as you can understand,
First understand and manage what you really need, then watch & read about them.
As an answer maxhud is explained code version of it.
But it is not the good way to make it with post request.
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
Similar to how you create a post in wordpress or even ask a question on this very website.
I want to know how to create a page by just filling out a form?
Here's what I know:
-I know how to make an html form
-I know how to place data in a database and take it out
-I know some php
What I don't know is how to to tie all of these things together. Please be as specific as possible and if you know of a tutorial on how to do this or you have the time to make a small example I would be very very grateful.
Thank you in advance for your time :-)
EDIT: To provide more details
I want to send data from a form (even a few text inputs would be enough) and for them to be placed in a page where I can display them.
And also that page should have an unique identifier so it gets stored similar to the questions on stack overflow where there is www.stackoverflow.com/posts/'identifiernumber'
And I would always to go back to that information provided I access the link which I assumed will be stored in the database.
Wordpress uses wysiwyg this is used to convert normal text into html code you can find jquery plugins for it.After user has entered the content of the page and hits submit. Wordpress directly stores the content in the database in HTML FORMAT . Now all it does is echo out the content stored in the database.
Now for the identifier , it should point out to the primary key of the database row where the content is stored. Wordpress stores a unique url as the identifier like the questions you asked is How to create a page using a form? php/html it will store it as how-to-create-a-page-using-a-form-php-html . This is then put in the href attribute of <a> tag , on click of this unique identifier it echo out the content of that row.
All you have to do now is make a form and textarea , apply the wysiwyg plugin on the textarea . Then onsubmit store the data in the database and also creating a unique identifier for it.
You question now is how to pass the identifier in the URL?
First you must know how to pass a variable in the URL and then capture it in the required place eg : www.yourwebsite.com?identifier=something and to make this a link on you website
Something
Once you have mastered this you can then study a concept called MOD REWRITE and in layman term for this is called clean URL or SEO URL . There are many blogs and methods of achieving this goal. You can google MOD REWRITE and SEO URL.
Create your website theme
on first page create form like you want
concept is like registration form and second page is edit profile
now what you stored in database from registration form
now echo in your edit profile form
for example username in database can be viewed in edit profile form
select * FROM registrationtable WHERE userid='$userid'
then store values in variables like for example
while ($query = mysql_fetch_array($request))
{
$username = $query['username'];
}
<input type="text" name="username" value="<?php echo $username; ?>"/>
p.s dont use mysql better options are mysqli and PDO
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 9 years ago.
Improve this question
I am getting confused as I read various posts about the typical task I am trying to perform, no doubt countless others have done it before. So at this point in 2013 what is the best practice solution to achieve the following:
I have an html page which asks the user for a number of values, x1, x2, .....xn.
There may be 10 to 20 such inputs. As such I don't want them to be lost or to have to be re-inputted again for whatever reason.
perform calculations based on user inputs then output the results (eg. y1, y2, y3..y5).
As suggested by some of the posts here, I tried "echo" (for PHP), that works fine. However, it shows the results in a new page so the user input is no longer visible.
I want the user to see both - their input and the resultant. That way they can print if they want to and see all info on one page.
I prefer to use "basic" technologies, ie. technologies that most users can use, that they don't have to click OK on some warning, change some setting on their browser, accept some thing or other etc..
Thanks in advance!
Create inputs with html.
Choose between reloading page or AJAX
If you choose reloading then use
code:
<form action="nextfile.php" method="POST">
<input type="text" value="" name="y1" />
<input type="text" value="" name="y2" />
<input type="submit" value="calc me" name="submit" />
</form>
Then in nextfile.php you need get values with $_POST and if you want them to be saved use $_SESSION
For example
<?php
session_start();
if(isset($_POST['y1']) && isset($_POST['y2']))
{
$_SESSION['res'] = (int)$_POST['y1'] * (int)$_POST['y2'];
}
The code above will perform calculation on two inputs with name y1 and y2 and save them in session.
If you want AJAX then you need to visit this page and see examples
You should think of JavaScript solution because it will fit your needs and no server code is needed.
The simplest way is to submit the form to the same page and repopulate the input fields:
// calc.php
<?php
if (isset($_POST['foo'])) {
echo 'Result: ', $_POST['foo'] + 1;
}
?>
<form action="calc.php" ...>
<input name="foo" value="<?php if (isset($_POST['foo'])) echo htmlspecialchars($_POST['foo']); ?>">
...
</form>
The more modern version would be to submit the calculations via AJAX and populate the result via Javascript without reloading the page.