Forum Moderators: coopster

Message Too Old, No Replies

Help with PHP form

looking for php script

         

esk19

7:43 pm on Jan 7, 2004 (gmt 0)



I would like to allow users to post a response to articles on the website. Under the article I want to create a simple for (which I know how to do) that allows a user to submit their name, a title for their post, and a response.

Then I would like all the responses to be posted on the same page, just below the submit form.

I can run PHP and I have a mysql database.

I think I use something like method=post action=somephpscript.php

but I don't know what script to use, and I don't know how to get the info to print back onto the html page.

Can anyone help out?

Thanks!
Emily.

coopster

2:41 pm on Jan 8, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, esk19!

You will probably want to write your own script in this case, and you came to the right place ;)
There are a number of ways to accomplish what you want to do and I'll show you some basics here and follow-up with some recommended reading. I think a working example will be best. Cut and paste the following code into a text editor, save the file with a .php extension and FTP the script to your server. Then just open the script in your web browser to test it:

form_sample.php


<html><head><title>Sample</title></head><body>
<form action="<?php print [php.net] $_SERVER [php.net]['PHP_SELF'];?>" method="post">
Name: <input type="text" name="name" /><br /><br />
Title: <input type="text" name="title" /><br /><br />
Response: <input type="text" name="response" size="50"
value="Check\Whacks and apostrophe's" /><br /><br />
<input type="submit" name="Submit" value="Submit" />
</form>
<?php
if ($_POST['Submit']) {
$name = $_REQUEST['name'];
$title = $_REQUEST['title'];
$response = $_REQUEST['response'];
print '$name is ' . $name . '<br />';
print '$title is ' . $title . '<br />';
print '$response is ' . $response . '<br />';
print 'stripslashes($name) is ' . stripslashes [php.net]($name) . '<br />';
print 'stripslashes($title) is ' . stripslashes($title) . '<br />';
print 'stripslashes($response) is ' . stripslashes($response) . '<br />';
}
?>
</body></html>

The stripslashes function is something that you may or may not have to use based on some of the PHP configuration settings regarding what is called Magic Quotes [webmasterworld.com]! The sample provided here along with the respected links should give you a good understanding how to get started with forms and PHP. Once you've got a fairly good handle on this you'll be ready to learn about the Basics of extracting data from MySQL using PHP [webmasterworld.com].