Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 25th, 2005, 10:47 PM
Registered User
 
Join Date: Jun 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to arakay
Default login system problem

I'm basically working my way through Chapter 12 of the Beginning PHP, Apache an MySQL book, and I've run into a couple of problems I can't seem to fix or even understand what's going wrong. First, there's a problem on my account updating page...I get the error message "Parse error: parse error, unexpected T_STRING in /home/arakay/public_html/testing/ttongues/update_account.php on line 12", here's first chunk of that page's code:
<?php
include "auth_user.inc.php";
include "conn.inc.php";
?>
<html>
<head><title>Tripping Tongues: Edit Your Profile</title></head>
<body>
Edit your profile info.<p>
<?php
if (isset($_POST['submit']) && $_POST['submit'] == "Update") {
$query_update = "UPDATE user_info SET email = '" . $_POST['email'] . "', city = '" . $_POST['city'] . "',
state = '" . $_POST['state'] . "', langs = '" . $_POST['langs'] . "' WHERE username = '" . $_SESSION['user_logged'] . "' AND password = '" . (PASSWORD('" . $_SESSION['user_password'] . "'))";
$result_update = mysql_query($query_update)
or die(mysql_error());
$query = "SELECT * FROM user_info WHERE username = '" . $_SESSION['user_logged'] . "' AND
password = (PASSWORD('" . $_SESSION['user_password'] . "'))";
$result = mysql_query($query)
or die(mysql_error());

$row = mysql_fetch_array($result);
?>

Also, on my user login page (I can only get to the edit profile section when I register a new user) I get the following error: "Parse error: parse error, unexpected T_ECHO in /home/arakay/public_html/testing/ttongues/user_login.php on line 28"

And here's the code (lines 1-28):

<?php
session_start();
include "conn.inc.php";

if (isset($_POST['submit'])) {
$query = "SELECT username, password FROM user_info WHERE username = '" . $_POST['username'] . "' AND
password = (PASSWORD('" . $_POST['password'] . "'))";
$result = mysql_query($query)
  or die(mysql_error());

if (mysql_num_rows($result) == 1) {
$_SESSION['user_logged'] = $_POST['username'];
$_SESSION['user_password'] = $_POST['password'];
header ("Refresh: 5; URL=" . $_POST['redirect'] . ";");
echo "You are being redirected to your page request";

} else {
?>
<html>
<head>
<title>Tripping Tongues</title>
</head>
<body>
<p>
Invalid Username/Password<br>
Not registered? <a href="register.php">Click here</a>!<br>
<form action="user_login.php" method="post">
<input type="hidden" name="redirect" value="<? php echo $_POST['redirect']; ?>">


Any help would be greatly appreciated! I usually try to puzzle this stuff out on my own, but I'm not getting anywhere. :(
 
Old June 27th, 2005, 09:15 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 142
Thanks: 0
Thanked 2 Times in 2 Posts
Default

With the first block, you'd got into a muddle with your opening and closing of quotes.

With quotes, the best idea when you're including array elements is rather than doing
"array key 'hello' = " . $arr['hello']
do
"array key 'hello' = {$arr['hello']}"
Anything in between curly braces is evaluated.

Also, be strict with your formatting - indent everything after
curly braces. With strings, take full advantage of the fact that php allows you to split them over multiple lines and nicely indent all your SQL statements.

It is worth getting a decent development environment: there's a lot out there, I use Dev-php which has a lot of nice features and best of all is completely free http://devphp.sourceforge.net/. You do have to put up with occasional bizarre german error messages, however.

The problems you've got are all to do with incorrect syntax - go through making sure all your strings close properly, you've got matching brackets/curly brackets (dev php helps with this by highlighting the other bracket), semicolons at the end of lines and $ signs in front of all your variables.

I've done the first one for you, as I said, you'll probably learn better if you go through the second one yourself.
Code:
<html>
<head><title>Tripping Tongues: Edit Your Profile</title></head>
<body>
Edit your profile info.<p>
<?php
if (isset($_POST['submit']) && $_POST['submit'] == "Update") 
{
    $query_update = 
        "UPDATE user_info 
         SET email = '{$_POST['email']}', 
             city  = '{$_POST['city']}', 
                 state = '{$_POST['state']}', 
                 langs = '{$_POST['langs']}' 
         WHERE username = '{$_SESSION['user_logged']}' 
           AND password = '(PASSWORD('{$_SESSION['user_password']}'))";
    $result_update = mysql_query($query_update) or die (mysql_error());
    $query = 
        "SELECT * 
         FROM user_info 
         WHERE username = '{$_SESSION['user_logged']}' 
           AND password = (PASSWORD('{$_SESSION['user_password']}'))";
  $result = mysql_query($query) or die (mysql_error());
    $row = mysql_fetch_array($result);
?>





Similar Threads
Thread Thread Starter Forum Replies Last Post
Login system chroniclemaster1 ASP.NET 2.0 Professional 2 March 4th, 2008 09:34 PM
Multiple problems with Login system, GridView hindereduseless ASP.NET 2.0 Professional 0 May 3rd, 2006 01:13 AM
Authenticate login on same system hitu_patel_soft JSP Basics 0 April 20th, 2006 09:14 AM
How to get system login and date Abhinav_jain_mca General .NET 2 August 26th, 2004 01:12 AM
system() login natmaster Beginning PHP 1 July 31st, 2003 01:59 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.