PDA

View Full Version : PHP Start



adamFTW
07-11-2007, 01:38 AM
I want to start trying PHP.

Could someone name one of the easiest PHP scripts that would be good for beginners?

Also, other then w3schools are there any good PHP tutorial websites?

DeejayMachoo$
07-11-2007, 01:43 AM
umm techtuts.com

QuickScriptz
07-11-2007, 01:45 AM
Well....
My first script ever was my PhP My-Admin. You can download it and take a look:

http://quickscriptz.ca/v3/freebies-admin.php

More Tuts:
http://www.tizag.com/phpT/

Colin-Roberts
07-11-2007, 01:55 AM
pixel2life.com

adamFTW
07-11-2007, 02:30 AM
I've just looked at some explaining, my code so far is very lame.

I'm creating a register themed thing. Im having problems with one code though.

Code:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<?php
// retrieve form data
$email = $_POST['email'];
// check entered value and branch
if ($email = @hotmail.com) {
echo 'Sorry, we do not accept @hotmail.com users!';
}
else {
echo "On to the next step....

<form action="username.php" method="post">
Enter desired username: <input name="username" size"20">
</form>";
}

?>

</body>
</html>
The error is: Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/habboboa/public_html/wlphp/passemail.php on line 20

Line 20 is the line that has "<form action="username.php" method="post">".

Help appreciated.

Aflux
07-11-2007, 06:56 AM
<?php
echo="LOLZ"
?>

www.php.net

Beau
07-11-2007, 07:38 AM
PHP.net is a fantastic resource. CHeck out the comments for functions, will save you a lot of time.

http://www.phpbuilder.com and http://www.good-tutorials.com are good also.

rh4u
07-11-2007, 07:49 AM
I've just looked at some explaining, my code so far is very lame.

I'm creating a register themed thing. Im having problems with one code though.

Code:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<?php
// retrieve form data
$email = $_POST['email'];
// check entered value and branch
if ($email = @hotmail.com) {
echo 'Sorry, we do not accept @hotmail.com users!';
}
else {
echo "On to the next step....

<form action="username.php" method="post">
Enter desired username: <input name="username" size"20">
</form>";
}

?>

</body>
</html>
The error is: Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/habboboa/public_html/wlphp/passemail.php on line 20

Line 20 is the line that has "<form action="username.php" method="post">".

Help appreciated.
change line 20 to <form action=\"username\" method=\"post\">

DeejayMachoo$
07-11-2007, 12:24 PM
Code:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<?php
// retrieve form data
$email = $_POST['email'];
// check entered value and branch
if ($email = @hotmail.com) {
echo 'Sorry, we do not accept @hotmail.com users!';
}
else {
echo "On to the next step....

<form action=\"username.php\" method=\"post\">
Enter desired username: <input name=\"username\" size\"20\">
</form>";
}

?>

</body>
</html>
Try that :)

adamFTW
07-11-2007, 12:34 PM
That didnt work, no matter what you input for the email it says no @hotmail.com users.

adamFTW
07-11-2007, 12:39 PM
No, that didnt work.

Also, I have the following code, but when the text comes out $username just comes out ast $username.


<?php
// retrieve form data
$username = $_POST['username'];
// check entered value and branch
{
echo 'You have now signed up as $username!';
}
?>

Colin-Roberts
07-11-2007, 12:55 PM
i believe?

<?php
// retrieve form data
$username = $_POST['username'];
// check entered value and branch
{
echo 'You have now signed up as '.$username.'!';
}
?>

lolwut
07-11-2007, 01:21 PM
Change the line that says:
if($email = @hotmail.com){
to:
if($email = "@hotmail.com"){

You where missing off the "'s around the email, because you can't put plaintext in if statements if they're not wrapped in "'s.

rh4u
07-11-2007, 04:32 PM
No, that didnt work.

Also, I have the following code, but when the text comes out $username just comes out ast $username.


<?php
// retrieve form data
$username = $_POST['username'];
// check entered value and branch
{
echo 'You have now signed up as $username!';
}
?>
its:
<?php
// retrieve form data
$username = $_POST['username'];
// check entered value and branch
{
echo "You have now signed up as $username!";
}
?>
;)

Blob
07-11-2007, 05:25 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<?php
if( $_POST["email"] && !empty($_POST["email"]) )
{
if( preg_match("(\w+@[a-zA-Z_-]+?\.[a-zA-Z]{2,6})", $_POST["email"]) )
{
if( preg_match("(\w+@hotmail+?\.[a-zA-Z]{2,6})", $_POST["email"]) )
{
echo "Sorry we do not allow hotmail emails";
} else
{
echo 'On to the next step....
<form action="username.php" method="post">
Enter desired username:
<br />
<input name="username" size="20" type="text"><br />
<input value="Submit" type="submit">
</form>';
}
} else
{
echo "You entered an invalid email";
}
} else
{
echo "You didnt enter anything for your email";
}
?>

</body>
</html>

Try that.

And for username:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<?php
if( $_POST["username"] )
{
echo 'You have now signed up as ' . $username . '!';
}
?>

</body>
</html>

adamFTW
07-11-2007, 09:40 PM
New error now. :l

Error: Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' in /home/habboboa/public_html/wlphp/new/reg.php on line 48

Line 48:

$query = mysql_query("INSERT INTO `system` (`username`, `password`, `age`) VALUES ($username, '$password', '$age'");

adamFTW
07-11-2007, 09:51 PM
Does it have to do with the ; or ' or does it have to do with the variable itself?

Frog!
07-11-2007, 09:54 PM
$query = mysql_query("INSERT INTO `system` (`username`, `password`, `age`) VALUES ('$username', '$password', '$age'");

Try that.

adamFTW
07-11-2007, 09:56 PM
Nope, didnt work.

Frog!
07-11-2007, 10:00 PM
Check the lines before incase you've missed an ; out.

adamFTW
07-11-2007, 10:02 PM
The line before is: else { The line before that has a ';'.

Frog!
07-11-2007, 10:04 PM
You've not closed something. Like an echo("");

adamFTW
07-11-2007, 10:05 PM
Heres my entire code.


<?php
if(!$_POST['this']){
echo("
Please use this form to register...<br>
<form method=\"POST\">
<table width=300><tr><td width=\"200\">Username:</td>
<td><input type=\"text\" name=\"username\"></td></tr>

<tr><td width=\"200\">Password:</td>
<td><input type=\"text\" name=\"password\"></td></tr>

<tr><td width=\"200\">Confirm Password:</td>
<td><input type=\"text\" name=\"cpassword\"></td></tr>

<tr><td width=\"200\">Email</td>
<td><input type=\"text\" name=\"email\"></td></tr>

<tr><td width=\"200\">Username:</td>
<td><input type=\"text\" name=\"username\"></td></tr><tr>

<tr><td width=\"200\">Age:</td>
<td><input type=\"text\" name=\"age\"></td></tr>

<tr><td width=\"200\"></td><td><input type=\"submit\" name=\"this\" value=\"register\"></td></tr></table>
</form>");}
else{
$username = $_POST['username'];
$password =$_POST['password'];
$password=md5($password);
$cpassword =$_POST['cpassword'];
$cpassword=md5($cpassword);
$age = $_POST['age'];
$email = $_POST['email'];
$cemail = $_POST['cemail'];
if($password != $cpassword){
echo("The Two passwords didnt match..."); exit;
}
if ($age <= 13) {{
echo("Your not old enough to join."); exit;
}

if($email != $cemail){
echo("The two emails didnt match..."); exit;
}

else {
echo("You have now singed up as <b>$username!</b> You can log in by clicking <a href='login.php'>here.</a>")
$query = mysql_query("INSERT INTO `system` (`username`, `password`, `age`) VALUES ('$username', '$password', '$age'");
echo("You have suscssfully registered $username");
}
}
?>

Frog!
07-11-2007, 10:07 PM
<?php
if(!$_POST['this']){
echo("
Please use this form to register...<br>
<form method=\"POST\">
<table width=300><tr><td width=\"200\">Username:</td>
<td><input type=\"text\" name=\"username\"></td></tr>

<tr><td width=\"200\">Password:</td>
<td><input type=\"text\" name=\"password\"></td></tr>

<tr><td width=\"200\">Confirm Password:</td>
<td><input type=\"text\" name=\"cpassword\"></td></tr>

<tr><td width=\"200\">Email</td>
<td><input type=\"text\" name=\"email\"></td></tr>

<tr><td width=\"200\">Username:</td>
<td><input type=\"text\" name=\"username\"></td></tr><tr>

<tr><td width=\"200\">Age:</td>
<td><input type=\"text\" name=\"age\"></td></tr>

<tr><td width=\"200\"></td><td><input type=\"submit\" name=\"this\" value=\"register\"></td></tr></table>
</form>");}
else{
$username = $_POST['username'];
$password =$_POST['password'];
$password=md5($password);
$cpassword =$_POST['cpassword'];
$cpassword=md5($cpassword);
$age = $_POST['age'];
$email = $_POST['email'];
$cemail = $_POST['cemail'];
if($password != $cpassword){
echo("The Two passwords didnt match..."); exit;
}
if ($age <= 13) {{
echo("Your not old enough to join."); exit;
}

if($email != $cemail){
echo("The two emails didnt match..."); exit;
}

else {
echo("You have now singed up as <b>$username!</b> You can log in by clicking <a href='login.php'>here.</a>");
$query = mysql_query("INSERT INTO `system` (`username`, `password`, `age`) VALUES ('$username', '$password', '$age'");
echo("You have suscssfully registered $username");
}
}
?>
You forgot to put the ';' at the end of the echo

Want to hide these adverts? Register an account for free!