I'm having troubles selecting data from a MySQL databse [duplicate] - mysql

This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 6 years ago.
I'm attempting to make a column be included only if the ID of the column is in the web address. But it's not returning the data. Any suggestions?
This is what my code looks like
$sql="SELECT * FROM orders WHERE `orders`.`id`= '$form_id'";
$order_data=mysql_query($sql);
$form_id=$_GET['id'];
If anyone has any suggestions, please let me know.

You may use this
$form_id=$_GET['id'];
$sql="SELECT * FROM orders WHERE `orders`.`id`= '$form_id'";
$order_data=mysql_query($sql);
Hopefully this will solve your problem

Related

Is there anyway to remove a row in mysql automatically? Nodejs, my-sql [duplicate]

This question already has an answer here:
Best way to manage row expiration in mysql
(1 answer)
Closed 12 months ago.
In mongodb with mongoose we can remove data automatically like this:
expiresAt:{
type: Date,
default: Date.now(),
index: {
expireAfterSeconds: 500,
},
},
But in mysql I cant find any solution for this. Please help.
you can use the Event Scheduler to start a query every secs,mins,.... if
you have a timestamp
see: https://dev.mysql.com/doc/refman/5.7/en/event-scheduler.html

PhpStorm & Yii2 shows "method insert not found in.." [duplicate]

This question already has answers here:
Method not found in class
(5 answers)
Closed 4 years ago.
I have several cases in Yii2 where the code analysis of PhpStorm will show that it can not find a method, even if these methods are Yii2 own methods.
$collection = Yii::$app->mongodb->getCollection('customer');
$collection->insert(['name' => 'John Smith', 'status' => 1]);
This is a standard example from the Yii2 documentation for mongoDB. But it shows this error:
Method 'insert' not found in (more...)
Please note that it does not state anything after " ... in ..." so I think it does not know at all which class is used at all.
Is there something I tell PhpStorm which class this is? Like via the PHPDoc or something?
The right hint came from Muhammad Omer Aslam in the comments to the original question.
I just needed to add this lphpDoc line just before the use of the insert.
/* #var $collection \Yii\MongoDb\Collection */
Then it will recognise the class used and throws no errors.
Thanks everybody for helping.

Error while connecting C program to MYSQL database [duplicate]

This question already has answers here:
MySQL and C : undefined reference to `_mysql_init#4'|
(3 answers)
Closed 7 years ago.
When I try to connect to my database I get an error :
undefined reference to 'mysql_init#4'
#include<mysql.h>
int main()
{
MYSQL *con;
con = mysql_init(NULL);
return 0;
}
I use code blocks. What is the issue?
"Undefined Reference" to something implies a linker error. In this case you are possibly not linking to the right mysql C library. Link with the appropriate C libraries.
Also, a similar question is answered here

how to work with a column name which has a space? [duplicate]

This question already has an answer here:
Blank spaces in column names with MySQL
(1 answer)
Closed 9 years ago.
I have a column name "user id" now when I use it in insert or... all of the following tries gave me syntax error:
insert into mytbl('user id',..
insert into mytbl(['user id'],..
insert into mytbl([user id],..
How can I solve this problem?
Please let me knbow if you need more clarification
Thanks
Wrap it in ticks:
INSERT INTO mytbl(`user id`,..
to reffer to a table use
tbl1.`user name`

Reverse version of sql LIKE in sqlalchemy [duplicate]

This question already has answers here:
how to pass a not like operator in a sqlalchemy ORM query
(2 answers)
Closed 9 years ago.
By "reverse version of like" I mean exactly like this question. The question is how to make a query like that in sqlalchemy?
I found out that to make "SELECT LIKE" query in sqlalchemy I should make something like that
session.query(Book).filter(Book.title.like("%"+my_title+"%"))
Because like is method of column, I don't know how to use like method to ask about "%" + Book.title + "%".
Thanks to this question, I figure out how to do that :)
session.query(Book).
filter(bindparam('book_title', book.title).contains(Book.title)).first()