Problem in Insert Into Code
Moderator: General Moderators
Problem in Insert Into Code
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
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
- jimthunderbird
- Forum Contributor
- Posts: 147
- Joined: Tue Jul 04, 2006 3:59 am
- Location: San Francisco, CA
Re: Problem in Insert Into Code
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.
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
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
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
- jimthunderbird
- Forum Contributor
- Posts: 147
- Joined: Tue Jul 04, 2006 3:59 am
- Location: San Francisco, CA
Re: Problem in Insert Into Code
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.
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
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
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
- jimthunderbird
- Forum Contributor
- Posts: 147
- Joined: Tue Jul 04, 2006 3:59 am
- Location: San Francisco, CA
Re: Problem in Insert Into Code
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
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
#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
- jimthunderbird
- Forum Contributor
- Posts: 147
- Joined: Tue Jul 04, 2006 3:59 am
- Location: San Francisco, CA
Re: Problem in Insert Into Code
You should not include $query in phpmyadmin, should only put sql statement in it.
- jimthunderbird
- Forum Contributor
- Posts: 147
- Joined: Tue Jul 04, 2006 3:59 am
- Location: San Francisco, CA
Re: Problem in Insert Into Code
Also, I recommend changing your insert query to:
This way it's easier to debug and less error-prone.
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'
Re: Problem in Insert Into Code
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
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
- jimthunderbird
- Forum Contributor
- Posts: 147
- Joined: Tue Jul 04, 2006 3:59 am
- Location: San Francisco, CA
Re: Problem in Insert Into Code
It should be working, the insert statement I provided is correct.
Re: Problem in Insert Into Code
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
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
Yet to receive any response.
It's still not working.
thanks & regards
Subho
It's still not working.
thanks & regards
Subho
Re: Problem in Insert Into Code
Where lies the flaw?
Code is randomly checked.
What else the insertion code ?
PL let me inform asap.
thanks & regards
Subho
Code is randomly checked.
What else the insertion code ?
PL let me inform asap.
thanks & regards
Subho
- jimthunderbird
- Forum Contributor
- Posts: 147
- Joined: Tue Jul 04, 2006 3:59 am
- Location: San Francisco, CA
Re: Problem in Insert Into Code
Maybe I need to see the database structure. The register table's field definition.