Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
I am using this query to insert values, but it is not working.
$sql="INSERT INTO $tbl_name (type, weight, side, size, quantity)
VALUES ($stock_type, $weight, $side,$size,$quantity)";
In Database table 'value type' is varchar for all values
I don't know the column types but you need to quote values for string type fields:
$sql='INSERT INTO $tbl_name (type, weight, side, size, quantity)
VALUES ("$stock_type", "$weight", "$side", "$size" , "$quantity")';
If any of those columns are char, varchar or date you need to quote them.
$sql="INSERT INTO $tbl_name ( type, weight, side, size, quantity)
VALUES ('$stock_type', $weight, '$side', $size, $quantity)";
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 7 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I am trying to execute the following query:
INSERT INTO table_timesheet (name, datein, dateout)
VALUES ('Rupert', 'NOW()', '')
WHERE NOT EXISTS (
SELECT name FROM table_listnames WHERE datein='NOW()'
);
But this returns an error.
Basically I don't want to insert a record if the 'datein' field of the record already exists in another record - how to check if the new datein is unique?
And how can i insert in the same way the date out on the same row something like an update the datein row?
This INSERT query will do exactly what you want:
INSERT INTO table_timesheet (name, datein, dateout)
SELECT 'Rupert', NOW(), null
FROM DUAL
WHERE NOT EXISTS (
SELECT * FROM table_listnames WHERE datein=NOW()
);
Please see it here. But a proper solution would be to set a table constraint. How are table_timesheet and table_listnames related? I would use a unique constraint on the datein column, but this depends on what are your requirements.
first check this query (using MYSQLI or PDO ) if this query return false than you insert record
IF... this return false
SELECT name FROM table_listnames WHERE datein='NOW()'
FALSE
INSERT INTO table_timesheet (name, datein, dateout)VALUES ('Rupert', 'NOW()', '')
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I've been trying to insert a tuple into my relation, but it doesn't seem to work.
<?php
$link=mysql_connect ("connection", "name", "pw");
mysql_select_db('pizzaria');
$sql = "INSERT INTO pizza_bakery (Name, Address, Telenum)
VALUES ('Test', 'Test', '111')";
?>
The connection seems to go through ok, as I'm able to print the table out easily on my html page, why is this failing?
Your insert statement should look something like this:
$sql = "INSERT INTO pizza_bakery (Name, Address, Telenum)
VALUES ('Test', 'Test', 111)";
Reason: The last column (Telenum) is an integer datatype and the insert statement was treating it like a string.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I'm trying to insert data into a MySQL table using PHP, but getting the error
Column count doesn't match value count at row 1
mysql_query("INSERT INTO file (id, filename, extention, filelink, filesize, filepass) VALUES('{$random}', '{$filename}', '{$extension}', '{$filelink}', '{$filesize}' '{$filepass}') ") or die(mysql_error());
mysql_query("INSERT INTO file (id, filename, extention, filelink, filesize, filepass) VALUES('{$random}', '{$filename}', '{$extension}', '{$filelink}', '{$filesize}' '{$filepass}') ") or die(mysql_error());
You should add the missing comma after {$filesize}:
mysql_query("INSERT INTO file (id, filename, extention, filelink, filesize, filepass) VALUES('{$random}', '{$filename}', '{$extension}', '{$filelink}', '{$filesize}', '{$filepass}') ") or die(mysql_error());
'{$filesize}' '{$filepass}' is being considered as a single value since you're missing the comma. Your query would look like:
INSERT INTO file (id, filename, extention, filelink, filesize, filepass)
VALUES ( '{$random}',
'{$filename}',
'{$extension}',
'{$filelink}',
'{$filesize}' '{$filepass}')
There. You have 6 columns and 5 values. The column count doesn't match the value count and hence MySQL throws an error message.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I have two queries in my PHP file:
$q1 = " INSERT INTO team_password ( team_name, password ) VALUES ( '". $team_name."', '". $password."' )";
$result = mysqli_query($con,$q1);
it is working fine.
$q2 = " INSERT INTO all_users ( user_name, team_name ) VALUES ('". $user_name."', '". $team_name."')";
$all_users_var = $mysqli_query($con,$q2);
But this query is not responding.
all_users have four columns user_name, team_name, longitude and latitude.
longitude and latitude have default have values NULL.
Any help will be appreciated.
I think the guilty here is the $ sign before your mysqli_query().
When you have a doubt, you should check your php_error.log :)
It is the $ sign before mysqli_query() which is creating problems, remove $ sign and execute the code
Try this:
$q2 = " INSERT INTO all_users ( user_name, team_name ) VALUES ('$user_name','$team_name')";
$all_users_var = mysqli_query($con,$q2);
or this one
$q2 = mysqli_query("INSERT INTO all_users(user_name, team_name) VALUES('$user_name','$team_name')") or die(mysqli_error());
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm using the below query to insert data into a MySQL database. But this not working.
I'm also using this type query in my other page and that's working fine.
This is the SQL query:
$query="INSERT INTO `add7ras_work`.`movies` (`url`, `title`, 'description')
VALUES ('$url','$title', '$desc');";
$result=mysql_query($query);
You used single quotes around description instead of backticks:
$query="INSERT INTO `add7ras_work`.`movies` (`url`, `title`, `description`) VALUES ('$url','$title', '$desc');";
Standard disclaimer: Read up on PDO and MySQLi as mysql_x functions are deprecated.
Bad quoting:
$query="INSERT INTO `add7ras_work`.`movies` (`url`, `title`, 'description')
^-- ^---
' quotes in SQL turn the quoted data into a string. This means you're using a string in a fieldname context, which does not work.