Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
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.
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.
Improve this question
I have a database called mkmatchmanager and it has a table called warviewer as you can see below.
You can see the structure of the table here. I am trying to add a row in this table:
$a= mysqli_connect("localhost","username","password","my_mkmatchmanager");
if (mysqli_connect_errno()) {
echo "Failed to connect";
}
mysqli_query($a, "INSERT INTO `my_mkmatchmanager`.`warviewer` (`clan1`, `score1`, `clan2`, `score2`, `table`) VALUES ('test3', '330', 'test4', '241', 'www.mylink.com'");
mysqli_close($a);
This code is included in a file called salva.php. This code by the way doens't work because the query doesn't add the data in the table. Do you have any idea?
Put your double quotes after the parentheses...instead of this:
mysqli_query($a, "INSERT INTO `my_mkmatchmanager`.`warviewer` (`clan1`, `score1`, `clan2`, `score2`, `table`) VALUES ('test3', '330', 'test4', '241', 'www.mylink.com'");
it should be this:
mysqli_query($a, "INSERT INTO `my_mkmatchmanager`.`warviewer` (`clan1`, `score1`, `clan2`, `score2`, `table`) VALUES ('test3', '330', 'test4', '241', 'www.mylink.com')");
should be
mysqli_query($a, "INSERT INTO `my_mkmatchmanager`.`warviewer` (`clan1`, `score1`, `clan2`, `score2`, `table`) VALUES ('test3', '330', 'test4', '241', 'www.mylink.com')");
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
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.
Closed 2 years ago.
Improve this question
I'm creating a small project that scrapes specific webshops and gives an alert when the price changed.
When I try to insert a new record (if price is up/down) it won't insert the record. A connection with the database is in place as I check if the last known price went up or down.
$sql = "INSERT INTO `product_prices` (`productId`, `shopId`, `url`, `originalPrice`, `lowestPrice`, `dateChanged`) VALUES ($productId, $shopId, '".$url."', '".$originalPrice."', '".$lowestPrice."', '".$dateChanged."')";
When I echo $sql it generates this:
INSERT INTO `product_prices` (`productId`, `shopId`, `url`, `originalPrice`, `lowestPrice`, `dateChanged`) VALUES ('1', '1', 'https://www.webshop.com/', '999,99', '800', '2020-07-28 15:04:30')
When I use a remote SQL client (like Sequal Pro) and paste the output of above line it will insert the record. What am I doing wrong?
Problem found, I wasn't using $mysqli->query($sql); after inserting. Now I will dive into SQL injection. Thanks #nico for the heads-up.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
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.
Closed 7 years ago.
Improve this question
I'm trying to show some data from a table in my database but i want it to show a specific ID "rid" that i get from another page with the code:
my SQL code is:
SELECT rid
, tid
, qid
, aid
, points
FROM result
WHEN rid = $val
if i delete WHEN rid=$val i will get all the all the "points" from my database. But i want to show a specific ID (rid). what should i do?
The correct SQL Statement would be
SELECT rid, tid, qid, aid, points FROM result WHERE rid=$val
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 is not reproducible or was caused by typos. It is not currently accepting answers.
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.
Closed 8 years ago.
Improve this question
I am trying to run this code to insert a new row in my "questions" table:
$sql = "INSERT INTO questions (id,quiz_id,question,image,type,option,answer,explanation,date)
VALUES (:id, :quiz_id, :question, :imagesstring, :type, :optionsstring, :answer, :explanation, :date)";
$query = $db->prepare($sql);
$results = $query->execute(array(
":id" => $id,
":quiz_id" => $quiz_id,
":question" => $question,
":imagesstring" => $imagesstring,
":type" => $type,
":optionsstring" => $optionsstring,
":answer" => $answer,
":explanation" => $explanation,
":date" => $date
));
It says there's a syntax error near, but I cannot find it. I checked the table multiple times and the columns correspond with the variables I inserted. Also the variables have the proper value assigned to them. Please help.
OPTION is a reserved keyword. If you don't want to receive any syntax error, you need to escape it using backtick,
INSERT INTO questions (id, quiz_id, question, image, type,
`option`, answer, explanation, date)
VALUES(...)
MySQL Reserved Keywords List