hello all: hope i am in the right place.
i am looking to build a comment type page on
our church website. i suppose it would be
similar to the one the comment section
on you tube. in all actuality it is a
testimony page where they may post
what is good in their lives.
i have some code written
but i'm not very good at it...just learning.
i have run across some very elaborate free
comment editors but they are too much for
our needs.
basically, all we need is a very simple script
that will reflect whatever the user inputs
into the text area of the form allowing us to
edit as needed.
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Posts: 7,686
Thanks: 42
Thanked 637 Times in 625 Posts
Divide the task into chunks.
Chunk 1: User enters data into an HTML form and submits.
Chunk 2: Data is saved into a file or database table.
Chunk 3: Data is displayed.
Take it one chunk at a time.
Now a kind note: You are going to be spammed into the ground by spammers if you do not have some kind of approval mechanism in place. If you do nothing but kick back to the page whatever is entered in the form, you'll have hundreds of Viagra and ***** enlargement posts overnight. Just a friendly warning.
here we have attempted to put php script in an html doc so that it will
display in the text area hopefully after the text has been entered by the user:
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Posts: 7,686
Thanks: 42
Thanked 637 Times in 625 Posts
How did that work out for ya?
You want to be careful to keep your HTML valid. The "id" attribute should be unique throughout your page and you have two elements with an id of "testify".
i so apologize for not responding sooner. my kid got sick and it's been a mess. thank
you for your patience.
I've changed the id to "testimony", so as to make sure the id is unique throughout the page. again i apologize and hope you will still help us.
You need to establish an sql connection if you want to store in database
PHP Code:
function GET_CONNECTION($host,$account,$password,$db)
{
$err=NULL;
$c = @ new mysqli($host,$account,$password,$db);
if (mysqli_connect_errno() != 0) { // // get the text of the error message from MySQLi //
$err = mysqli_connect_error();$err.= "\nConection to database failed!<br />"; }
if($err!=NULL)
throw new Exception($err);
return $c;
}
Then you may need to escape string with php to put it in database
PHP Code:
mysql_escape_string($string);
Also you need a database table to store the testimonials
__________________
Two things are infinite: the universe and human stupidity; and I'm not sure about the universe.
Albert Einstein
----------------------------------------------------- My Blogsongs
Last edited by adarshakb; 12-17-2010 at 06:27 PM..
Is someone going to administer the comments before they are posted?
I hate to think this would happen, but you're going to end-up with comments
your church will not want on their website ... and who is going to be the judge
of what comments are accepted and which one's are not?
I personally think it's a bad idea.
The only reason I would say to go ahead and do this project, would be so you
could learn more about PHP and MySQL. The experience will be more beneficial
than the result.
i regret to inform that the church has decided to hire someone to do the backend. i am disappointed that i was not able to see this through to completion. However, i am working on a personal site and need php/myphpadmin assistance in accessing form data so i can use it.
mysql_select_db("xxx", $con);
$sql="INSERT INTO register (Your First Name, Your Last Name, Your Phone Number, Your E-mail Address, Baby's First Name, Baby's Middle Name,
Baby's Last Name, Baby's Birthdate, Baby's Age, Baby's Height, Baby's Weight, Baby's Eye Color, Baby's Hair Color, Baby's Ethnicity) values ('$yourfirstname',
'$yourlastname', '$yourphonenumber', '$youremailaddress', '$babysfirstname', '$babysmiddlename', '$babyslastname',
'$babysbirthdate', '$babysage', '$babysheight', '$babysweight', '$babyseyecolor', '$babyshaircolor', '$babysethnicity')";
mysql_query($sql, $con) or die ("<br>Query string: $sql<br>Produced error: " . mysql_error() . '<br>');
?>
when i hit the submit button it appears that no data is sent to the server. i really would like as much help as possible. i want to learn this even if the church has taken a different path. i want this.
from the script to see what happens when the form is submitted. it appears as if the header masked the exceptions...maybe because it was the code encountered first. anyway, this is the output when i submitted the form with random info:
Query string: INSERT INTO register (Your First Name, Your Last Name, Your Phone Number, Your E-mail Address, Baby's First Name, Baby's Middle Name, Baby's Last Name, Baby's Birthdate, Baby's Age, Baby's Height, Baby's Weight, Baby's Eye Color, Baby's Hair Color, Baby's Ethnicity) values ('SF', 'SDF', '', '', 'SDGF', 'SDF', 'SDF', 'SDF', '', '', '', 'SDF', 'SDF', '')
Produced error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'First Name, Your Last Name, Your Phone Number, Your E-mail Address, Baby's First' at line 1
I question the use of spaces and especially single quotes you used for MySQL column names.
It's my opinion that you should change your variable name spaces to underscore,
and eliminate any special characters (like the single quote ... baby's ).
You would have to change all of those within your MySQL admin and also in the script.
things are looking up! thanks. i followed your suggestions and it appears to be working
i removed the spaces, the hyphen in the email field/variable and rid myself of the spaces ( i did not include the underscore as you suggested...if that's alright). i did this for the html, php and myphpadmin fields
mysql_query($sql, $con) or die ("<br>Query string: $sql<br>Produced error: " . mysql_error() . '<br>');
i haven't tested all the fields yet but i get no exception and i can see the data in my database table!!!!! so far this has been a total success.
i'm going to re-include that heading script in the which jumps to the checkbox form. is it just possible that you could walk me through the steps of setting up the php script of the form?
i have yet to set up a table and do the php for the form. and actually its a set of different forms over several pages. i know it seems like its too much; to do different forms on different pages but i'm looking to provide a different type of experience where filling in the form isn't so tedious; i'm trying to add a little more than just the form submitting.
but i know others need your help too! you're very valuable. if you couldn't help me any further you really did hook me up. thank you very very much.
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Posts: 7,686
Thanks: 42
Thanked 637 Times in 625 Posts
Multiple page forms can be pretty tricky... the trick is how to bring the data from each page over to the next page. You can save the data into a database, or use sessions... at any rate you'll have some good experience under your belt once you're done
You are going to have several forms.
Between each form, you will save the information for that form before you display the next one?
That's a good plan, so the user doesn't have to start all over if they get halfway and
decide to quit (and come back later).
So, you already have the "username" field ... you will have to add a field where the
user can enter a "password" (enter it twice to validate).
By doing it that way, at the very beginning of each page (script) that has a form,
you will need to check to see if the user has already filled it out. Because you don't
know who is currently viewing your form, you will need to have some way for the user
to "login" ... to see if they already have their name in the database. If they have their
name in your database, that means they previously filled-out, at least, the first form.
You can then determine where they left-off, or quit the form(s). This will also be a way
to give the user a "user profile" page where they can modify, or correct any wrong
information.
==================
On post #13, you're now showing us a form with checkboxes.
is that the 2nd form that will appear for the user?
Are you questioning how to process the checkboxes?
EDIT:
There are some "security issues" you will need to address, in particular,
the use of "user input" being allowed to be used in a SQL query.
I just don't want to throw too many things at you, at one time.
Just know that any variable values provided by a user (site visitor) should be
sanitized if you plan on using it within a query. It will stop users from
injecting their own queries into your database.