New to php
Moderator: General Moderators
-
tekkenlord
- Forum Newbie
- Posts: 11
- Joined: Fri Aug 28, 2009 6:21 pm
New to php
Ok, so i'm new to this whole php scripting thing. I am making a site, with a friend who knows no php so not looking great.
But this is what I know so far:
to set a variable you type $variable1 = "James"
and then I could show that on a page as html by using the echo function: echo $variable1 and just the word James would come out on the page.
And I think I know how to make an array
$array1 = array("James","Bob",7)
And i could echo the second part of this array by typing echo $array1[1] (I know that php starts from the number 0).
And I also (think) I know how to make another type of array:
$array2 = array("Regular" => 300,"Medium" => 350,"Large" => 450)
And if i echoed $array2[Large] I would get 450 come up.
Now I beleive that I would also be able to learn some functions (if I learned them).
Now my problem really is that I want to be able to create a data-entry form that would mean that I could easily input data into a html table. And I dont know how I would go abouts doing this. Does anyone know a tutorial where i can do this please thanks
But this is what I know so far:
to set a variable you type $variable1 = "James"
and then I could show that on a page as html by using the echo function: echo $variable1 and just the word James would come out on the page.
And I think I know how to make an array
$array1 = array("James","Bob",7)
And i could echo the second part of this array by typing echo $array1[1] (I know that php starts from the number 0).
And I also (think) I know how to make another type of array:
$array2 = array("Regular" => 300,"Medium" => 350,"Large" => 450)
And if i echoed $array2[Large] I would get 450 come up.
Now I beleive that I would also be able to learn some functions (if I learned them).
Now my problem really is that I want to be able to create a data-entry form that would mean that I could easily input data into a html table. And I dont know how I would go abouts doing this. Does anyone know a tutorial where i can do this please thanks
Re: New to php
One of the first hits when I searched for "PHP form" was this one:
http://www.tizag.com/phpT/forms.php
http://www.tizag.com/phpT/forms.php
Re: New to php
The web is filled with tutorials. Many of us think that one of the best places to go for this is http://w3schools.com/.
You're correct about the PHP facts that you mentioned, but you must realize that that is maybe 0.0001% of what you need to know, just to write a simple login script, for example.
You're correct about the PHP facts that you mentioned, but you must realize that that is maybe 0.0001% of what you need to know, just to write a simple login script, for example.
-
tekkenlord
- Forum Newbie
- Posts: 11
- Joined: Fri Aug 28, 2009 6:21 pm
Re: New to php
thanks for the quick answer.
and oh - 0.00001% i've got a lot of work
and oh - 0.00001% i've got a lot of work
-
tekkenlord
- Forum Newbie
- Posts: 11
- Joined: Fri Aug 28, 2009 6:21 pm
Re: New to php
roughly, how long would it take me to learn php and mysql.
baring in mind that i have limited time (about an hour or two a day) cause i'm 15 and about to do my GCSEs
baring in mind that i have limited time (about an hour or two a day) cause i'm 15 and about to do my GCSEs
-
tekkenlord
- Forum Newbie
- Posts: 11
- Joined: Fri Aug 28, 2009 6:21 pm
Re: New to php
and i would also like to know, where would be a good place to start?
Re: New to php
I've learned from a book, PHP bible.
-
tekkenlord
- Forum Newbie
- Posts: 11
- Joined: Fri Aug 28, 2009 6:21 pm
Re: New to php
is it easy to read, i'm not very good when it comes to books lol
Re: New to php
Ive never helped anyone out on here because i normally need the help but you sound like me 2 weeks ago :ptekkenlord wrote:Now my problem really is that I want to be able to create a data-entry form that would mean that I could easily input data into a html table. And I dont know how I would go abouts doing this. Does anyone know a tutorial where i can do this please thanks
First of all your going to need a MySQL database set up, if you dont have one google a tutorial on how to make one. The idea is to send information to database then use that information on request to output a html table.
Follow this for a tutorial on MySQL setup: http://www.w3schools.com/PHP/php_mysql_connect.asp
As you create one you need to make a table call it table1, this should be in the tutorial, make the table have 2 columns for this example to work "name" and "favorite". You can make a new table and everything once you understand how the system works.
Once you have MySQL setup you can begin to make your form.
start the form like this
Code: Select all
<form action="http://[color=#FF0000]ENTERYOURWEBSITE[/color]/process.php" method="post">Next is to create areas for users to input, in this example ill show you a text area and a one line area.
One line input:
This will have in my example the users name
<input name="name" type="text" value=" Enter Name Here" size="20" />
Text Area (multiple lines):
This will be favorite things in life (random i know)
Code: Select all
<textarea name="favorite" cols="20" rows="5" wrap="physical" >Write here what you love in life..isit php? I bet it is</textarea>Now when you got the form set out you need a submit button, this will send the data to the database. Here is an example:
Code: Select all
<input name="submit" type="submit" value="submit" />Process.php
This will read the information and insert it into the database for you.
First of all the php script will connect to your database
Code: Select all
<?php
$host="localhost"; // Host name
$username="enter here"; // Mysql username
$password="enter here"; // Mysql password
$db_name="enter here"; // Database name
$tbl_name="enter here"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
Code: Select all
// Insert data into mysql
$sql="INSERT INTO $tbl_name(name, favorite)VALUES('$name', '$favorite')";
$result=mysql_query($sql);Once inserted finish the script with this:
Code: Select all
// if successfully insert data into database, displays message "Successful".
if($result){
echo "Thank you for submiting your job, our team will now take a look and approve very soon ";
echo "<BR>";
echo "<a href='http://miniworkers.justfree.com/jobs.php'>Click here to go back to miniworkers</a>";
}
else {
echo "ERROR";
}
?>FINAL PART: createing the html table with the data... Start a new php page called table.php and start the script like this, connecting to the Database
Code: Select all
<?php
$host="localhost"; // Host name
$username="enter here"; // Mysql username
$password="enter here"; // Mysql password
$db_name="enter here"; // Database name
$tbl_name="enter here"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");Code: Select all
$result = mysql_query("SELECT `title`,`favorite` FROM `table1`") or die( mysql_error() );Next its down to the table, lets start:
Code: Select all
// START AN OUTPUT TABLE
echo "<table class='sample5'>";
// IF NO RESULTS
if (!mysql_num_rows($result))
{
echo "<tr><td colspan='8'>The database has found no records</td></tr>";
}
// IF WE HAVE RESULTS
else
{Code: Select all
// TITLE FOR COLUMNS
echo "<tr><td nowrap><b>Name</b></td><td align='left'><b>favorite</b></th></tr>";Next its getting the information we want into the table and ending the table like so:
Code: Select all
// ITERATE OVER THE RESULTS SET
while ($line = mysql_fetch_assoc($result))
{
// EASY-TO-READ LOCAL VARIABLES
foreach ($line as $key => $val) { $$key = htmlentities($val); }
// CREATE THE ROW OF DATA
echo "<tr>";
echo "<td>$name</td>\n";
echo "<td align='left'>$faovrite</td>\n";
} // END WHILE ITERATOR
echo "</table>\n";
} // END IF/ELSE
?>LOL kinda went on a bit.... Ah well i might of got the wrong idea here but thats how i would do it.
-
tekkenlord
- Forum Newbie
- Posts: 11
- Joined: Fri Aug 28, 2009 6:21 pm
Re: New to php
thanks so much AMAZING tutorial. and its 2.04am now, so i'd better go to bed lol. I'm going to do this in the morning though (or when i wake up)
btw when it is connecting to the database, what is the host:
<?php
$host="localhost"; // Host name
$username="enter here"; // Mysql username
$password="enter here"; // Mysql password
$db_name="enter here"; // Database name
$tbl_name="enter here"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
i know that localhost is the one that is specific to my computer. but i have a website, so wondered how i would do it with that
btw when it is connecting to the database, what is the host:
<?php
$host="localhost"; // Host name
$username="enter here"; // Mysql username
$password="enter here"; // Mysql password
$db_name="enter here"; // Database name
$tbl_name="enter here"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
i know that localhost is the one that is specific to my computer. but i have a website, so wondered how i would do it with that
Re: New to php
keep it as localhost, it should work, does for my site anyway 
-
tekkenlord
- Forum Newbie
- Posts: 11
- Joined: Fri Aug 28, 2009 6:21 pm
Re: New to php
oh thanks. did u learn php in 2 weeks??
and if you don't mind could i see ur website?
and if you don't mind could i see ur website?
Re: New to php
Ill pm you hang on, and no i dont claim to know php yet
these guys here "KNOW" php 