View Full Version : PHP RPing
xangelo
12-08-2004, 11:05 PM
I've recently started a little project that uses PHP/mySQL to create a Role Play. So far i've run into a little problem. Im quite new to PHP and mySQL so it problem might be very basic...
1. How do I select information from a table?
EX:
Table Name=Users
Fields: 'users', 'password'
And I have a bunch of usernames and passwords. I basically want to know how I would go about creating a login script that checks the entered information in a form and matches it to a certain row in the table. (The Form will have Username and Password input fields). If the password and username entered is correct I want them to be redirected to a different page and if it is wrong I want the page to reload saying that they have entered the wrong password and that they should try again.
If someone could help me I would greatly appreciate it.
This should work:
<?php
$correct_location = "http://www.yahoo.com/";
mysql_connect("localhost", "cPUserName", "cPPass") or die(mysql_error());
mysql_select_db("yourDBName") or die(mysql_error());
$inUser = $_POST['Username'];
$inPass = $_POST['Password'];
$result = mysql_query("SELECT * FROM `Users` WHERE `users` = '$inUser' AND `password` = '$inPass') or die(mysql_error());
mysql_close();
if (mysql_num_rows($result) == 0)
{
echo "Incorrect Password. Please go back.";
}
else
{
echo "Correct!<br /><script>document.location = $correct_location;</script><noscript><a href='$correct_location'>Click here to continue.</a></noscript>";
}
?>
Edit to suit your needs, of course... :)
xangelo
12-09-2004, 02:29 AM
WoW Thanks! I just hope this works!
EDIT:
I keep getting the following error:
Parse error: parse error, unexpected T_STRING in /home/theboxt/public_html/rp/pages/loginprocess.php on line 20
My line 20 is:
echo "Incorrect Password. Please go back.";
And I dont see a problem...
reid315
12-09-2004, 04:01 AM
nomrally your line twenty and the server's ine 20 are off. somtimes they mean line 36 or line 14. T_STRING error occurs normally when a function or variable is mispelled or a semi colon is missing. check again. -- did you find it?
Ah I found the problem. I forgot the " ending semicolon after the query. So try this:
<?php
$correct_location = "http://www.yahoo.com/";
mysql_connect("localhost", "cPUserName", "cPPass") or die(mysql_error());
mysql_select_db("yourDBName") or die(mysql_error());
$inUser = $_POST['Username'];
$inPass = $_POST['Password'];
$result = mysql_query("SELECT * FROM `Users` WHERE `users` = '$inUser' AND `password` = '$inPass'") or die(mysql_error());
mysql_close();
if (mysql_num_rows($result) == 0)
{
echo "Incorrect Password. Please go back.";
}
else
{
echo "Correct!<br /><script>document.location = $correct_location;</script><noscript><a href='$correct_location'>Click here to continue.</a></noscript>";
}
?>Sorry :P
xangelo
12-10-2004, 03:29 AM
THANKS!! That worked.. I hate to bother you again.. but now this script comes up with a T_STRING ERROR on line 17. I believe it has something to do with my horribe knowledge of PHP/mySQL...
<html>
<head><title>Register</title>
<link rel=stylesheet href="http://thebox.titaniumhosting.com/rp/require/style.css" type=text/css>
<html>
<head>
<title>Quick RP</title>
<link rel=stylesheet href="http://thebox.titaniumhosting.com/rp/require/style.css" type=text/css>
</head>
<body>
<table width=100% cellpadding=3 cellspacing=3 frame=void>
<tr>
<th width=100% colspan=3>
<?php require("require/dbconn.php");
$result1=mysql_query("SELECT username FROM `rpprofiles` WHERE `users` = '$inUser' AND `password` = '$inPass') or die(mysql_error());
mysql_close();
$result2=mysql_query("SELECT str FROM `rpprofiles` WHERE `users` = '$inUser' AND `password` = '$inPass') or die(mysql_error());
mysql_close();
$result3=mysql_query("SELECT def FROM `rpprofiles` WHERE `users` = '$inUser' AND `password` = '$inPass') or die(mysql_error());
mysql_close();
echo "Username: ". $result1;
echo " | ";
echo "Strength: ". $result2;
echo " | ";
echo "Defence: ". $result3
?>
<div align=right>
<?php
$today = date("F j, Y, g:i a");
?>
</div>
</th>
</tr>
<tr>
<td width=18%>
<?php include("require/menu.php"); ?>
</td>
<td width=41%>
<?php include("stat.php") ?>
</td>
<td width=41%>
<?php include("avatar.php"); ?>
</td>
</tr>
</table>
</body>
<html>
mahangee
12-10-2004, 06:47 AM
First of all in future tell us which line is 17 by commenting on it. Second of all non of your queries had the ending " $result1=mysql_query("SELECT username FROM `rpprofiles` WHERE `users` = '$inUser' AND `password` = '$inPass'") or die(mysql_error());
mysql_close();
$result2=mysql_query("SELECT str FROM `rpprofiles` WHERE `users` = '$inUser' AND `password` = '$inPass'") or die(mysql_error());
mysql_close();
$result3=mysql_query("SELECT def FROM `rpprofiles` WHERE `users` = '$inUser' AND `password` = '$inPass'") or die(mysql_error());
mysql_close();
xangelo
12-13-2004, 05:22 AM
Thank you!
vBulletin® v3.7.0, Copyright ©2000-2008, Jelsoft Enterprises Ltd.