473,779 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

insert data on mysql thru php

ddtpmyra
333 Contributor
I don’t know if I posted my question on the right forum if not my bad, but I’m having trouble how to create a php script that will insert data on mysql

Scenario:
I have 3 checkbox on my form and users select all
Checkbox1
Checkbox2
Checbox3

Table structure:
Date, checknames


Goal:
Every time I hit the update button with query behind I want to insert the current date and checkboxnames (see below table)
------------------------------
|Created | checkboxname|
---------------------------------
|10-07-08 |checkbox1 |
---------------------------------
|10-07-08 |checkbox2 |
--------------------------------
|10-07-08 |checkbox3 |
---------------------------------

Problem:
Help to construct my insert query which i know is wrong :(
INSERT INTO dmtable (Created, checkboxname)
VALUES (NOW(),'{checkb ox1}', '{checkbox2}',' {checkbox3}');
Oct 7 '08 #1
5 1534
chelvan
90 New Member
hi
i don't know why you put this { bracket, on your inserting value. remove that.

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO dmtable (Created, checkboxname)
  2. VALUES (NOW(),'{checkbox1}', '{checkbox2}','{checkbox3}');
  3.  
change your query like this
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO dmtable (Created, checkboxname)
  2. VALUES (NOW(),'checkbox1', 'checkbox2','checkbox3');
  3.  

regards
chel-1
Oct 8 '08 #2
Markus
6,050 Recognized Expert Expert
hi
i don't know why you put this { bracket, on your inserting value. remove that.

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO dmtable (Created, checkboxname)
  2. VALUES (NOW(),'{checkbox1}', '{checkbox2}','{checkbox3}');
  3.  
That wouldn't affect anything..

OP, you pass more values to your query than columns. You give 2 columns (created, checkboxname) and 4 values. This will not work.
Oct 8 '08 #3
ddtpmyra
333 Contributor
Markus that's the thing how can I insert all the 3 information in one column in one query
Oct 8 '08 #4
Markus
6,050 Recognized Expert Expert
Markus that's the thing how can I insert all the 3 information in one column in one query
Why can't you have a column for each checkbox? That makes sense.
Oct 8 '08 #5
Atli
5,058 Recognized Expert Expert
Why don't you just add a row for each checked box?

Arrays of checkboxes can be sent using the same <input> name, each one containing a unique value.
You can simply send such an an array, loop through it once you get it and construct a query based on that.

For example:
Expand|Select|Wrap|Line Numbers
  1. <form action="?" method="post">
  2.   <input type="checkbox" name="boxes[]" value="box1" /><br />
  3.   <input type="checkbox" name="boxes[]" value="box2" /><br />
  4.   <input type="checkbox" name="boxes[]" value="box3" /><br />
  5.   <input type="submit" />
  6. </form>
  7. <?php
  8. if(isset($_POST['boxes']))
  9. {
  10.   $rows = array();
  11.   foreach($_POST['boxes'] as $_box)
  12.   {
  13.     $rows[] = "(NOW(), '{$_box}')";
  14.   }
  15.  
  16.   if(count($rows) > 0)
  17.   {
  18.     $sql = "INSERT INTO `tbl`(`Date`, `Box`) VALUES";
  19.     $sql .= implode(", ", $rows);
  20.  
  21.     echo "<pre>", $sql, "</pre>";
  22.   }
  23. }
  24. ?>
  25.  
You would want to sanitize the box value before using it tho. I skipped that part to keep things simple.
Oct 8 '08 #6

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

Similar topics

15
7395
by: Jack | last post by:
I have a text file of data in a file (add2db.txt) where the entries are already entered on separate lines in the following form: INSERT INTO `reviews` VALUES("", "Tony's", "Lunch", "Great atmosphere. Good food.", " (Harry Houdini - 03/01/2004)"); INSERT INTO `reviews` VALUES("", "Le Chow Place", "Lunch", "yada yada", " (Herbert Hoover - 03/03/2004)"); INSERT INTO `reviews` VALUES("", "Golden Dragon", "Lunch", "Exquisite.
2
2851
by: Atz | last post by:
Hi to all ! Im using MySql front and PHP 5 for some web shop. I didn't try it so far but i guess that the online data insertation ( accept costs and time ) should be the same process like for local connection. Problem: I have to create online ( on remote server ) some 6 tables and some 20 fields with MySql front. Ok. This shouldn't be great problem ( i hope :-)).
10
52790
by: Python_it | last post by:
Python 2.4 MySQL-python.exe-1.2.0.win32-py2.4.zip How can I insert a NULL value in a table (MySQL-database). I can't set a var to NULL? Or is there a other possibility? My var must be variable string or NULL. Becaus i have a if statement: if .... cursor.execute(".................insert NULL ..............") if ....
1
5427
by: Joe | last post by:
Hello All, I am trying to insert a record in the MS Access DB and for some reason I cannot get rid of error message, System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement. And the line it shows in red is cmd.ExecuteNonQuery()
2
1711
by: bballr | last post by:
I have a problem that I'm not sure if it can be done. I'm trying to use the MySQL C API to be able to use a normal sql insert statement that will send the data or file to a directory and NOT the database. I'm not sure if there is anything out there that will allow this, but I've searched everywhere, and I have found no solution. If anyone has any work around solutions, I also welcome those. Thanks for the help.
6
2117
by: VitaminB | last post by:
Hi Guys, I try to insert data from a form into a mysql database, but it did not work... There is no error, but the data did not pass thru the table. This is the short script:
1
6134
by: sheenaa | last post by:
Hello Members, I m creating my application forms in ASP.Net 2005 C# using the backend SQL Server 2005. What i have used on forms :: ? On my first form i have used some label,textboxs,dropdownlists,radiobutton and checkbox asp standard controls. On the click event of the command button the data gets stored into the database. I have created the stored procedures for the insert,update,delete. I have...
2
7047
josie23
by: josie23 | last post by:
Egad, I'm not a coder/programmer by nature or occupation but understand things like html and css and a small amount of perl. So, basically, I'm a perl/mysql imbecile. But, I've been trying to find syntax to insert values into a mysql database table. I'm able to use the below syntax to insert hard-coded values like 'josie' and 'smith' but can't find working syntax to insert $scalar data from another file (which is really what perl-mysql is...
9
6552
by: jith87 | last post by:
My proj involves JSP @ front end n MySql @ back end and connectivity is established thru JDBC. The thing is when i store values from the front end into the db i need to change the data types n vice versa.Consider ths. I m retrieving date from the db thru the result set i m traversing thru each n every record(next() function is used). String d1 = rs.getString(2);System.out.println("Date="+date); How do i convert the date field into a...
0
9636
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9930
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6724
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5373
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5503
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2869
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.