 |
BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6  | This is the forum to discuss the Wrox book Beginning PHP, Apache, MySQLWeb Development by Michael K. Glass, Yann Le Scouarnec, Elizabeth Naramore, Gary Mailer, Jeremy Stolz, Jason Gerner; ISBN: 9780764557446 |
|
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 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
|
|
|
|

March 23rd, 2004, 04:26 PM
|
|
Authorized User
|
|
Join Date: Mar 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
chapter11 login
from the script in the book on page 327 (index.php)
I receive this message:
Notice: Undefined index: user_logged in c:\inetpub\wwwroot\test2\index.php on line 3
How can this be fixed or adjusted so it does not display an error
|
|

March 23rd, 2004, 04:29 PM
|
|
Authorized User
|
|
Join Date: Mar 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Line 3 is
if ($_SESSION['user_logged'] == "" || $_SESSION['user_password'] == "")
|
|

March 23rd, 2004, 04:38 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
|
|
Does the page start with session_start(); ?
Does it work, and you want to remove the error, or does it not work?
----------
---Snib---
----------
<><
|
|

March 23rd, 2004, 04:43 PM
|
|
Authorized User
|
|
Join Date: Mar 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
it does start with session_start();
and the page seems to work, but I get this undefined error throughout the page examples
|
|

March 23rd, 2004, 04:45 PM
|
|
Authorized User
|
|
Join Date: Mar 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
on the register page I get an undefined index: submit in
if ($_POST['submit'] == "register") <-- this is the line they are pointing to.
|
|

March 23rd, 2004, 04:50 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
|
|
OK, I think you need to understand this: I don't have the book. Many people here don't. Therefore, you must provide more information.
It looks to me like you didn't have a form that POSTed to the 'register page.'
So it seems that you have 3 pages. The register page, the page that should have POSTed to it, and the page that has the troublesome Line 3....
Am I right?
----------
---Snib---
----------
<><
|
|

March 23rd, 2004, 05:09 PM
|
|
Authorized User
|
|
Join Date: Mar 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
okay the situation is this:
the index.php page code is this: (this gives me a undefined error on line3 which is the line that begins with if)
<?php
session_start();
if ($_SESSION['user_logged'] == "" || $_SESSION['user_password'] == "")
{
include "unlogged_user.php";
}
else
{
include "logged_user.php";
}
?>
Now if the User needs to be REGISTERED it brings you to the registration page which is below which gives me an undefined error beginning with (if ($_POST['submit'] == "Register")) line 11.
code:
<?php
session_start();
include "conn.inc.php";
?>
<html>
<head>
<title>Beginning PHP, Apache, MySQL Web Development</title>
</head>
<body>
<?php
if ($_POST['submit'] == "Register")
{
if ($_POST['username'] != "" && $_POST['password'] != "" &&
$_POST['f_name'] != "" && $_POST['l_name'] != "" &&
$_POST['email'] != "")
{
$check_user = $_POST['username'];
$query = "SELECT username FROM user_info WHERE username =
'$check_user';";
$result = mysql_query($query) or die(mysql_error());
if (mysql_num_rows($result) != 0)
{
?>
<b>The Username, <?php echo $_POST['username']
; ?>, is already in use, please choose another!</b>
<form action="register.php" method="post">
Username: <input type="text" name="username"><br>
Password: <input type="password" name="password" value="<?php echo
$_POST['password']; ?>"><br>
Email: <input type="text" name="email" value="<?php echo
$_POST['email']; ?>"><br>
First Name: <input type="text" name="f_name" value="<?php echo
$_POST['first_name']; ?>"><br>
Last Name: <input type="text" name="l_name" value="<?php echo
$_POST['last_name']; ?>"><br>
City: <input type="text" name="city" value="<?php echo
$_POST['city']; ?>"><br>
State: <input type="text" name="state" value="<?php echo
$_POST['state']; ?>"><br>
Hobbies/Interests: (choose at least one)<br>
<select name="hobbies[]" size="10" multiple>
<option value="Golfing"<?php if (in_array("Golfing",
$_POST['hobbies'])) echo " selected"; ?>>Golfing</option>
<option value="Hunting"<?php if (in_array("Hunting",
$_POST['hobbies'])) echo " selected"; ?>>Hunting</option>
<option value="Reading"<?php if (in_array("Reading",
$_POST['hobbies'])) echo " selected"; ?>>Reading</option>
<option value="Dancing"<?php if (in_array("Dancing",
$_POST['hobbies'])) echo " selected"; ?>>Dancing</option>
<option value="Internet"<?php if (in_array("Internet",
$_POST['hobbies'])) echo " selected"; ?>>Internet</option>
<option value="Flying"<?php if (in_array("Flying",
$_POST['hobbies'])) echo " selected"; ?>>Flying</option>
<option value="Traveling"<?php if (in_array("Traveling",
$_POST['hobbies'])) echo " selected"; ?>>Traveling</option>
<option value="Exercising"<?php if (in_array("Exercising",
$_POST['hobbies'])) echo " selected"; ?>>Exercising</option>
<option value="Computers"<?php if (in_array("Computers",
$_POST['hobbies'])) echo " selected"; ?>>Computers</option>
<option value="Other Than Listed"<?php if (in_array("Other Than
Listed", $_POST['hobbies'])) echo " selected"; ?>>Other Than
Listed</option>
</select><br><br>
<input type="submit" name="submit" value="Register"> <input
type="reset" value="Clear">
</form>
<?php
}
else
{
$query = "INSERT INTO user_info(username, password, email, f_name,
l_name, city, state, hobbies) VALUES ('" . $_POST['username'] .
"', (password('"
. $_POST['password'] . "')), '" . $_POST['email'] . "', '" .
$_POST['f_name'] .
"', '" . $_POST['l_name'] . "', '" . $_POST['city'] . "', '" .
$_POST['state'] .
"', '" . implode(", ", $_POST['hobbies']) . "');";
$result = mysql_query($query) or die(mysql_error());
$_SESSION['user_logged'] = $_POST['username'];
$_SESSION['user_password'] = $_POST['password'];
?>
Thank you, <?php echo $_POST['f_name'] . ", " . $_POST['l_name']; ?> for registering!<br>
<a href="index.php">Click here</a> to continue.
<?php
}
}
else
{
?> <b>The Username, Password, Email, First Name, and
Last Name fields are required!</b>
<form action="register.php" method="post">
Username: <input type="text" name="username" value="<?php echo
$_POST['username']; ?>"><br>
Password: <input type="password" name="password" value="<?php echo
$_POST['password']; ?>"><br>
Email: <input type="text" name="email" value="<?php echo $_POST['email'];
?>"><br>
First Name: <input type="text" name="f_name" value="<?php echo
$_POST['first_name']; ?>"><br>
Last Name: <input type="text" name="l_name" value="<?php echo
$_POST['last_name']; ?>"><br>
City: <input type="text" name="city" value="<?php echo $_POST['city'];
?>"><br>
State: <input type="text" name="state" value="<?php echo $_POST['state'];
?>"><br>
Hobbies/Interests: (choose at least one)<br>
<select name="hobbies[]" size="10" multiple>
<option value="Golfing"
<?php if (in_array("Golfing", $_POST['hobbies']))
echo " selected"; ?>>Golfing</option>
<option value="Hunting"
<?php if (in_array("Hunting", $_POST['hobbies']))
echo " selected"; ?>>Hunting</option>
<option value="Reading"
<?php if (in_array("Reading", $_POST['hobbies']))
echo " selected"; ?>>Reading</option>
<option value="Dancing"
<?php if (in_array("Dancing", $_POST['hobbies']))
echo " selected"; ?>>Dancing</option>
<option value="Internet"
<?php if (in_array("Internet", $_POST['hobbies']))
echo " selected"; ?>>Internet</option>
<option value="Flying"
<?php if (in_array("Flying", $_POST['hobbies'])) echo
" selected"; ?>>Flying</option>
<option value="Traveling"
<?php if (in_array("Traveling",
$_POST['hobbies'])) echo " selected"; ?>>Traveling</option>
<option value="Exercising"
<?php if (in_array("Exercising",
$_POST['hobbies'])) echo " selected"; ?>>Exercising</option>
<option value="Computers"
<?php if (in_array("Computers",
$_POST['hobbies'])) echo " selected"; ?>>Computers</option>
<option value="Other Than Listed"
<?php if (in_array("Other Than Listed",
$_POST['hobbies'])) echo " selected"; ?>>Other Than Listed</option>
</select><br><br>
<input type="submit" name="submit" value="Register"> <input
type="reset" value="Clear">
</form>
<?php
}
}
else
{
?>
Welcome to the registration page!<br>
The Username, Password, Email, First Name, and Last Name fields are required!
<form action="register.php" method="post">
Username: <input type="text" name="username"><br>
Password: <input type="password" name="password"><br>
Email: <input type="text" name="email"><br>
First Name: <input type="text" name="f_name"><br>
Last Name: <input type="text" name="l_name"><br>
City: <input type="text" name="city"><br>
State: <input type="text" name="state"><br>
Hobbies/Interests: (choose at least one)<br>
<select name="hobbies[]" size="10" multiple>
<option value="Golfing">Golfing</option>
<option value="Hunting">Hunting</option>
<option value="Reading">Reading</option>
<option value="Dancing">Dancing</option>
<option value="Internet">Internet</option>
<option value="Flying">Flying</option>
<option value="Traveling">Traveling</option>
<option value="Exercising">Exercising</option>
<option value="Computers">Computers</option>
<option value="Other Than Listed">Other Than Listed</option>
</select><br><br>
<input type="submit" name="submit" value="Register"> <input type="reset"
value="Clear">
</form>
<?php
}
?>
</body>
</html>
|
|

March 23rd, 2004, 05:12 PM
|
|
Authorized User
|
|
Join Date: Mar 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
also once the user is logged in and decides to update their information I get an undefined index submit starting with this line
if ($_POST['submit'] == "Update")
code:
<?php
// session_start();
include "auth_user.inc";
include "conn.inc.php";
?>
<html>
<head>
<title>Beginning PHP, Apache, MySQL Web Development</title>
</head>
<body>
<h1>Update Account Information</h1>
Here you can update your account information for viewing in your profile.<br><br>
<?php
if ($_POST['submit'] == "Update")
{
$query_update = "UPDATE user_info SET email = '" . $_POST['email'] . "', city
= '" . $_POST['city'] . "', state = '" . $_POST['state'] . "', hobbies =
'" . implode(", ", $_POST['hobbies']) . "' 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);
$hobbies = explode(", ", $row['hobbies'])
?>
<b>Your account information has been updated.</b><br>
<a href="user_personal.php">Click here</a> to return to your account.
<form action="update_account.php" method="post">
Email: <input type="text" name="email" value="<?php echo $row['email']; ?>"><br>
City: <input type="text" name="city" value="<?php echo $row['city']; ?>"><br>
State: <input type="text" name="state" value="<?php echo $row['state']; ?>"><br>
Hobbies/Interests: (choose at least one)<br>
<select name="hobbies[]" size="10" multiple>
<option value="Golfing"<?php if (in_array("Golfing", $hobbies)) echo " selected";
?>>Golfing</option>
<option value="Hunting"<?php if (in_array("Hunting", $hobbies)) echo " selected";
?>>Hunting</option>
<option value="Reading"<?php if (in_array("Reading", $hobbies)) echo " selected";
?>>Reading</option>
<option value="Dancing"<?php if (in_array("Dancing", $hobbies)) echo " selected";
?>>Dancing</option>
<option value="Internet"<?php if (in_array("Internet", $hobbies)) echo "
selected"; ?>>Internet</option>
<option value="Flying"<?php if (in_array("Flying", $hobbies)) echo " selected";
?>>Flying</option>
<option value="Traveling"<?php if (in_array("Traveling", $hobbies)) echo "
selected"; ?>>Traveling</option>
<option value="Exercising"<?php if (in_array("Exercising", $hobbies)) echo "
selected"; ?>>Exercising</option>
<option value="Computers"<?php if (in_array("Computers", $hobbies)) echo "
selected"; ?>>Computers</option>
<option value="Other Than Listed"<?php if (in_array("Other Than Listed",
$hobbies)) echo " selected"; ?>>Other Than Listed</option>
</select><br><br>
<input type="submit" name="submit" value="Update"> <input type="button"
value="Cancel" onclick="history.go(-1);">
</form>
<?php
}
else
{
$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);
$hobbies = explode(", ", $row['hobbies'])
?>
<form action="update_account.php" method="post">
Email: <input type="text" name="email" value="<?php echo $row['email']; ?>"><br>
City: <input type="text" name="city" value="<?php echo $row['city']; ?>"><br>
State: <input type="text" name="state" value="<?php echo $row['state']; ?>"><br>
Hobbies/Interests: (choose at least one)<br>
<select name="hobbies[]" size="10" multiple>
<option value="Golfing"<?php if (in_array("Golfing", $hobbies)) echo " selected";
?>>Golfing</option>
<option value="Hunting"<?php if (in_array("Hunting", $hobbies)) echo " selected";
?>>Hunting</option>
<option value="Reading"<?php if (in_array("Reading", $hobbies)) echo " selected";
?>>Reading</option>
<option value="Dancing"<?php if (in_array("Dancing", $hobbies)) echo " selected";
?>>Dancing</option>
<option value="Internet"<?php if (in_array("Internet", $hobbies)) echo "
selected"; ?>>Internet</option>
<option value="Flying"<?php if (in_array("Flying", $hobbies)) echo " selected";
?>>Flying</option>
<option value="Traveling"<?php if (in_array("Traveling", $hobbies)) echo "
selected"; ?>>Traveling</option>
<option value="Exercising"<?php if (in_array("Exercising", $hobbies)) echo "
selected"; ?>>Exercising</option>
<option value="Computers"<?php if (in_array("Computers", $hobbies)) echo "
selected"; ?>>Computers</option>
<option value="Other Than Listed"<?php if (in_array("Other Than Listed"
, $hobbies)) echo " selected"; ?>>Other Than Listed</option>
</select><br><br>
<input type="submit" name="submit" value="Update"> <input type="button"
value="Cancel" onclick="history.go(-1);">
</form>
<?php
}
?>
</body>
</html>
|
|

March 23rd, 2004, 05:32 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
|
|
Like I said in my previous post, PHP does not seem to be recieving the $_POST predefined variable....
This probably means that the index of $_POST that you requested (the part in the []) is not set. And this means that the page that was supposed to POST to the page that reads $_POST is not POSTing correctly....
----------
---Snib---
----------
<><
|
|

March 23rd, 2004, 05:33 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
|
|
Or it could mean you have an old PHP.....
What version are you using?
----------
---Snib---
----------
<><
|
Similar Threads
|
| Thread |
Thread Starter |
Forum |
Replies |
Last Post |
| Chapter11-ProposalManager.zip Password Protected ? |
ian |
BOOK: Professional SharePoint 2007 Development ISBN: 978-0-470-11756-9 |
2 |
August 27th, 2008 12:06 PM |
| Chapter11 page 400 |
asplundo |
BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 |
0 |
February 18th, 2008 09:29 AM |
| error in chapter11 postcard.php |
GOUR CHANDRA PAUL |
BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 |
0 |
December 7th, 2005 07:30 PM |
|
 |