PHP Logged In As:

Permabanned
Joined
22 Apr 2007
Posts
1,805
Me again,

I have a login which checks username and password stored in a MySQL db.

When the user logs in and gets redirected to the right page, I'd like to show a

"You are logged in as: xxxxxxxxxx"

thingy

Any ideas?
 
No thats it. Cool. Thanks

One other thing. I have a field in a MySQL table that is classed as Unique. When a form submits to the MySQL database (with PHP) how can I get it to check for uniqueness, and, if its not unique, display something on the site to tell the user that?

If you know, that would be great.
 
Cool thanks. So under //Error Logic you'd have something like

echo 'sorry, blah blah already exits', etc, etc?

Also, where you have:

($_POST['unique_value']);

does that have to be the field that is unique? (in my case, hotel_name)
 
Last edited:
Cool, thanks marc

I'll give this a go. Funny I was just reading up about HTMLentities on Tizag.

thanks again, I'll reply if I have any problems.
 
ok, I've got this and can't seem to find out whats wrong. Perhaps its a has of lots of different code areas.

Code:
<?php
session_start();
if(!$_SESSION['username']) {
       //not logged in. redirect to login page
       header("Location: login.php");
       exit;
}

$address = "localhost";
$username = "myuser";
$password = "mypass";
$database = "mydb";

mysql_connect($address,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">


<head>

</head>

<body>


<?php
echo "<strong>You are logged in as:</strong> " . $_SESSION['username'];
?>


<p>Please answer all questions. For blank fields, please enter <strong>N/A</strong>.</p>
<p>Fields marked with an asterisk (<span class="warning">*</span>) must be completed.</p>

<?php
if (!isset($_POST['submit'])) {
?>

<form action="" method="post">

//HTML FORM HERE
</form>



<?php

$uniqueValue = mysql_real_escape_string($_POST['hotel_name']);
$query = "SELECT `hotel_name` FROM `survey` WHERE `hotel_name` = '$uniqueValue'";
$result = mysql_query($query);
$rowCount = mysql_num_rows($result);

if ($rowCount > 0)
{
    // Error logic.
	echo '<input type="text" name="hotel_name" value="'.htmlentities($_POST['hotel_name']).'">';
}
else
{
    // Carry on with the script.
}




} else {

$hotel_name = mysql_real_escape_string($_POST['hotel_name']);
$contact = mysql_real_escape_string($_POST['contact_name']);
$telephone = mysql_real_escape_string($_POST['telephone']);
$do = mysql_real_escape_string($_POST['do']);
$have = mysql_real_escape_string($_POST['have']);



mysql_query("INSERT INTO `survey` (hotel_name, contact, telephone, do, have) VALUES 

('$hotel_name','$contact','$telephone','$do','$have')");
echo "Thank you! Your survey is now complete and the information has been submitted";
}


mysql_close();

?>

</body>
</html>

When I hit submit, the "thank you your data has been entered" message appears, but nothing enters the Database.

NOTE:(I am forcing the same username as I already have stored in the DB, if I create a unique entry, all is well).

EDIT:

and what about this......


Quote:
My last php question ever!

lies.

Teehee :p
 
Cool,

Ok, two things:

1), I'm getting this error when the page loads now:

Code:
Parse error: syntax error, unexpected $end in survey.php on line 72

2) in my form I have drop down boxes eg
Code:
<select name="do">
<option value="Yes" selected="selected">Yes</option>
<option value="No">No</option>
</select></p>

how do I code that wih the html entities?

Thanks again
 
Last edited:
:( Can't find it

EDIT: OOOOOOO, is it this bit?

Code:
<?php
session_start();
if(!$_SESSION['username']) {
       //not logged in. redirect to login page
       header("Location: hotel-login.php");
       exit;
}

$address = "localhost";
$username = "dsf";
$password = "sdf";
$database = "sdf";

mysql_connect($address,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

if (isset($_POST['submit'])) {
	$hotel_name = mysql_real_escape_string($_POST['hotel_name']);
	$contact = mysql_real_escape_string($_POST['contact_name']);
	$telephone = mysql_real_escape_string($_POST['telephone']);
	$do = mysql_real_escape_string($_POST['do']);
	$have = mysql_real_escape_string($_POST['have']);
	
	$query = "SELECT `hotel_name` FROM `survey` WHERE `hotel_name` = '$hotel_name'";
	$result = mysql_query($query);
	if (mysql_num_rows($result) == 1) {
		$message = 'That hotel name is already in the database. Please use another.';
	} else {
		mysql_query("INSERT INTO `survey` (hotel_name, contact, telephone, do, have) VALUES 

('$hotel_name','$contact','$telephone','$do','$have')");
		$message = "Thank you! Your survey is now complete and the information has been submitted";
	}
	mysql_close();
?>

the { is open, but doesnt seem to close again in the line:

if (isset($_POST['submit'])) {

Double Edit: YES Get in!!!!!!!!
 
Last edited:
Ok, thanks

Back to what marc2003 was explaining:

I have a load of questions where the answers are either 'Yes' or 'No' which should be displayed in a drop down box.

I define the variables in php as:

<?php
$Yes = "Yes";
$No = "No";
?>

How do I implement that in to the HTML form?
 
Back
Top Bottom