/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Parse error

[B]Parse error:[/B] parse error, unexpected T_STRING in [B]/home2/dtoporg/public_html/catolog/session/addmakdir.php[/B] on line [B]9[/B]

[code=php]<?php
$username = $_REQUEST[“username”];
$username = $_REQUEST[“password”];

mkdir(“/home2/dtoporg/public_html/catolog/users/$username”, 0700);
mkdir(“/home2/dtoporg/public_html/catolog/users/$username/thumbs”, 0700);
mkdir(“/home2/dtoporg/public_html/catolog/users/$username/large”, 0700);

$sql = INSERT INTO login (username, password, user_group) VALUES (‘$username’, md5(‘$password’), ‘0’);

echo(‘User created. Click <a href=”/catolog/checkLogin.php”>here</a> to return to admin section.’);
?>[/code]

There is a form, it takes the password, and the user name. It makes a directory for that user to store pictures in. After that, I would like it to made a new feild into my database, and this is the part that isn’t working.

to post a comment
PHP

20 Comments(s)

Copy linkTweet thisAlerts:
@chazzyMar 16.2006 — this is a string

[colorcode=php]

$sql = INSERT INTO login (username, password, user_group) VALUES ('$username', md5('$password'), '0');

[/colorcode]

But you didn't put any quotes around it.
Copy linkTweet thisAlerts:
@The_Little_GuyauthorMar 16.2006 — what do I need to change it to?
Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYMar 16.2006 — [code=php]$sql = "INSERT INTO login (username, password, user_group) VALUES ('$username', ".md5('$password').", '0')";[/code]
Copy linkTweet thisAlerts:
@NogDogMar 16.2006 — (LCF beat me to it.)
Copy linkTweet thisAlerts:
@The_Little_GuyauthorMar 16.2006 — OK, Now it works. How do I get it to add That info into the MySQL database?
Copy linkTweet thisAlerts:
@chazzyMar 16.2006 — you need to execute the sql

[colorcode=php]

$result = mysql_query($sql);

if(!$result){

echo "Your insert failed!".mysql_error();

}

[/colorcode]
Copy linkTweet thisAlerts:
@The_Little_GuyauthorMar 16.2006 — I also have to connect do the database dont I?
Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYMar 16.2006 — (LCF beat me to it.)[/QUOTE]
? ? ?
Copy linkTweet thisAlerts:
@The_Little_GuyauthorMar 16.2006 — I get this message when It is ran:

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 'e9410a9f577d2d662c67025ee9, '0')' at line 1
Copy linkTweet thisAlerts:
@The_Little_GuyauthorMar 16.2006 — Ok, I got the previous thing to work, but now I get this error:

Duplicate entry '2' for key 1
Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYMar 16.2006 — do you have an auto incrementing field?
Copy linkTweet thisAlerts:
@The_Little_GuyauthorMar 16.2006 — Yes, and that is the [B]user_id[/B] field.

Here is how my phpAdmin reccomends I use in my php. For the VALUES part, I want [B]username[/B], and [B]password[/B] to be the vaiables that I have previously set and [B]password [/B]to be md5

$sql = 'INSERT INTO login (user_id, username, password, user_group) VALUES ('2', 'username', 'password', '0')';
Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYMar 16.2006 — [code=php]
$sql = "INSERT INTO login (user_id, username, password, user_group) VALUES ('', '$username', '$password', '0')";
[/code]
Copy linkTweet thisAlerts:
@The_Little_GuyauthorMar 16.2006 — Ok, but now I get this error:

[B]Duplicate entry '0' for key 1[/B]

I can add one person, but when I add a second I get the aboveerror
Copy linkTweet thisAlerts:
@The_Little_GuyauthorMar 16.2006 — Ok, but now I get this error:

[B]Duplicate entry '0' for key 1[/B]

I can add one person, but when I add a second I get the aboveerror[/QUOTE]



Got it, I had an index of that one set to unique
Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYMar 16.2006 — problem solved?
Copy linkTweet thisAlerts:
@chazzyMar 17.2006 — Got it, I had an index of that one set to unique[/QUOTE]

Then you didn't define it as an auto_increment primary key.
Copy linkTweet thisAlerts:
@The_Little_GuyauthorMar 17.2006 — I had both. One was called something, the other had a 2 after it.

I have ran into another problem. I had this working fine at work, and when I got home to try it, after about 3-4 hours, It isn't.

I am able to log in, but It doenst login propperly.



[code=php]
<?PHP
//check that the user is calling the page from the login form and not accessing it directly
//and redirect back to the login form if necessary
if (!isset($username) || !isset($password)) {
header( "Location: http://www.d-top.org/catolog/login.htm" );
}
//check that the form fields are not empty, and redirect back to the login page if they are
else if (empty($username) || empty($password)) {
header( "Location: http://www.d-top.org/catolog/login.htm" );
}
else{

//convert the field values to simple variables

//add slashes to the username and md5() the password
$user = addslashes($_POST['username']);
$pass = md5($_POST['password']);


//set the database connection variables

$dbHost = "localhost";
$dbUser = "dtoporg_dtop";
$dbPass = "abc123";
$dbDatabase = "dtoporg_login";

//connet to the database

$db = mysql_connect("$dbHost", "$dbUser", "$dbPass") or die ("Error connecting to database.");

mysql_select_db("$dbDatabase", $db) or die ("Couldn't select the database.");

$result = mysql_query("select * from login where username='$user' AND password='$pass'", $db);


//check that at least one row was returned

$rowCheck = mysql_num_rows($result);
if($rowCheck > 0){
$usergroup = mysql_result($result, 0, 'user_group');

//while ($row = mysql_fetch_array($result)){

//start the session and register a variable

session_start();
session_register('$user, $usergroup');

//successful login code will go here...
echo 'Login Was A Success!';

//we will redirect the user to another page where we will make sure they're logged in
echo '<br><a href="checkLogin.php">Click Here To Continue</a>';

// }

}
else {

//if nothing is returned by the query, unsuccessful login code goes here...

echo '<a href="login.htm">Login Was Unsuccessful. Please try again.</a>';
}
}
?>
[/code]


[code=php]
<?php
//start the session
session_start();
//check to make sure the session variable is registered
if(session_is_registered('$user, $usergroup'))
{
if($usergroup == "1")
{
echo ('Your Logged in as the admin Select an action from the list below:
<p><a href="session/add.php">Add Session</a> | <a href="session/delete.php">Delete Session</a> | <a href="session/edit.php">Edit Session</a></p>');
}
else if ($usergroup == "0")
{
echo('hello ' . $user . '... Please select an action to continue');
}

}
else{

//the session variable isn't registered, send them back to the login page
header( "Location: http://www.d-top.org/catolog/login.htm" );
}

?>
[/code]


If I use another name, one that is in the database it doesn't work.

Feild 1: ryan

Feild 2: ryan

[URL=http://www.d-top.org/catolog/login.htm][B]Try it HERE[/B][/URL]

If I use the admin name, get a blank page.
Copy linkTweet thisAlerts:
@chazzyMar 17.2006 — 1 error i see is here:
[code=php]
if(session_is_registered('$user, $usergroup'))
[/code]


I'm not sure what you're trying to do here.
Copy linkTweet thisAlerts:
@The_Little_GuyauthorMar 17.2006 — I took that and changed it to:

$_session['user'] = ''. $user;

$_
session['usergroup'] = ''. $usergroup;

Now I can login, logout, and I have all the users working now. I can add users, and right now I am working on deleting users. At this moment, the program is running perfictly fine, for how far it is, so I don't have any questions yet at this moment.


This is my very first PHP program, and I am feel good about it.

Thanks For helping me through this as well.
×

Success!

Help @The_Little_Guy spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...