I must say i´m a comeplete noobie, and got created a webpage with dreamweaver, and i´m ok with it.
But i have now created a post message field and the right .php file, but how do i link the two?
can´t seem to get the submit button to read my .php file. how do i link the two ?
do i setup the button as a submit button, or the function none and then write the code my self ?
Hope someone will be able to help... have been stuck at this for days now ....
4 Replies - 193 Views - Last Post: 22 February 2013 - 05:05 PM
#1
Help me get my submit button to activate my PHP form (Dreamweaver)
Posted 22 February 2013 - 02:33 AM
Replies To: Help me get my submit button to activate my PHP form (Dreamweaver)
#2
Re: Help me get my submit button to activate my PHP form (Dreamweaver)
Posted 22 February 2013 - 02:43 AM
#3
Re: Help me get my submit button to activate my PHP form (Dreamweaver)
Posted 22 February 2013 - 03:20 AM
now i´m just eaven more confused.. don´t both parts have to be on the server ?
i´m pretty sure, i have got it all right.
i got my table with the info, name, phonenumber and email. and i got the right php file, i downloaded it as a template and altered the info so it is the same as on the table. now i just need to link the two parts together somehow. but i have no idéa how to do that.
do i mention the .php file somewhere from the page with the table somewhere.
i´m pretty sure, i have got it all right.
i got my table with the info, name, phonenumber and email. and i got the right php file, i downloaded it as a template and altered the info so it is the same as on the table. now i just need to link the two parts together somehow. but i have no idéa how to do that.
do i mention the .php file somewhere from the page with the table somewhere.
#4
Re: Help me get my submit button to activate my PHP form (Dreamweaver)
Posted 22 February 2013 - 05:17 AM
the_wire_man, on 22 February 2013 - 11:20 AM, said:
now i´m just eaven more confused.. don´t both parts have to be on the server ?
that’s a completely different question. PHP, HTML and JS are *stored* on the server (and hence served *from* the server) but the are *executed* differently. PHP is *executed* on the server while HTML and JS are *executed* on the client.
#5
Re: Help me get my submit button to activate my PHP form (Dreamweaver)
Posted 22 February 2013 - 05:05 PM
Think about it like this. PHP lives on the server. Your browser neither knows nor cares that the HTML is being generated by PHP. All the browser cares about is receiving valid(ish) HTML, CSS and Javascript. That's what the browser needs to show you the page. Once the browser has received that from the server, PHP is no longer involved; it has done it's job and is out of the picture.
In order to get information from the user/browser to the server, you need the browser to send that information back to the server. PHP can not access the info from the browser unless the browser sends it. That's what <form> elements do; they collect info from the user and then when they are submitted they send that data to the PHP script referenced in the "action" parameter.
Once the browser has sent the info to the server, your PHP code can process that info using by looking into the $_POST array. Every <input name="myText"> element in the HTML form will be represented in PHP by a $_POST["myText"] element, where the "name" of the input element is the name of the element in PHP.
So, say for example that you want to allow visitors to post message on a user profile, you could add a form like this to the profile page:
Note that in this snippet, I am assuming that the PHP code generating this page has the ID of the user who's profile it's showing in a $userID variable. That will then be insert into the form via a <input type="hidden"> element, which will then be sent to the server when the form is submitted along with the rest of the form.
So, the "addComment.php" page can process this form by accessing the $_POST array, like so:
Do you get what I mean?
In order to get information from the user/browser to the server, you need the browser to send that information back to the server. PHP can not access the info from the browser unless the browser sends it. That's what <form> elements do; they collect info from the user and then when they are submitted they send that data to the PHP script referenced in the "action" parameter.
Once the browser has sent the info to the server, your PHP code can process that info using by looking into the $_POST array. Every <input name="myText"> element in the HTML form will be represented in PHP by a $_POST["myText"] element, where the "name" of the input element is the name of the element in PHP.
So, say for example that you want to allow visitors to post message on a user profile, you could add a form like this to the profile page:
<form action="addComment.php" method="post">
<input type="hidden" name="user_id" value="<?php echo $userID; ?>">
<textarea name="message"></textarea><br>
<input type="submit" value="Send Comment">
</form>
Note that in this snippet, I am assuming that the PHP code generating this page has the ID of the user who's profile it's showing in a $userID variable. That will then be insert into the form via a <input type="hidden"> element, which will then be sent to the server when the form is submitted along with the rest of the form.
So, the "addComment.php" page can process this form by accessing the $_POST array, like so:
<?php
if (!empty($_POST["user_id"]) && !empty($_POST["message"])) {
// Lets assume that the following function does the
// actual database stuff. I can't be bothered to do
// all that in this example :)/>
if (saveComment($_POST["user_id"], $_POST["message"])) {
// Success! Go back to the profile page.
header("Location: /profile.php?id=" . $_POST["user_id"]);
exit;
}
else {
// Error! Failed to save the comment. Show the user
// and error message, or something.
header("Location: /form_error.php");
exit;
}
}
Do you get what I mean?
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote




|