add item on the site

Joined
Sep 7, 2008
Messages
972
Reaction score
81
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:
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>

I get this error:
Dutch:
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

translated to english:

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
 
tabel dbo.Character, column 'CID' Lees de Error.

odbc_exec($connect,"INSERT INTO CharacterItem (CID, ItemID) VALUES ('$CID', '50042')");
FF kijke weet niet precies hoe je het moet fixe xD maarjah zal vast niet supermoeilijk zijn:P
:alienmental:
 
Last edited by a moderator:
Upvote 0
translated:
Eele:It's your datebase er an error in the insert statement.
Niels: How do you fix it?
Eele:tabel dbo.Character, column 'CID' Read the Error.

odbc_exec($connect,"INSERT INTO CharacterItem (CID, ItemID) VALUES ('$CID', '50042')");
I think this problem is easy.

This is translated.

Errors i get:
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

Or

Shit happend
 
Upvote 0
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 [B]FOREIGN KEY mitigation 
Character_CharacterItem_FK1.[/B] 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


Hope the picture helps...
 

Attachments

  • 2 - add item on the site - RaGEZONE Forums
    2.webp
    85.9 KB · Views: 31
Upvote 0
Back