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

How to insert values present in variable into mysql table?

Hi all,

I have created a small Bank form GUI in gtk.
I want to store the information in the database.
Values(string) are present in variable say entry1.
e.g. entry1[]="Amit"
how can i insert string present in entry1 into table.

I have tried different syntax's like

insert into table01 values('entry1');
insert into table01 values('"entry1"');
insert into table01 values('$entry1');

it didnt worked...

please help me to sort this problem..

Thanks...
Sep 23 '10 #1
1 7474
Atli
5,058 Expert 4TB
Hey.

If we are to be any help at all, we need to know a few basic things. Like:
Which programming languages are you using?
What does you code look like? (Exactly!)
How do you expect it to work?
How does it actually work?
Do you get any errors? (This is crucial!)


"It doesn't work" is not a very helpful problem description ;)

I have tried different syntax's like

insert into table01 values('entry1');
insert into table01 values('"entry1"');
insert into table01 values('$entry1');
The first one is correct. The second one is incorrect, unless you plan on including the double-quotes in the string, in which case it should be fine. The third one looks like something you would do when injecting variables into strings in PHP; a fairly common sight in PHP code.

In PHP we would create MySQL commands somewhat like this:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // Some initial values, most likely comming from a database
  3. // or $_POST/$_GET.
  4. $values = array();
  5. $values[] = 'Something';
  6. $values[] = 'Something else';
  7.  
  8. // Make them safe to be put into a MySQL query.
  9. // ALWAYS do this before putting things into a query,
  10. // or you risk SQL Injection.
  11. $first = mysql_real_escape_string($values[0]);
  12. $second = mysql_real_escape_string($values[1]);
  13.  
  14. // Construct a query.
  15. $sql = "INSERT INTO myTable(col1, col2)
  16.         VALUES('$first', '$second')";
  17.  
  18. // Etc...
  19. ?>
Sep 24 '10 #2

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

Similar topics

4
by: Xenophobe | last post by:
I have a series of checkboxes and need to store their values in a MySQL table. I'm wondering what data type people recommend: varchar or text, exp. "True/False", "Yes/No" tinyint, exp. "0/1"...
11
by: grumfish | last post by:
I'm trying to add a row to a MySQL table using insert. Here is the code: connection = MySQLdb.connect(host="localhost", user="root", passwd="pw", db="japanese") cursor = connection.cursor()...
2
by: jaks | last post by:
How can I export a MySQL table with a different name using phpmyadmin? I want to export nuke_bbsearch_wordmatch and all it contents to phpbb_search_wordmatch This table in a different db. ...
5
by: Stephen Preston | last post by:
Trying to load an multidimensional array into a MySQL table with columns as follows, level1,level2,level3,illust,item,description,partNo,qua,price,remarks,weight ,size,mass the array first...
12
by: mantrid | last post by:
Hello Can anyone point me in the right direction for the way to read a text file a line at a time and separate the fields on that line and use them as data in an INSERT to add a record to a mysql...
2
by: idorjee | last post by:
hello, i'm trying to write a perl cgi script to insert some values that i get from the my html form. i could manage to get the params from the html and process them (that part is not included in...
10
by: help4me | last post by:
I am having trouble updating a table. The logic seems so simple but I just can’t get it to work. The table is named test. The column names are passcode, name, address, city, state, zip and email....
3
by: eihabisaac | last post by:
i want to add a column to a created table its name is department i wrote this ALTER TABLE department ADD dCode char(10); this code will work ,, but the problem is that i dont know exactly...
2
by: servo | last post by:
I am using the following code. Why it does not insert record in the MySQL Table through php script: <?php $dbhost='localhost'; $dbuser='root'; $dbpass='newpass'; $mysqldb='mysql'; ...
9
by: PI | last post by:
Hi Guys, I need some assistance with the following scenario please. I know this might be more of a MySQL post than a PHP one, but it is likely some developer has been here before and would be...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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: 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.