473,382 Members | 1,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

error in sql statement

I am making a from in php and inserting values in members table.Structure of members table is:
id varchar(30) not null primary key
username varchar(15)
password varchar(15)

when i insert values in table using $_POST[] it gives error
Error:Duplicate entry 'john' for key 'PRIMARY' whereas there is no entry in my table as john.Code is:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $con = mysql_connect("localhost","root","");
  3. if (!$con)
  4.   {
  5.   die('Could not connect: ' . mysql_error());
  6.   }
  7. mysql_select_db("seed_bank", $con);
  8.  
  9. $sql = "insert into members(id,username,password) 
  10. values('$_POST[emailid]','$_POST[firstname]','$_POST[password]')";
  11. print $sql;
  12. $result=mysql_query($sql);
  13. $count=mysql_num_rows($result);
  14. if($count==1)
  15. {
  16. echo "Registration SUCCCESSFUL";
  17. }
  18.  
  19. if(!mysql_query($sql,$con))
  20. {
  21. die('Error:'.mysql_error());
  22. }
  23.  
  24. else {echo"Registration succcessful";}
  25. mysql_close($con);
  26. ?>
  27.  
It gives the error but at the same time also inserts values in the table.why it is giving error even when inserting values in the table?
Jun 26 '12 #1

✓ answered by Rabbit

It's because you run your query twice. Once on line 12 and again on line 19.

1 1740
Rabbit
12,516 Expert Mod 8TB
It's because you run your query twice. Once on line 12 and again on line 19.
Jun 26 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Timh Bergström | last post by:
Hi all! Can i do a global "on error" statement for all forms and modules instead of having "on error goto ErrHand" in each sub/function? The error should be catched to another form there the...
3
by: Nathan Bloomfield | last post by:
Hi there, I am having difficulty with a piece of code which would work wonders for my application if only the error trapping worked properly. Basically, it works as follows: - adds records...
10
by: jeff regoord | last post by:
A user inputs a float value. The scanf() function gets the value. However, I need to create an error handler with an if else statement saying invalid input if the input is not a number. Does...
10
by: Anthony England | last post by:
(sorry for the likely repost, but it is still not showing on my news server and after that much typing, I don't want to lose it) I am considering general error handling routines and have...
1
by: game_freak | last post by:
In a line of code I have: Public Overrides Sub Draw() I copied the code exactly but still shows the error. I need help! -- I love games!
70
kiss07
by: kiss07 | last post by:
Hi, i want 2 and 3 rd max salary in a table .i want a single query. please help.. Arun
3
by: DKelley | last post by:
I'm receiving a "severe" error that I can't seem to trap and evaluate in SQL Server 2000 (and no, I can't switch to 2005, this is on our customers' machines). And I've not been able to find info on...
4
pentahari
by: pentahari | last post by:
How to give the Common Error statement to all procedure and function. For ex Sub sub1() On Error Resume Next statement..... End Sub Sub sub2()
1
by: dianaroslan | last post by:
have an error in this coding. the error is statement missing at line (78,11) thank you. #include <iostream> #include <conio> const int listSize=2; struct menuItemType { char menuItem ;
9
by: Amit Lamba | last post by:
I am trying to run a module from a button on a form where I populate a subform from Query1 with a product formula. The module is supposed to check whether the product formula can be implemented...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.