Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

insert wont work

Posted on 2013-06-27
7
Medium Priority
?
318 Views
Last Modified: 2013-06-27
Hi,

This insert in php wont work and I am not getting any error msg.

$sql2="insert into tbmod1  (id,q1,q2,q3,q4,q5,q6,q7,q8,q9,q10,q11,q12,user,section) values 
(1, 'enter here1' ,'enter here2', 'enter here3', 'enter here4' ,'enter here5', 'enter here6','enter here7' ,'enter here8', 'enter here9','enter here10' ,'enter here11', 'enter here12'," . $myusername .",'section1')";

$result2=mysql_query($sql2);

Open in new window

0
Comment
Question by:jagguy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 35

Expert Comment

by:gr8gonzo
ID: 39281328
Try:

$sql2="insert into tbmod1  (id,q1,q2,q3,q4,q5,q6,q7,q8,q9,q10,q11,q12,user,section) values
(1, 'enter here1' ,'enter here2', 'enter here3', 'enter here4' ,'enter here5', 'enter here6','enter here7' ,'enter here8', 'enter here9','enter here10' ,'enter here11', 'enter here12','" . mysql_real_escape_string($myusername) ."','section1')";

$result2=mysql_query($sql2);

(Added single quotes around the user value, and added mysql_real_escape_string on the value itself.
0
 
LVL 31

Accepted Solution

by:
Marco Gasi earned 2000 total points
ID: 39281345
To get error messages you must use mysql_error() function:

$result2=mysql_query($sql2) or die(mysql_error());

Also, keep in mind mysqk is deprecated and you should migrate your code to mysqli: see the giant pink warning here: http://it2.php.net/manual/en/function.mysql-query.php

Cheers
0
 
LVL 6

Expert Comment

by:BurundiLapp
ID: 39281354
Also confirm that your ID field is not an autonumber type field, trying to manually provide a value for ID if it is an autonumber field will break your insert.

For debugging I print the completed SQL statements to screen and then manually copy and paste them into phpmyadmin or SQL Server Management Studio (depending on what DB I'm working with) and then execute the statement and i can see any error messages straight away.
0
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 
LVL 7

Expert Comment

by:dimmergeek
ID: 39281356
$sql2="insert into tbmod1  (id,q1,q2,q3,q4,q5,q6,q7,q8,q9,q10,q11,q12,user,section) values
(1, 'enter here1' ,'enter here2', 'enter here3', 'enter here4' ,'enter here5', 'enter here6','enter here7' ,'enter here8', 'enter here9','enter here10' ,'enter here11', 'enter here12','$myusername','section1')";

$result2=mysql_query($sql2);
0
 

Author Comment

by:jagguy
ID: 39281374
OK i had a duplicate value. The id filed is listed as a Primary but I didnt create the thing as a Primary key and I cant remove primary key from this field
0
 
LVL 35

Expert Comment

by:gr8gonzo
ID: 39281381
You can use ALTER statements to change the table definition, or you can use a GUI tool like HeidiSQL (free) to do it for you.
0
 
LVL 44

Expert Comment

by:Chris Stanyon
ID: 39281410
Just to confuse matters, you should be moving away from using mysql_* and switch to mysqli or PDO ;)
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question