Hi all - I'm a designer trying to cut his teeth on some php. I have a real simple task to do and was hoping for some help.
All I want to try doing first is have a page that says
'Hi my name is.....'
And have the blank updatable via a page that has a text field and a save button. I already have made a database, but not sure what to
create in the way of tables etc.
I thought it'd be easy to find a tutorial for this but no luck, so any help would be immensely appreciated!
Thanks!
Beginner Needs Help
Moderator: General Moderators
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: Beginner Needs Help
The form code and 'display' codedilby wrote:And have the blank updatable via a page that has a text field and a save button. I already have made a database, but not sure what to
create in the way of tables etc.
Code: Select all
<!-- the html form -->
<form method="post" action="page_to_display" >
<input type="text" name="text_field" size="20" maxlength="50" />
<input type="submit" name="save" value="Save" />
</form>
Code: Select all
<?php
// u need an html form, using post as a method
// on the previous page
// ---
// check that the 'save' button is clicked
// or you will have 'Hi my name is.....' shown
// without a name
if (isset($_POST['save'])) {
// remove whitespace if any
$name = trim($_POST['text_field']);
// stop possible XSS attacks
$clean_name = htmlentities($name);
// print to browser
echo 'Hi my name is '. $clean_name;
}
?>“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Re: Beginner Needs Help
Hi thanks fo much for the reply! Please excuse my green questions, but what do I need to name the database table? And does this code go into the one file - if so what is the code to actually display it on say an index page in the root?
Thanks!
Thanks!
Re: Beginner Needs Help
Hey, I make a simple coded one to show what you are asking and doesn't require a database.
Maybe you will find this useful.
Code: Select all
<?php
if(isset($_POST['submit'])){
$name = $_POST['name'];
if($name){
echo "Hi, my name is $name";
} else {
echo "Plese enter your name.";
}
} else {
echo "
<form method='POST' action='name.php'>
Type your name in the textfield bellow and press the button.<br />
<input type='text' name='name' size='30' /><br />
<input type='submit' name='submit' value='Submit' />
</form>";
}
?>
- Kaleb Klein
------------------------------------
Web Developer | Software Developer
https://kalebklein.com
PGP Key: https://keybase.io/pazuzu156
------------------------------------
Web Developer | Software Developer
https://kalebklein.com
PGP Key: https://keybase.io/pazuzu156
Re: Beginner Needs Help
Here's a fairly decent tutorial that covers what you are asking about:
http://www.blazonry.com/scripting/links ... t_data.php
http://www.blazonry.com/scripting/links ... t_data.php