Php Mmorpg
#1
Posted 12 May 2007 - 03:56 AM
#2
Posted 12 May 2007 - 04:13 AM
#3
Posted 12 May 2007 - 01:47 PM
#4
Posted 12 May 2007 - 03:13 PM
This is a general database design strategy for many-to-many relationships that you can use all over the place.
#5
Posted 13 May 2007 - 01:53 AM
#6
Posted 13 May 2007 - 10:17 AM
I reckomend that you read some basic database design tutorials, since it's easy to do bad design decisions if you don't know exactly why they are bad.
#7
Posted 07 June 2007 - 05:12 AM
else{
$cxn = mysql_connect($host,$username,$pass);
$db_selected = mysql_select_db("users", $cxn);
$sql = "SELECT user_name FROM $table_name WHERE user_name='$user'";
$result = mysql_query($sql,$cxn);
$num = mysql_num_rows($result);
I consistently get a PHP error like the following:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in c:\program files\easyphp1-8\www\lotmo\register.php on line 42
Which corresponds to the line with mysql_num_rows in the script. Can somebody please tell me what is going on? I stated all the connection variables earlier in the script.
#8
Posted 07 June 2007 - 09:18 AM
Quote
#9
Posted 07 June 2007 - 09:44 AM
sql: SELECT user_name FROM users WHERE user_name='' error: No database selected
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in c:\program files\easyphp1-8\www\lotmo\register.php on line 43
But I already selected a database with my mysql_select_db function. Or did I do something wrong?
#10
Posted 07 June 2007 - 12:58 PM
#11
Posted 07 June 2007 - 01:27 PM
#12
Posted 07 June 2007 - 01:55 PM
#13
Posted 07 June 2007 - 01:57 PM
session_start();
include "includes/pass.inc";
$user = $_POST['username'];
$passwd = $_POST['password'];
$rpasswd = $_POST['rpassword'];
$email = $_POST['email'];
$table_name = "users";
if (strcasecmp($passwd, $rpasswd) !== 0) {
include "includes/header.inc";
echo "Passwords do not match! Please try again!";
include "pages/register.inc";
include "includes/footer.inc";
}
else{
if($user = ""){
include "includes/header.inc";
echo "The user field has been left blank! Please <a href='index.php?page=register'>try again</a>.";
include "includes/footer.inc";
}
elseif($passwd = ""){
include "includes/header.inc";
echo "The password field has been left blank! Please <a href='index.php?page=register'>try again</a>.";
include "includes/footer.inc";
}
elseif($email = ""){
include "includes/header.inc";
echo "The email field has been left blank! Please <a href='index.php?page=register'>try again</a>.";
include "includes/footer.inc";
}
elseif(strlen($user) > 30){
include "includes/header.inc";
echo "Your username is too long! Please <a href='index.php?page=register'>shorten it</a>.";
include "includes/footer.inc";
}
else{
$cxn = mysql_connect($host,$username,$pass);
$db_selected = mysql_select_db("users",$cxn);
$sql = "SELECT 'user_name' FROM $table_name WHERE 'user_name'='$user'";
$result = mysql_query($sql,$cxn);
$number = mysql_num_rows($result);
if($number > 0){
include "includes/header.inc";
echo "Username already exists! Please <a href='index.php?page=register'>try again</a>.";
include "includes/footer.inc";
}
else{
$md5pass = md5($passwd);
$q = "INSERT INTO users VALUES ('$username','$md5pass','$email')";
return mysql_query($q,$cxn);
include "includes/header.inc";
echo "Welcome to <strong>Work in Progress Game</strong>, " . $username . "!<br>";
include "includes/footer.inc";
}
}
}
?>
Here is the full text of the script for reference. I'm a beginner at PHP so I sorta overdosed on the elseifs.
#14
Posted 07 June 2007 - 04:05 PM
http://wsframework.c...1.2&view=markup
http://wsframework.c...1.3&view=markup
#15
Posted 07 June 2007 - 04:06 PM
#16
Posted 07 June 2007 - 04:26 PM
#17
Posted 08 June 2007 - 04:32 AM
This code...
"SELECT 'user_name' FROM $table_name WHERE 'user_name'='$user'";...would simply return an empty result, since the WHERE clausule now compares the string "user_name" to whatever is in the variable $user.
Don't make changes like that if you don't understand what they do, and why you make them. Coding is not about randomly changing stuff and hoping they will suddenly be right. You need to figure out what is wrong, and fix it.
The SQL that you printed earlier was clearly missing a user name in it. That means the input variable to the script is not valid. Solve that problem first. (Usually, it would be fine to check that in the beginning of the script and just die() with a short message if it is not available. I guess you send the username from a form in another file, so unless the user is actually trying to break your code, it should work.)
The error message indicates that your database was'nt selected. You wrote that you have checked that, but I must say I believe the error message.
Put another
print(mysql_error());immedeately after the call to mysql_select_db(), and you might find out was went wrong.
I should also take the opportunity to point out that you have a serious flaw in your code: SQL injection! The variable $user_name is just taken from the $_POST data without any validation, and sent into your SQL without even escaping it. If someone write this...
'; DROP DATABASE users;...as their username when they log on, they can delete your database. Allways treat data from the outside of the script very suspiciously. The username should be matched against a regular expression to see if it's valid, or escaped before used in the SQL.
#18
Posted 08 June 2007 - 11:29 AM
#19
Posted 08 June 2007 - 04:31 PM
sql: SELECT user_name FROM users WHERE user_name='' error: No database selectedIt shows a blank string for the username, showing your $user variable was empty.
By the way, you don't need to hold on to the $cxn variable and pass it to every function. If you call mysql_connect it will set the default connection, which will be used by the other functions.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











