Think the problem is a config thing. Just installed WAMP

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
peapod
Forum Newbie
Posts: 9
Joined: Wed Jul 22, 2009 11:30 pm

Think the problem is a config thing. Just installed WAMP

Post by peapod »

I just started working on WAMP on my vista machine. I have had all my scripts working perfectly in my schools server, but on this setup some things are not working as they should.

I have a login page that is suppose to send a message ex.("You forgot to enter a user name"/)to the user when no data is in the text fields and the user has clicked submit.

The Part where the comment says:// Check for an email address. and // Check for an password is the code that is not doing anything when there should be text displayed on the page.


please help
I'm showing all the code even though I had it working fine on another server.
Code is below:


<?php # Script 9.3 - login.php (2nd version after Script 9.1)
// Send NOTHING to the Web browser prior to the setcookie() lines!

// Check if the form has been submitted.
if (isset($_POST['submitted'])) {

require_once ('mysql_connect_inc.php'); // Connect to the db.

$errors = array(); // Initialize error array.

// Check for an email address.
if (empty($_POST['userName'])) {
$errors[] = 'You forgot to enter your user name.';
} else {
$u = escape_data($_POST['userName']);
}

// Check for a password.
if (empty($_POST['password'])) {
$errors[] = 'You forgot to enter your password.';
} else {
$p = escape_data($_POST['password']);
}

if (empty($errors)) { // If everything's OK.

/* Retrieve the user_id and first_name for
that email/password combination. */
$query = "SELECT * FROM User WHERE userName='$u' AND password=MD5('$p')";
$result = @mysql_query ($query); // Run the query.
$row = mysql_fetch_array ($result, MYSQL_NUM); // Return a record, if applicable.

if ($row) { // A record was pulled from the database.

//Set the cookies & redirect.
setcookie ('userID', $row[0], time()+3600, '/', '', 0);
setcookie ('userName', $row[4], time()+3600, '/', '', 0);
setcookie ('password', $row[5], time()+3600, '/', '', 0);

if ($row) {
//set the session.
session_start();
$_SESSION['sessuserID']=$row[0];
$_SESSION['sessfirstName']=$row[1];
$_SESSION['sesslastName']=$row[2];
$_SESSION['sessemail']=$row[3];
$_SESSION['sesslastVisit']=$row[7];



// Redirect the user to the loggedin.php page.
// Start defining the URL.
$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
// Check for a trailing slash.
if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) {
$url = substr ($url, 0, -1); // Chop off the slash.
}
}
// Add the page.
$url .= '/loggedin.php';

header("Location: $url"winking smiley;
exit(); // Quit the script.

} else { // No record matched the query.
$errors[] = 'The email address and password entered do not match those on file.'; // Public message.
$errors[] = mysql_error() . '<br /><br />Query: ' . $query; // Debugging message.
}



mysql_close(); // Close the database connection.

} else { // Form has not been submitted.

$errors = NULL;

} // End of the main Submit conditional.
} // End of if (empty($errors)) IF.
// Begin the page now.
$page_title = 'Login';
include ('head.inc');

if (!empty($errors)) { // Print any error messages.
echo '<h1 id="mainhead">Error!</h1>
<p class="error">The following error(s) occurred:<br />';
foreach ($errors as $msg) { // Print each error.
echo " - $msg<br />\n";
}
echo '</p><p>Please try again.</p>';
}

// Create the form.
?>
<h2>Login</h2>
<form action="login.php" method="post">
<p>User Name: <input type="text" name="userName" size="20" maxlength="40" /> </p>
<p>Password: <input type="password" name="password" size="20" maxlength="20" /></p>
<p><input type="submit" name="submit" value="Login" /></p>
<input type="hidden" name="submitted" value="TRUE" />
</form>
Not Registered &#63; &nbsp;<a href = "regUser.php">Click here</a>
<?php
include ('foot.inc');
?>
Posted by: pod (---.hsd1.wa.comcast.net)
Date: November 27, 2009 11:22PM

I just started working on WAMP on my vista machine. I have had all my scripts working perfectly in my schools server, but on this setup some things are not working as they should.

I have a login page that is suppose to send a message ex.("You forgot to enter a user name"/)to the user when no data is in the text fields and the user has clicked submit.

The Part where the comment says:// Check for an email address. and // Check for an password is the code that is not doing anything when there should be text displayed on the page.


please help
Code is below:


<?php # Script 9.3 - login.php (2nd version after Script 9.1)
// Send NOTHING to the Web browser prior to the setcookie() lines!

// Check if the form has been submitted.
if (isset($_POST['submitted'])) {

require_once ('mysql_connect_inc.php'); // Connect to the db.

$errors = array(); // Initialize error array.

// Check for an email address.
if (empty($_POST['userName'])) {
$errors[] = 'You forgot to enter your user name.';
} else {
$u = escape_data($_POST['userName']);
}

// Check for a password.
if (empty($_POST['password'])) {
$errors[] = 'You forgot to enter your password.';
} else {
$p = escape_data($_POST['password']);
}

if (empty($errors)) { // If everything's OK.

/* Retrieve the user_id and first_name for
that email/password combination. */
$query = "SELECT * FROM User WHERE userName='$u' AND password=MD5('$p')";
$result = @mysql_query ($query); // Run the query.
$row = mysql_fetch_array ($result, MYSQL_NUM); // Return a record, if applicable.

if ($row) { // A record was pulled from the database.

//Set the cookies & redirect.
setcookie ('userID', $row[0], time()+3600, '/', '', 0);
setcookie ('userName', $row[4], time()+3600, '/', '', 0);
setcookie ('password', $row[5], time()+3600, '/', '', 0);

if ($row) {
//set the session.
session_start();
$_SESSION['sessuserID']=$row[0];
$_SESSION['sessfirstName']=$row[1];
$_SESSION['sesslastName']=$row[2];
$_SESSION['sessemail']=$row[3];
$_SESSION['sesslastVisit']=$row[7];



// Redirect the user to the loggedin.php page.
// Start defining the URL.
$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
// Check for a trailing slash.
if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) {
$url = substr ($url, 0, -1); // Chop off the slash.
}
}
// Add the page.
$url .= '/loggedin.php';

header("Location: $url"winking smiley;
exit(); // Quit the script.

} else { // No record matched the query.
$errors[] = 'The email address and password entered do not match those on file.'; // Public message.
$errors[] = mysql_error() . '<br /><br />Query: ' . $query; // Debugging message.
}



mysql_close(); // Close the database connection.

} else { // Form has not been submitted.

$errors = NULL;

} // End of the main Submit conditional.
} // End of if (empty($errors)) IF.
// Begin the page now.
$page_title = 'Login';
include ('head.inc');

if (!empty($errors)) { // Print any error messages.
echo '<h1 id="mainhead">Error!</h1>
<p class="error">The following error(s) occurred:<br />';
foreach ($errors as $msg) { // Print each error.
echo " - $msg<br />\n";
}
echo '</p><p>Please try again.</p>';
}

// Create the form.
?>
<h2>Login</h2>
<form action="login.php" method="post">
<p>User Name: <input type="text" name="userName" size="20" maxlength="40" /> </p>
<p>Password: <input type="password" name="password" size="20" maxlength="20" /></p>
<p><input type="submit" name="submit" value="Login" /></p>
<input type="hidden" name="submitted" value="TRUE" />
</form>
Not Registered &#63; &nbsp;<a href = "regUser.php">Click here</a>
<?php
include ('foot.inc');
?>
peapod
Forum Newbie
Posts: 9
Joined: Wed Jul 22, 2009 11:30 pm

Re: Think the problem is a config thing. Just installed WAMP

Post by peapod »

Ok, I figured out a fix for this. I am not sure why my wamp server is balking on this maybe it has to do something with the configuration.

In case someone else is having the same problem this is what I did.

I had to take out the else statement or simply comment out. else from script shown below.


} else { // Form has not been submitted.

$errors = NULL;
Post Reply