php help

swirly

Active Member
Messages
1,930
Reaction score
0
Points
36
well that was the wrong code i figured out...but now i got the right one...but its not working....its for people to add names and passwords etc..but its not submitting, and i copied it straight out of the book. did i just spell something. heres the code...
Code:
<html>
<head>
<title>Add User</title></head>

<?php
if( (!$firstname) or (!$lastname)
                               or (!$username) or (!$password) )
{
$form ="Please enter all new user details...";
$form.="<for action=\"$PHP_SELF\"";
$form.=" method=\"post\">First Name: ";
$form.="<input type=\"text\" name\"firstname\"";
$form.="value=\"$firstname\"><br>Last Name: ";
$form.="<input type=\"text\" name\"lastname\"";
$form.="value=\"$lastname\"><br>User Name: ";
$form.="<input type=\"text\" name\"username\"";
$form.="value=\"$username\"><br>Password: ";
$form.="<input type=\"text\" name\"password\"";
$form.="value=\"$password\"><br>";
$form.="<input type=\"submit\" value=\"Submit\">";
$form.="</form>";
echo($form);
}
else
{ $conn = @mysql_connect("localhost", "swirlys", "friends")
or die("Could not connect to MYSQL");

$db = @mysql_select_db("swirlys_user", $conn)
or die("could not select database"); 

$sql = "insert into users
(first_name,last_name,user_name,password) values
(\"$firstname\",\"$lastname\",\"$username\",
                               password(\"$password\") )";
$result =@mysql_query($sql,$conn)
or die("Could not execute query");
if($result) {echo("New user $username added"); }
}
?></body</html>
 
Last edited:

lambada

New Member
Messages
2,444
Reaction score
0
Points
0
You missed out the opening body tag, and the '>' off the closing body tag.

Thats all I can see.
 

Xenon Design

New Member
Messages
160
Reaction score
0
Points
0
Heres another mistake:
$form.="<for action=\"$PHP_SELF\""; .... you missed the m in form
 

randomize

New Member
Messages
674
Reaction score
0
Points
0
swirly said:
Code:
{
[B][COLOR=red]$form ="Please enter all new user details...";[/COLOR][/B]
[B][COLOR=darkorange]$form.="<for action=\"$PHP_SELF\"";[/COLOR][/B]
$form.=" method=\"post\">First Name: ";
$form.="<input type=\"text\" name\"firstname\"";
$form.="value=\"$firstname\"><br>Last Name: ";
$form.="<input type=\"text\" name\"lastname\"";
$form.="value=\"$lastname\"><br>User Name: ";
$form.="<input type=\"text\" name\"username\"";
$form.="value=\"$username\"><br>Password: ";
$form.="<input type=\"text\" name\"password\"";
$form.="value=\"$password\"><br>";
$form.="<input type=\"submit\" value=\"Submit\">";
$form.="</form>";
echo($form);
}

Look at the the code in red then look at the code in orange.

There is a dot missing at the end of the "form" on the very first line.

I dunno if that is an error but I just thought I would point it out to you guys anyway!
 

flapietoetoe

New Member
Messages
226
Reaction score
0
Points
0
What error does it give?
That would be alot more helpfull then just posting it doesnt work
 

The_Magistrate

New Member
Messages
1,118
Reaction score
0
Points
0
randomize said:
Look at the the code in red then look at the code in orange.
There is a dot missing at the end of the "form" on the very first line.
I dunno if that is an error but I just thought I would point it out to you guys anyway!

That's not an error, the dot (.) is used to concatenate two strings together. (i.e. $form = "String from line 1" + "String from line 2")

Also, global varables are turned on here at X10, so you'll need to use
Code:
if(isset($_POST['firstname']))
   $firstname = $_POST['firstname'];
if(isset($_POST['lastname']))
   $lastname = $_POST['lastname'];
if(isset($_POST['username']))
   $username = $_POST['username'];
if(isset($_POST['password']))
   $password = $_POST['password'];

Add that to the top of your script and you should be golden.
 
Last edited:

Bryon

I Fix Things
Messages
8,149
Reaction score
101
Points
48
The_Magistrate said:
Also, global varables are turned on here at X10, so you'll need to use
PHP:
if(isset($_POST['firstname']))
   $firstname = $_POST['firstname'];
if(isset($_POST['lastname']))
   $lastname = $_POST['lastname'];
if(isset($_POST['username']))
   $username = $_POST['username'];
if(isset($_POST['password']))
   $password = $_POST['password'];

Add that to the top of your script and you should be golden.

Good point.. Register Globals, I believe, is turned off on x10's free server. I'm surprised I didnt' catch that earlier when I looked at this.. :)
 
Top