Page 1 of 2

Problem in Insert Into Code

Posted: Thu Jan 17, 2008 12:16 am
by subho
Error generated : "Error, insert query failed"

For the Following Code : -

<?Php
$mysql_user = "os2s";
$mysql_password = "online2";
$myDatabase = "online";
$server = "localhost:3306";

$Name=$_POST['Name'];
$Address=$_POST['Address'];
$City=$_POST['City'];
$Pcode=$_POST['Pcode'];
$State=$_POST['State'];
$Country=$_POST['Country'];
$Cperson=$_POST['Cperson'];
$Desig=$_POST['Desig'];
$Ophone=$_POST['Ophone'];
$Rphone=$_POST['Rphone'];
$Fax=$_POST['Fax'];
$Mobile=$_POST['Mobile'];
$Email=$_POST['Email'];
$Website=$_POST['Website'];
$Categ=$_POST['Categ'];
$AbServ=$_POST['AbServ'];
$Utype=$_POST['Utype'];
$Rtype=$_POST['Rtype'];
$Rmks=$_POST['Rmks'];

$con = mysql_connect($server,$mysql_user,$mysql_password);
@mysql_select_db($myDatabase, $con) or die("Unable to select database");


$query = "SELECT * FROM register WHERE Name = '$Name' AND Address = '$Address'";
$result = mysql_query($query, $con);


If (mysql_numrows($result))
{echo "<br><br><font color='#FF0000' size='2' face='Verdana, Arial, Helvetica, sans-serif'><b><center>You had registered yourself in previous occassion. Please don't do that again. To enter into the site you have to use your unique User Id and Password which had been supplied by us.</center></b></font><br><br>";
}

Else
{
$query = "INSERT INTO register (RegId, img_id, ScrapId, Name, Address, City, Pcode, State, Country, Cperson, Desig, Ophone,"
. "Rphone, Mobile, Fax, Email, Website, Categ, AbServ, Utype, Rtype, Uid, Pwd, Rmks) VALUES (, , , '$Name', '$Address',"
. " '$City', '$Pcode', '$Pcode', '$State', '$Country', '$Cperson', '$Desig', '$Ophone', '$Rphone', '$Mobile', '$Fax',"
. " '$Email', '$Website', '$Categ', '$AbServ', '$Utype', '$Rtype', '', '', '$Rmks')";


@mysql_query($query, $con) or die('Error, insert query failed');

echo "<font color='#0000FF' size='2' face='Verdana, Arial, Helvetica, sans-serif'><b>Dear <font color='#FF0000'>$Name</font>,<br><br>Now you are become a registerd member of Onlines2s.com. <br><br>Your User Id and Password will be sent to you shortly in your email address.</b></font><br><br>";

}

mysql_close($con);
?>

Pl let me know where the problem lies and its solution. Treat this as most urgent

thanks & regards
Subho

Re: Problem in Insert Into Code

Posted: Thu Jan 17, 2008 12:24 am
by jimthunderbird
Your insert statement has syntax errors I believe.
When you are sure some fields in your table won't store any value, just don't let them appear in your statement.

Re: Problem in Insert Into Code

Posted: Thu Jan 17, 2008 12:36 am
by subho
The First Field "RegId" Is the Primary Key and Autoincremented value.

Other Fields "img_id" and "ScrapId" holds Integer Value and "Uid", "Pwd" holds Varchar value.

These 4 fields are left blank at the time of data insertion.

Again I have omitted those fileds from the Insert Into statement and following is the code : -



$query = "INSERT INTO register (Name, Address, City, Pcode, State, Country, Cperson, Desig, Ophone,"
. "Rphone, Mobile, Fax, Email, Website, Categ, AbServ, Utype, Rtype, Uid, Pwd, Rmks) VALUES ('$Name', '$Address',"
. " '$City', '$Pcode', '$Pcode', '$State', '$Country', '$Cperson', '$Desig', '$Ophone', '$Rphone', '$Mobile', '$Fax',"
. " '$Email', '$Website', '$Categ', '$AbServ', '$Utype', '$Rtype', '$Rmks')";


Again same error is generated. Pl reply asap.

thanks & regards
Subho

Re: Problem in Insert Into Code

Posted: Thu Jan 17, 2008 12:46 am
by jimthunderbird
No, your insert statement still wrong I guess...

you have uid appear in the table field but no corresponding uid value, so the field is not matching the value...

for long insert statement like this, try using insert into [table] set [field] = '[value]', this way you can avoid all these mismatching things.

Re: Problem in Insert Into Code

Posted: Thu Jan 17, 2008 12:58 am
by subho
Yes I accepted my mistake. Thanks for point.

But still same error is generated. Now Changed code is following : -

$query = "INSERT INTO register (Name, Address, City, Pcode, State, Country, Cperson, Desig, Ophone, "
. "Rphone, Mobile, Fax, Email, Website, Categ, AbServ, Utype, Rtype, Rmks) VALUES ('$Name', '$Address',"
. " '$City', '$Pcode', '$State', '$Country', '$Cperson', '$Desig', '$Ophone', '$Rphone', '$Mobile', '$Fax',"
. " '$Email', '$Website', '$Categ', '$AbServ', '$Utype', '$Rtype', '$Rmks')";


Pl help asap.

thanks & regards
Subho

Re: Problem in Insert Into Code

Posted: Thu Jan 17, 2008 1:04 am
by jimthunderbird
What i will do is after your $query, put print $query, then see what that is, copy that into phpmyadmin and run it see what's going on.

Re: Problem in Insert Into Code

Posted: Thu Jan 17, 2008 1:20 am
by subho
In PhpMyadmin error showing is following below : -

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '$query = "INSERT INTO online.register (Name, Address, City, Pcode, State, Countr' at line 1


I don't know what's wrong in it ?

My MySQL - 4.1.20 & phpMyAdmin - 2.8.2.4

Then now i am getting helpless. Pl reply

thanks & regards
Subho

Re: Problem in Insert Into Code

Posted: Thu Jan 17, 2008 1:33 am
by jimthunderbird
You should not include $query in phpmyadmin, should only put sql statement in it.

Re: Problem in Insert Into Code

Posted: Thu Jan 17, 2008 1:37 am
by jimthunderbird
Also, I recommend changing your insert query to:

Code: Select all

 
insert into register set Name = '$Name',
                         Address = '$Address',
                         City = '$City',
                         Pcode = '$Pcode',
                         State = '$State',
                         Country = '$Country',
                         Cperson = '$Cperson', 
                         Desig = '$Desig',
                         Ophone = '$Ophone',
                         Mobile = '$Mobile',
                         Fax = '$Fax',
                         Email = '$Emmail',
                         Website = '$Website',
                         Categ = '$Categ',
                         AbServ = '$AbServ',
                         Utype = '$Utype',
                         Rtype = '$Rtype',
                         Rmks = '$Rmks'
 
This way it's easier to debug and less error-prone.

Re: Problem in Insert Into Code

Posted: Thu Jan 17, 2008 1:44 am
by subho
Again same error is generated.

I have put acc to u

$query = "insert into register set Name = '$Name',
Address = '$Address',
City = '$City',
Pcode = '$Pcode',
State = '$State',
Country = '$Country',
Cperson = '$Cperson',
Desig = '$Desig',
Ophone = '$Ophone',
Mobile = '$Mobile',
Fax = '$Fax',
Email = '$Email',
Website = '$Website',
Categ = '$Categ',
AbServ = '$AbServ',
Utype = '$Utype',
Rtype = '$Rtype',
Rmks = '$Rmks'";


Pl help

thanks & regards
Subho

Re: Problem in Insert Into Code

Posted: Thu Jan 17, 2008 2:10 am
by jimthunderbird
It should be working, the insert statement I provided is correct.

Re: Problem in Insert Into Code

Posted: Thu Jan 17, 2008 3:32 am
by subho
Sorrry for delayed response.

Still code is not working and same error is generated.

Folowing is the code : -

$query = "insert into register set Name = '$Name',
Address = '$Address',
City = '$City',
Pcode = '$Pcode',
State = '$State',
Country = '$Country',
Cperson = '$Cperson',
Desig = '$Desig',
Ophone = '$Ophone',
Rphone = '$Rphone',
Mobile = '$Mobile',
Fax = '$Fax',
Email = '$Email',
Website = '$Website',
Categ = '$Categ',
AbServ = '$AbServ',
Utype = '$Utype',
Rtype = '$Rtype',
Rmks = '$Rmks'";

Pl do the needful asap.

thanks & regards
Subho

Re: Problem in Insert Into Code

Posted: Thu Jan 17, 2008 4:38 am
by subho
Yet to receive any response.

It's still not working.

thanks & regards
Subho

Re: Problem in Insert Into Code

Posted: Thu Jan 17, 2008 5:31 am
by subho
Where lies the flaw?

Code is randomly checked.

What else the insertion code ?

PL let me inform asap.

thanks & regards
Subho

Re: Problem in Insert Into Code

Posted: Thu Jan 17, 2008 6:04 am
by jimthunderbird
Maybe I need to see the database structure. The register table's field definition.