...

View Full Version : script error



cheat
02-05-2007, 09:42 PM
i have been given teh scripts for a mmorpg game. i have the scripts uploaded and the database set up however i keep getting a error on the register.

e.g. i try registering using signup.php, it goes to complete.php and says:


Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/game/public_html/complete.php on line 66
Unsucessful sign-up please try again


this is where the error is supposed to be located:
lse {
$sql = "INSERT INTO users VALUES ('', '$username', password('$_POST[password]'), '$_POST[full_name]', '$email', '0', '0', '500', 'none', '100', '0', '0', '0', '0', 'alive', '0', '0', '0', '$time', '0', '$country', '0','0', '0', 'no', '', '1', '$drug_prices', '0', 'none', 'middle.jpg', 'none', '$_POST[username]', '0', '0', '0', '0', '0', '1')";
$_SESSION["name"] = $_POST["username"];
if (mysql_query($sql, $conn)) {
echo "Succesful signup!<br><a href='index.php'>Sign in</a>";
} else {
echo "Unsucessful sign-up please try again";
}

this is line 66:
if (mysql_query($sql, $conn)) {

.......................
can someone help me with this plz

koyama
02-05-2007, 10:12 PM
You have many columns. This makes it likely that you could have missed a field?

Try to do some debugging. This should give some indication where the error might be.


else {
$sql = "INSERT INTO users VALUES ('', '$username', password('$_POST[password]'), '$_POST[full_name]', '$email', '0', '0', '500', 'none', '100', '0', '0', '0', '0', 'alive', '0', '0', '0', '$time', '0', '$country', '0','0', '0', 'no', '', '1', '$drug_prices', '0', 'none', 'middle.jpg', 'none', '$_POST[username]', '0', '0', '0', '0', '0', '1')";

echo $sql;
mysql_query($sql, $conn) or die(mysql_error());
}

$_SESSION["name"] = $_POST["username"];
/*
if (mysql_query($sql, $conn)) {
echo "Succesful signup!<br><a href='index.php'>Sign in</a>";
} else {
echo "Unsucessful sign-up please try again";
}
*/

cheat
02-05-2007, 10:33 PM
the script i got came with a database backup

koyama
02-05-2007, 10:49 PM
What have you tried? If you're not sure what you are doing, start changing line 66 to this and tell us what you see:


if (mysql_query($sql, $conn) or die(mysql_error())) {

cheat
02-05-2007, 11:04 PM
im still quite new to php and with sql i only just started learning

cheat
02-05-2007, 11:06 PM
i put that code in and this came up

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/game/public_html/complete.php on line 66

cheat
02-05-2007, 11:08 PM
i dont know if this makes it any easier but this is the full script for complete.php

<?php
session_start();
include("conn.php");
$country = $_POST[location];
if ($country == "England") {
$drug_prices = "8-13-21-9-106-36-32-103-159";
} elseif ($country == "France") {
$drug_prices = "12-54-28-2-129-29-19-97-147";
} elseif ($country == "Italy") {
$drug_prices = "10-26-54-19-97-23-25-89-153";
} elseif ($country == "Germany") {
$drug_prices = "11-47-13-121-39-12-93-149-131";
} elseif ($country == "China") {
$drug_prices = "7-38-17-22-152-27-14-95-144";
} elseif ($country == "Russia") {
$drug_prices = "4-41-33-7-122-65-21-94-120";
} elseif ($country == "Mexico") {
$drug_prices = "11-40-28-14-136-21-81-100-160";
} elseif ($country == "Japan") {
$drug_prices = "9-45-22-63-101-30-100-87-152";
} elseif ($country == "Australia") {
$drug_prices = "21-33-27-6-100-35-22-88-133";
}
?>
<html>
<head>
<title>Sign Up</title>
<style type="text/css">
<!--
body,td,th {
color: #FFFFFF;
}
body {
background-color: #000000;
}
a:link {
color: #00FFFF;
text-decoration: underline;
}
a:visited {
text-decoration: underline;
color: #00FFFF;
}
a:hover {
text-decoration: none;
color: #FFFFFF;
}
a:active {
text-decoration: underline;
}
-->
</style>
</head>
<body>
<?php
$time = time();
$email = $_POST["email"];
$user = str_replace(" ", "_", $_POST[username]);
$username = strtolower($user);
$user_exist = mysql_query("SELECT * FROM users WHERE username='$username'") or die(mysql_error());
if (mysql_num_rows($user_exist) == "1") {
echo "Username already in use";
} else {
$sql = "INSERT INTO users VALUES ('', '$username', password('$_POST[password]'), '$_POST[full_name]', '$email', '0', '0', '500', 'none', '100', '0', '0', '0', '0', 'alive', '0', '0', '0', '$time', '0', '$country', '0','0', '0', 'no', '', '1', '$drug_prices', '0', 'none', 'middle.jpg', 'none', '$_POST[username]', '0', '0', '0', '0', '0', '1')";
$_SESSION["name"] = $_POST["username"];
if (mysql_query($sql, $conn) or die(mysql_error())) {
echo "Succesful signup!<br><a href='index.php'>Sign in</a>";
} else {
echo "Unsucessful sign-up please try again";
}
}
?>
</body>
</html>




p.s sorry to anyone who finds posting the full script annoying;

ralph l mayo
02-05-2007, 11:11 PM
Sounds like the problem is conn.php failing to make a legitimate connection to the mysql database. Check that your details match there.. username/password/host/etc

plz 2b reading some sticky threads ok thx

cheat
02-05-2007, 11:13 PM
ok lol thanks, ive been trying for 4 days to get this working lol

cheat
02-05-2007, 11:14 PM
<?
$host = 'localhost';
$user = 'username';
$pass = 'password';
$data = 'database';
mysql_connect($host, $user, $pass);
mysql_select_db($data);
?>

details removed

cheat
02-05-2007, 11:17 PM
ok i have just changed the conn to

<?php

$conn = mysql_connect("localhost", "user", "pass");

mysql_select_db("database", $conn);

?>

and it came up with this error

Column count doesn't match value count at row 1

koyama
02-05-2007, 11:31 PM
So what does your table 'users' look like?

cheat
02-06-2007, 03:15 PM
its phpmyadmin 4.1

Mhtml
02-06-2007, 03:56 PM
What koyama meant was, what is the structure of the table, what fields does it have?

Also, whoever gave you the script isn't such a great programmer. You should always error check your code! ALWAYS!


<?php
$conn = mysql_connect("localhost", "user", "pass");
if(!$conn){
die("Unable to make connection to database.<br/>MySQL Says:".mysql_error());
}
mysql_select_db("database", $conn);
?>
You could have saved a lot of time to begin with, if only the conn.php file contained 3 more lines.

Obviously you would realistically handle errors in a different fashion in real-world applications but that will help you debug at least!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum