Becuase my gunz server is opened 4 days now i want to give the first players a gift.
Wizkidje helped me. But i get an error. I dont know what i do wrong.
This is the script:
I get this error:Code:<?php //Made by Wizkid. //Removing my copyright is stupid. //Let us connect the database. //Yeah yeah, ODBC this time. $host = "Servername"; $user = "sa"; $pass = "secret"; $dbname = "GunzDB"; $connect = odbc_connect("Driver={SQL Server};Server={$host}; Database={$dbname}", $user, $pass) or die("Can't connect the MSSQL server."); //Anti SQL injection function antisql($sql) { // Remove words that contain SQL syntax $sql = preg_replace(sql_regcase("/(from|select|insert|delete|where|drop table|show tables|#|\*|--|\\\\)/"),"",$sql); $sql = trim($sql); //Cleans up spaces $sql = strip_tags($sql);//Php and html tags strip $sql = addslashes($sql);//Adds backslashes to one string return $sql; } //The num_rows() function for ODBC since the default one always returns -1. function num_rows(&$rid) { //We can try it at least, right? $num= odbc_num_rows($rid); if ($num >= 0) { return $num; } if (!odbc_fetch_row($rid, 1)) { odbc_fetch_row($rid, 0); return 0; } if (!odbc_fetch_row($rid, 2)) { odbc_fetch_row($rid, 0); return 1; } $lo= 2; $hi= 8192000; while ($lo < ($hi - 1)) { $mid= (int)(($hi + $lo) / 2); if (odbc_fetch_row($rid, $mid)) { $lo= $mid; } else { $hi= $mid; } } $num= $lo; odbc_fetch_row($rid, 0); return $num; } //GET the act and do the stuff. if (isset($_GET['act']) AND $_GET['act'] == "do") { //Let's get the charname. $charname = antisql($_POST['charname']); //No charname entered... the bastard. if (empty($charname)) { die("No shit."); } //Let us get the CID. $query = odbc_exec($connect,"SELECT CID FROM Character WHERE Name = '$charname'"); $count = num_rows($query); //Charname doesn't exist into the table or does exist multiple times. if ($count != 0) { die("Shit happened or you can't type."); } odbc_fetch_row($query); $CID = odbc_result($query, 1); //The real part. Edit the ItemID eventually. odbc_exec($connect,"INSERT INTO CharacterItem (CID, ItemID) VALUES ('$CID', '50042')"); echo "$cid<br><br>"; } ?> <form action='<?=$_SERVER['PHP_SELF']?>?act=do' method='POST'> Text shit goes here.<br><br> <table width='250'> <tr> <td width='50%'><b>Charactername:</b></td> <td width='50%'><input type='text' name='charname'></td> </tr> <tr> <td width='50%'></td> <td width='50%'><input type='submit' value='Welcome!'></td> </tr> </table> </form> <br><br> <font size='1'>Made by Wizkid.</font>
Dutch:
translated to english:Code:Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC SQL Server Driver][SQL Server]De INSERT-instructie heeft tot een conflict geleid met de FOREIGN KEY-beperking Character_CharacterItem_FK1. Het conflict is opgetreden in database GunZDB, tabel dbo.Character, column 'CID'., SQL state 23000 in SQLExecDirect in C:\wamp\www\beginner\free2.php on line 87
Code:Warning: odbc_exec () [function.odbc-exec]: SQL error: [Microsoft] [ODBC SQL Server Driver] [SQL Server] The INSERT statement has led to a conflict with the FOREIGN KEY mitigation Character_CharacterItem_FK1. The conflict occurred in database GunZDB, dbo.Character table, column 'CID'., SQL state 23000 in SQLExecDirect in C: \ WAMP \ www \ beginner \ free2.php on line 87


Reply With Quote


