Error in sql
Posted: Wed Apr 27, 2011 7:43 am
Hello everyone,
While running my script I got an error that I really cant understand why it pop up!
error:
I guess you wonder why I have this $table variable, it because I have each table for each letter for example:
TGameUser
AGameUser
Hope you get it,
Anyway I cant understand why it say cant insert to user colum ... I didnt even tried to! (Passwd) VALUES ('$Npassword') I tried to the Passwd colum.
Thanks.
While running my script I got an error that I really cant understand why it pop up!
error:
Here is the script:Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC SQL Server Driver][SQL Server]Cannot insert the value NULL into column 'userid', table 'AccountDB.dbo.TGameUser'; column does not allow nulls. INSERT fails., SQL state 23000 in SQLExecDirect in C:\Program Files\VertrigoServ\www\magicpt\finish_update.php on line 53
SQL statement failed with error:
Code: Select all
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div id="MainWrapper" align="center">
<img src="images/top.jpg" />
<div id="content">
<?php
$username = $_POST['username'];
$password = $_POST['password'];
$Npassword = $_POST['Npassword'];
if($_POST['submitted']==1)
{
$errormsg = "";
if(!$username || !$password || !$Npassword)
$errormsg = "Please make sure all the fields are filled out.";
}
if($errormsg)
{
echo "<b><font size='3px' color='red'>".$errormsg."</b></font><br />";?>
<input type="button" value="Back" onclick="window.location.href='http://81.218.161.218:8888/magicpt/password.php'"><?php
}
else
{
$host = "DRIVER={SQL Server};"."SERVER=;"."DATABASE=";
$user = "";
$pw ="";
$table = substr($username,0,1);
$table .= "GameUser";
$con = odbc_connect($host,$user,$pw);
$CheckSql="SELECT * FROM $table WHERE userid='$username'";
$CheckRes = odbc_exec($con,$CheckSql);
if(!$CheckRes)
print("SQL statement failed with error:\n");
else
if(!odbc_fetch_array($CheckRes))
{
echo "<script>alert('Account does not exist !')</script>";?>
<input type="button" value="Back" onclick="window.location.href='http://81.218.161.218:8888/magicpt/password.php'"><?php
}
else
{
$pass=odbc_result($CheckRes,"Passwd");
if($pass!=$password)
{
echo "<script>alert('Password is incorrect !')</script>"; ?>
<input type="button" value="Back" onclick="window.location.href='http://81.218.161.218:8888/magicpt/password.php'"><?php
}
else
{
$sql = "INSERT INTO $table (Passwd) VALUES ('$Npassword')";
$res = odbc_exec($con,$sql);
if (!$res)
print("SQL statement failed with error:\n");
else
echo "<script>alert('Password has been changed successfully !')</script>";
odbc_close($con); ?>
<input type="button" value="Back" onclick="window.location.href='http://81.218.161.218:8888/magicpt/manager.php'"><?php
}
}
}?>
</div><br />
<img src="images/bottom.jpg" />
</div>
</body>
</html>
TGameUser
AGameUser
Hope you get it,
Anyway I cant understand why it say cant insert to user colum ... I didnt even tried to! (Passwd) VALUES ('$Npassword') I tried to the Passwd colum.
Thanks.