|
You last visited: Today at 15:58
Advertisement
helping php iss users with mssql connect
Discussion on helping php iss users with mssql connect within the Shaiya PServer Development forum part of the Shaiya Private Server category.
09/29/2011, 13:24
|
#16
|
elite*gold: 0
Join Date: Sep 2011
Posts: 140
Received Thanks: 147
|
that worked... wow thank you so much!
|
|
|
09/29/2011, 14:30
|
#17
|
elite*gold: 0
Join Date: Feb 2010
Posts: 675
Received Thanks: 240
|
char ress
sweet sweet black. can you please do this one too?
relay could use it.. thanks for the good work.. on the pvp rank
<?php
function mssql_escape_string($data) {
if(!isset($data) or empty($data)) return '';
if(is_numeric($data)) return $data;
$non_displayables = array(
'/%0[0-8bcef]/', // url encoded 00-08, 11, 12, 14, 15
'/%1[0-9a-f]/', // url encoded 16-31
'/[\x00-\x08]/', // 00-08
'/\x0b/', // 11
'/\x0c/', // 12
'/[\x0e-\x1f]/' // 14-31
);
foreach($non_displayables as $regex)
$data = preg_replace($regex,'',$data);
$data = str_replace("'","''",$data);
return $data;
}
$host = '127.0.0.1';
$dbuser = 'Shaiya';
$dbpass = 'Shaiya123';
$class = array(0 => 'Warrior',1=>'Guardian',2=>'Assasin',3=>'Hunter',4 =>'Pagan',5=>'Oracle',
6 => 'Fighter',7=>'Defender',8=>'Ranger',9=>'Archer',10 =>'Mage',11=>'Priest');
$link = mssql_connect($host,$dbuser,$dbpass) or die("Cannot connect to MSSQL server");
$login = isset($_POST['username']) ? mssql_escape_string(trim($_POST['username'])) : '';
$pass = isset($_POST['password']) ? mssql_escape_string(trim($_POST['password'])) : '';
$toon = isset($_POST['char']) ? mssql_escape_string(trim($_POST['char'])) : '';
if (isset($_POST['submit']))
{
if ( strlen($login) < 1)
die ("User Name too short");
if ( strlen($pass) < 1)
die ("Password too short.");
$res = mssql_query("SELECT UserID FROM [PS_userdata].[dbo].[Users_Master] WHERE UserID = '$login' AND Pw = '$pass'");
if (mssql_num_rows($res)==0)
{
die ("Username/Password is incorrect");
}
else
{
$res2 = mssql_query("SELECT umg.Country, c.Family, c.CharName, c.CharID, c.Job, c.Level FROM [PS_GameData].[dbo].[UserMaxGrow] AS umg
INNER JOIN [PS_GameData].[dbo].[Chars] AS c ON
umg.UserUID = c.UserUID WHERE c.UserID = '$login' AND c.Del=1");
if (mssql_num_rows($res2)==0)
echo "Account does not contain any dead characters.";
else
{
echo "<form action=\"".$_SERVER['PHP_SELF']."\" method=\"POST\">Select toon to resurrect :<br />
<input type=\"hidden\" name=\"username\" value=\"$login\">
<table cellspacing=1 cellpadding=2 border=1 style=\"border-style:hidden;\">
<tr><td>Select</td><td>CharName</td><td>Class</td><td>Level</td></tr>";
while ($chars = mssql_fetch_array($res2))
{
if($chars['Country'] == 0){
if($chars['Family'] == 0 || $chars['Family'] == 1){
echo "<tr>
<td><input type=\"radio\" name =\"char\" value=\"".$chars['CharName'].",".$chars['CharID']."\"></td>
<td>".$chars[2]."</td><td>".$class[$chars[4]+6]."</td>
<td>".$chars[5]."</td>
</tr>";
}
}
else if($chars['Country'] == 1){
if($chars['Family'] == 2 || $chars['Family'] == 3){
echo "<tr>
<td><input type=\"radio\" name =\"char\" value=\"".$chars['CharName'].",".$chars['CharID']."\"></td>
<td>".$chars[2]."</td><td>".$class[$chars[4]]."</td>
<td>".$chars[5]."</td>
</tr>";
}
}
}
echo "</table><input type=\"submit\" value=\"Submit\" name=\"submit2\" /></form>";
}
}
}
else if (isset($_POST['submit2']))
{
$slot=-1;
mssql_select_db("PS_GameData", $link);
$res1 = mssql_query("
SELECT MIN(Slots.Slot) AS OpenSlot FROM
(SELECT 0 AS Slot UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4) AS Slots
LEFT JOIN
(SELECT c.Slot
FROM PS_UserData.dbo.Users_Master AS um
INNER JOIN PS_GameData.dbo.Chars AS c ON c.UserUID = um.UserUID
WHERE um.UserID = '$login'
AND c.Del = 0) AS Chars ON Chars.Slot = Slots.Slot
WHERE Chars.Slot IS NULL");
$slot=mssql_fetch_array($res1);
$toon2 = explode(',',$toon);
if($slot[0]>-1 && $slot[0]<5){
mssql_query("UPDATE dbo.Chars SET Del=0, Slot=$slot[0], Map=42, PosX=63 , PosZ=57, DeleteDate=NULL WHERE CharID = $toon2[1]");
echo "Successfully resurrected <br /> Login = $login<br />Slot = ".($slot[0]+1)."<br />Char = $toon2[0]";
}
else
echo "No slots avaliable";
}
else {
?>
<html>
<head>
<title>Character Ressurection</title></head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
<fieldset style="font:100% trebuchet ms;width:100px;">
<legend >Resurrection Form </legend>
<font face="Trebuchet MS">
<table>
<tr>
<font size=1><i>*Toon will be resurrected in an avaliable free slot.</i></font>
</tr>
<tr>
<td>Account Login:</td><td> <input type="text" name="username" maxlength=12 /></td>
</tr>
<tr>
<td>Account Password:</td><td><input type="password" name="password" maxlength=12/></td>
</tr>
</font>
</table>
<input type="submit" value="Submit" name="submit" />
</fieldset>
</form>
</body>
</html>
<?php
}
?>
|
|
|
09/30/2011, 02:24
|
#18
|
elite*gold: 0
Join Date: Sep 2010
Posts: 520
Received Thanks: 1,289
|
Quote:
Originally Posted by Svinseladden
sweet sweet black. can you please do this one too?
relay could use it.. thanks for the good work.. on the pvp rank
|
-Snipped non-working code-
I'm on my laptop, which lacks a webserver for me to test it on. If for some reason it doesn't work, let me know, and I'll redo it on my desktop.
|
|
|
09/30/2011, 07:54
|
#19
|
elite*gold: 0
Join Date: Feb 2010
Posts: 675
Received Thanks: 240
|
sorry to say. it don't work. this comes up in the error logg:
[30-Sep-2011 08:50:42] PHP Parse error: syntax error, unexpected T_FOREACH, expecting ')' in C:\inetpub\wwwroot\resschar.php on line 14
anyway i love you right now. finaly one that can and will help us with the convertion
|
|
|
09/30/2011, 08:57
|
#20
|
elite*gold: 0
Join Date: Sep 2010
Posts: 520
Received Thanks: 1,289
|
My bad! I spotted the error immediately.
PHP Code:
<?php function mssql_escape_string($data) { if (!isset($data) or empty($data)) return ''; if (is_numeric($data)) return $data; $non_displayables = array('/%0[0-8bcef]/', // url encoded 00-08, 11, 12, 14, 15 '/%1[0-9a-f]/', // url encoded 16-31 '/[\x00-\x08]/', // 00-08 '/\x0b/', // 11 '/\x0c/', // 12 '/[\x0e-\x1f]/'); // 14-31 foreach ($non_displayables as $regex) $data = preg_replace($regex, '', $data); $data = str_replace("'", "''", $data); return $data; } $host = '127.0.0.1'; $dbuser = 'Shaiya'; $dbpass = 'Shaiya123'; $class = array(0 => 'Warrior', 1 => 'Guardian', 2 => 'Assasin', 3 => 'Hunter', 4 => 'Pagan', 5 => 'Oracle', 6 => 'Fighter', 7 => 'Defender', 8 => 'Ranger', 9 => 'Archer', 10 => 'Mage', 11 => 'Priest'); $conn = @odbc_connect("Driver={SQL Server};Server=$host;", $dbuser, $dbpass) or die("Database Connection Error!"); $UserID = isset($_POST['username']) ? mssql_escape_string(trim($_POST['username'])) : ''; $Pass = isset($_POST['password']) ? mssql_escape_string(trim($_POST['password'])) : ''; $Char = isset($_POST['char']) ? mssql_escape_string(trim($_POST['char'])) : ''; if (isset($_POST['submit'])) { if (strlen($UserID) < 1) die("User Name too short"); if (strlen($Pass) < 1) die("Password too short."); $res = odbc_exec($conn, "SELECT * FROM [PS_UserData].[dbo].[Users_Master] WHERE UserID = '" . $UserID . "' AND Pw = '" . $Pass . "'"); if (odbc_num_rows($res) == 0) { die("Username/Password is incorrect"); } else { $res2 = odbc_exec($conn,"SELECT umg.Country, c.Family, c.CharName, c.CharID, c.Job, c.Level FROM [PS_GameData].[dbo].[UserMaxGrow] AS umg INNER JOIN [PS_GameData].[dbo].[Chars] AS c ON umg.UserUID = c.UserUID WHERE c.UserID = '" . $UserID . "' AND c.Del=1"); if (odbc_num_rows($res2) == 0) { echo "Account does not contain any dead characters."; } else { echo "<form action=\"" . $_SERVER['PHP_SELF'] . "\" method=\"POST\">Select toon to resurrect :<br /> <input type=\"hidden\" name=\"username\" value=\"" . $UserID . "\"> <table cellspacing=1 cellpadding=2 border=1 style=\"border-style:hidden;\"> <tr><td>Select</td><td>CharName</td><td>Class</td><td>Level</td></tr>"; while ($chars = odbc_fetch_array($res2)) { if ($chars['Country'] == 0) { if ($chars['Family'] == 0 || $chars['Family'] == 1) { echo "<tr>"; echo "<td><input type=\"radio\" name =\"char\" value=\"" . $chars['CharName'] . "," . $chars['CharID'] . "\"></td>"; echo "<td>" . $chars['CharName'] . "</td><td>" . $class[$chars['Job'] + 6] . "</td>"; echo "<td>" . $chars['Level'] . "</td>"; echo "</tr>"; } } elseif ($chars['Country'] == 1) { if ($chars['Family'] == 2 || $chars['Family'] == 3) { echo "<tr>"; echo "<td><input type=\"radio\" name =\"char\" value=\"" . $chars['CharName'] . "," . $chars['CharID'] . "\"></td>"; echo "<td>" . $chars['CharName'] . "</td><td>" . $class[$chars['Job']] . "</td>"; echo "<td>" . $chars['Level'] . "</td>"; echo "</tr>"; } } } echo "</table><input type=\"submit\" value=\"Submit\" name=\"submit2\" /></form>"; } } } elseif (isset($_POST['submit2'])) { $slot = -1; $res1 = odbc_exec($conn, " SELECT MIN(Slots.Slot) AS OpenSlot FROM (SELECT 0 AS Slot UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4) AS Slots LEFT JOIN (SELECT c.Slot FROM PS_UserData.dbo.Users_Master AS um INNER JOIN PS_GameData.dbo.Chars AS c ON c.UserUID = um.UserUID WHERE um.UserID = '" . $UserID . "' AND c.Del = 0) AS Chars ON Chars.Slot = Slots.Slot WHERE Chars.Slot IS NULL"); $slot = odbc_fetch_array($res1); $toon2 = explode(',', $Char); if ($slot['OpenSlot'] > -1 && $slot['OpenSlot'] < 5) { odbc_exec($conn, "UPDATE PS_GameData.dbo.Chars SET Del=0, Slot=".$slot['OpenSlot'].", Map=42, PosX=63 , PosZ=57, DeleteDate=NULL WHERE CharID = $toon2[1]"); echo "Successfully resurrected <br /> Login = " . $UserID . "<br />Slot = " . ($slot['OpenSlot'] + 1) . "<br />Char = $toon2[0]"; } else echo "No slots avaliable"; } else { ?> <html> <head> <title>Character Ressurection</title></head> <body> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <fieldset style="font:100% trebuchet ms;width:100px;"> <legend >Resurrection Form </legend> <font face="Trebuchet MS"> <table> <tr> <font size=1><i>*Toon will be resurrected in an avaliable free slot.</i></font> </tr> <tr> <td>Account Login:</td><td> <input type="text" name="username" maxlength=20/></td> </tr> <tr> <td>Account Password:</td><td><input type="password" name="password" maxlength=20/></td> </tr> </font> </table> <input type="submit" value="Submit" name="submit" /> </fieldset> </form> </body> </html> <?php } ?>
I tested part of it on my desktop, and it loaded correctly, however I didn't test much further. Let me know the results. ^^
|
|
|
09/30/2011, 09:25
|
#21
|
elite*gold: 0
Join Date: Feb 2010
Posts: 675
Received Thanks: 240
|
not sure if works. the loggin box comes up. but well i need more more letters to be able to loggin. is there a way to fix this? i need 3 more to be able to type in my complete loggin name.
|
|
|
09/30/2011, 09:30
|
#22
|
elite*gold: 0
Join Date: Sep 2010
Posts: 520
Received Thanks: 1,289
|
Yeah, that wasn't my doing, that was part of the original script. Look for this:
PHP Code:
<td>Account Login:</td><td> <input type="text" name="username" maxlength=12 /></td> </tr> <tr> <td>Account Password:</td><td><input type="password" name="password" maxlength=12/></td>
and modify the "maxlength" to whatever, or just remove it altogether.
|
|
|
09/30/2011, 09:40
|
#23
|
elite*gold: 0
Join Date: Feb 2010
Posts: 675
Received Thanks: 240
|
ty that worked. but i have killed 2 of my chars now. and i still get this: Account does not contain any dead characters. when i loggin.
2 diff accounts too
error code:
[30-Sep-2011 10:39:47] PHP Warning: odbc_exec() expects at least 2 parameters, 1 given in C:\inetpub\wwwroot\resschar.php on line 45
[30-Sep-2011 10:39:47] PHP Warning: odbc_num_rows() expects parameter 1 to be resource, null given in C:\inetpub\wwwroot\resschar.php on line 47
|
|
|
09/30/2011, 10:03
|
#24
|
elite*gold: 0
Join Date: Sep 2010
Posts: 520
Received Thanks: 1,289
|
Svinseladden, I appologize for my multiple fails. I posted the working one above. I fully tested it, and resurrected two characters.
I hope it works for you this time, again, I apologize for the many failures on my end.
|
|
|
09/30/2011, 10:08
|
#25
|
elite*gold: 0
Join Date: Feb 2010
Posts: 675
Received Thanks: 240
|
lol i take errors any day as long as we can work it out together it's better then nothing. i love you even more each day now:-P
don't work on gm accounts yet. but np at all (just hade to test it) heheh
but worked for a normal account. and no i did not del/killed my working gm hahahah
hope it's ok if i now/later publish this under a new topic so ppl can find it.. and if you like i have more for you:-)
top players.
online players ( i realy have a big prob with this one. even setting up the sql stuff before it works. i have the new colum. but all just set's to NULL)
Statistics: only for gm use.
just tell me and i'll add them here for you:-) ..
|
|
|
09/30/2011, 10:56
|
#26
|
elite*gold: 0
Join Date: Sep 2010
Posts: 520
Received Thanks: 1,289
|
I already converted those. If you have more, post them, and I'll upload a new. ^^
|
|
|
09/30/2011, 11:06
|
#27
|
elite*gold: 0
Join Date: Feb 2010
Posts: 675
Received Thanks: 240
|
nice one.. didnt know thta. but i still have the problem trying to add the add_logginstatus: Msg 4902, Level 16, State 1, Line 1
Cannot find the object "dbo.Chars" because it does not exist or you do not have permissions.
procedure1:
Msg 208, Level 16, State 6, Procedure usp_Read_Chars_Detail2_R, Line 78
Invalid object name 'dbo.usp_Read_Chars_Detail2_R'.
and 2: Msg 208, Level 16, State 6, Procedure usp_Save_Char_LeaveDate_R, Line 14
Invalid object name 'dbo.usp_Save_Char_LeaveDate_R'.
did the same on the original post but got no answer for it. sorry
|
|
|
09/30/2011, 11:45
|
#28
|
elite*gold: 0
Join Date: Sep 2010
Posts: 520
Received Thanks: 1,289
|
I reuploaded a fixed one. Thanks.
Basically just add "USE PS_GameData" without quotes to the top. ^^
|
|
|
09/30/2011, 11:52
|
#29
|
elite*gold: 0
Join Date: Feb 2010
Posts: 675
Received Thanks: 240
|
ty but i already have a collum with that name. do you think a alter would change that? just change all NULL to 0?
i got the error but it's still there but all set to NULL
and the rest of the errors?
procedure1:
Msg 208, Level 16, State 6, Procedure usp_Read_Chars_Detail2_R, Line 78
Invalid object name 'dbo.usp_Read_Chars_Detail2_R'.
and 2: Msg 208, Level 16, State 6, Procedure usp_Save_Char_LeaveDate_R, Line 14
Invalid object name 'dbo.usp_Save_Char_LeaveDate_R'.
sorry used USE PS_GameData on thos too also and it worked i think. only prob now is the NULL on all char's under loggin status
|
|
|
09/30/2011, 11:54
|
#30
|
elite*gold: 0
Join Date: Sep 2010
Posts: 520
Received Thanks: 1,289
|
You have to add USE PS_GameData to the top of those queries, I just did, and it ran just fine.
If you already have the column, then set them all to 0, and get those last two queries ran
|
|
|
 |
|
Similar Threads
|
MSSQL-connect Problem
07/02/2011 - Flyff Private Server - 0 Replies
Ich versuche seit einer Stunde Treachery CS-Shop zum laufen zu kriegen, aber ich schaffe es einfach nicht das PHP sich endlich mal meinem Willen beugt und sich mit meiner DB verbindet...
Ich gebe in die config.php datei brav meine Daten ein, allerdings will es trotzdem nicht klappen...
http://img18.imageshack.us/img18/2105/mssql.png
http://img220.imageshack.us/img220/8788/configr.p ng
http://img31.imageshack.us/img31/7397/resultata.p ng
Wäre echt nett, wenn mir jemand einen Tipp geben...
|
[NOTICE] Unable to connect to MSSQL server using XAMPP
12/06/2010 - Dekaron Private Server - 0 Replies
Hi,
i would like to notice that if you use XAMPP and install Apache as Service
it happened to me for some reason
Error:
you might have a ERROR "Unable to connect to server ..."
if you try to load a page that contains a mssql connection
This seems to happen on XAMPP for windows 1.7.3
|
Giving a 78 2 hand on Posidon for helping me connect my xbox360 to pc
11/29/2009 - Silkroad Online Trading - 2 Replies
Hey all iam giving a 78 2 hand sword on posidon for anyone can help me connect xbox 360 to my pc windows
i guess its the best offer ;)
my msn:
[email protected]
my skype:
maged.edward
|
[Helping Topic] 24/7 Helping Services!
08/27/2008 - EO PServer Hosting - 31 Replies
stucked on anything while setuping your server?
post your problem here and you will get answer as fast as possible better than spamming with posts :cool:
first of all try reading Ahmedpotop's Pserver All thing guide.
if your couldn't solve it out post your problem down here
""That includes PHP rankings pages / registrations pages / Status pages""
|
All times are GMT +1. The time now is 15:59.
|
|