473,385 Members | 1,973 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,385 software developers and data experts.

Solve my Database Insert error?

Expand|Select|Wrap|Line Numbers
  1. if(isset($_REQUEST['submit']))
  2. {
  3. date_default_timezone_set("Asia/Calcutta");
  4. $date = date('d/m/Y');
  5. $in=$_POST['in'];
  6. $out=$_POST['out'];
  7. $project1=$_POST['project1'];
  8. $hrs1=$_POST['hrs1'];
  9. $project2=$_POST['project2'];
  10. $hrs2=$_POST['hrs2'];
  11. $otherremark=$_POST['otherremark'];
  12. $hrs3=$_POST['hrs3'];
  13. $total=$_POST['total'];
  14.  
  15.  
  16. $result=mysql_query("INSERT into user_tasksheet(today_date,in,out,project1,hrs1,project2,hrs2,otherremark,total) values('".$date."','$in','$out','$project1','$hrs1','$project2','$hrs2','$otherremark','$hrs3',$total)") or die(mysql_error());
  17. if(mysql_num_rows()==1)
  18. {
  19. echo "insert data";    
  20. }
  21. else
  22. {
  23.  
  24. echo "not insert data";    
  25. }
  26.  
  27. }
  28. else
  29. {
  30.     return false;
  31.     }
  32.  
  33. ?>
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 'in,out,project1,hrs1,project2,hrs2,otherremark,to tal) values('19/08/2012','','',' at line 1
Aug 19 '12 #1

✓ answered by Claus Mygind

You have 9 fields (columns) and 10 values.

I also noted that your variable values after the date were submitted as constants, in that you did not concatenate the variables with the .

Just a suggestion, if your database is MySQL you may want to use this alternate syntax of name/value pairs. I think it is easier to match up the field with the value like this

INSERT INTO tbl_name SET col_name1=expr1 , col_name2=expr2, ...

So your code would look something like this.

$result=mysql_query("INSERT into user_tasksheet set today_date = '".$date."', in=".$in.", out=".$out.',...

3 1695
Claus Mygind
571 512MB
You have 9 fields (columns) and 10 values.

I also noted that your variable values after the date were submitted as constants, in that you did not concatenate the variables with the .

Just a suggestion, if your database is MySQL you may want to use this alternate syntax of name/value pairs. I think it is easier to match up the field with the value like this

INSERT INTO tbl_name SET col_name1=expr1 , col_name2=expr2, ...

So your code would look something like this.

$result=mysql_query("INSERT into user_tasksheet set today_date = '".$date."', in=".$in.", out=".$out.',...
Aug 19 '12 #2
Thnk You very much

thnks for suggestion
Aug 19 '12 #3
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 'in='4', out='2', project1='ygb', hrs1='2', project2='grtg', hrs2='3', othe' at line 3
Expand|Select|Wrap|Line Numbers
  1. <?php include('conn.php')?>
  2. <?php
  3. if(isset($_REQUEST['submit']))
  4. {
  5. date_default_timezone_set("Asia/Calcutta");
  6. $date = date('d/m/Y');
  7. $in=$_POST['in'];
  8. $out=$_POST['out'];
  9. $project1=$_POST['project1'];
  10. $hrs1=$_POST['hrs1'];
  11. $project2=$_POST['project2'];
  12. $hrs2=$_POST['hrs2'];
  13. $other_remarks=$_POST['other_remark'];
  14. $hrs3=$_POST['hrs3'];
  15. $total=$_POST['total'];
  16.  
  17. $query="INSERT into user_tasksheet SET 
  18. today_date='".$date."',
  19. in='".$in."',
  20. out='".$out."',
  21. project1='".$project1."',
  22. hrs1='".$hrs1."',
  23. project2='".$project2."',
  24. hrs2='".$hrs2."',
  25. other_remark='".$other_remarks."',
  26. hrs3='".$hrs3."',
  27. total='".$total."'";
  28.  
  29. $result=mysql_query($query) or die(mysql_error());
  30. if($result)    
  31. {
  32. echo "insert data";    
  33. }
  34. else
  35. {
  36.  
  37. echo "not insert data";    
  38. }
  39.  
  40. }
  41. else
  42. {
  43.     return false;
  44. }
  45.  
  46. ?>
Aug 20 '12 #4

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

Similar topics

3
by: jason | last post by:
I am picking up the following error message which is strange as it has only started happening since I have transferred servers: Microsoft JET Database Engine error '80004005' Operation must use...
6
by: jason | last post by:
I am picking up an error message on a straightforward INSERT - do I need an optimistic-type to get this working....here is is the error: Microsoft JET Database Engine error '80004005' Operation...
2
by: Alex Vidal | last post by:
Hi, I have windows 2000 server with IIS and I program ASP. I use the string: "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=basedatos.mdb;" to data base Access and it always works ok. But I...
7
by: | last post by:
I am having trouble figuring out to call a database INSERT procedure from a simple submit form. It appears I should use the onclick event to trigger the procedure called BUT when I do this I...
1
by: INSERT ERROR | last post by:
I am trying to INSERT record in MYSQL database, but each time the code tries to execute the command: MySQL_cmdGLAccount.ExecuteNonQuery(), it reports an error with the message "COLUMN COUNT...
3
by: INSERT ERROR | last post by:
I am trying to INSERT record in MYSQL database, but each time the code tries to execute the command: MySQL_cmdGLAccount.ExecuteNonQuery(), it reports an error with the message "COLUMN COUNT...
1
by: pawar karuna | last post by:
Hi all, I have designed a database in which there are lot of reltaionships. Sometime i get error stating "jet database engine error" can you please help to solve this problem.
3
by: Greg Corradini | last post by:
Hello, I'm trying to perform a simple insert statement into a table called Parcel_Test (see code below). Yet, I get an error message that I've never seen before (see traceback below). I've tried...
2
by: Greg Corradini | last post by:
Hello, I've never gotten this traceback error before using mx.ODBC. Any ideas about resolving this issue? The statement and the error it generates are listed below. curse.execute("Insert into...
2
by: phuc2583 | last post by:
I have a problem with an application I developed with code charge. Whenever I try to access a table in a database I get the following error: Microsoft JET Database Engine error '80040e09' Cannot...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.