mysqli

php and mysql, best practices

眉间皱痕 提交于 2021-02-09 05:41:09
问题 I started working with php and mysql today. Basically, what I have, is an empty page with pieces that I fill in from looking up an id in a database. So on my home page I have an url that looks like this: <a href="content/display.php?id=id1"> And then in my display.php I have this: <?php include '../includes/header.php'; $id = $_GET['id']; $mysqli = new mysqli('localhost','username','password','dbname'); if($result = $mysqli->query("SELECT * FROM portfolio WHERE id='".$id."'")) { while($row =

php and mysql, best practices

好久不见. 提交于 2021-02-09 05:40:51
问题 I started working with php and mysql today. Basically, what I have, is an empty page with pieces that I fill in from looking up an id in a database. So on my home page I have an url that looks like this: <a href="content/display.php?id=id1"> And then in my display.php I have this: <?php include '../includes/header.php'; $id = $_GET['id']; $mysqli = new mysqli('localhost','username','password','dbname'); if($result = $mysqli->query("SELECT * FROM portfolio WHERE id='".$id."'")) { while($row =

Table does not exist, but it EXISTS

北慕城南 提交于 2021-02-08 10:40:33
问题 So I'm starting to learn how to use PHP to access MYSQL databases and after successfully connecting to the database. I want to select data from it. However I get the issue that the table doesn't exist. Yet, it exists when I check it in my phpmyadmin. I've checked spelling, capitalization, etc.. and nothing works. I've tried it with multiple databases and I get the same error. So I'm really confused as to whats going on because from the looks of it, there is NOTHING wrong with the code. I've

How to use mysqli prepare statement to login with email or username (Not PDO)?

删除回忆录丶 提交于 2021-02-08 10:37:39
问题 I have saw many answer about php login with username or email, but I can't find the resolution of "Mysqli Prepare Statement", all of them used PDO... My question is, why I can't use two ? to select username or email? My code is here: Database table user --id int(11) UNSIGNED NOT NULL AUTO_INCREMENT, --username varchar(20), --password varchar(255), --email varchar(30), html <form action="login.php" id="login_form" method="post"> <input type="text" name="account" placeholder="username or email"

How to use mysqli prepare statement to login with email or username (Not PDO)?

落花浮王杯 提交于 2021-02-08 10:37:21
问题 I have saw many answer about php login with username or email, but I can't find the resolution of "Mysqli Prepare Statement", all of them used PDO... My question is, why I can't use two ? to select username or email? My code is here: Database table user --id int(11) UNSIGNED NOT NULL AUTO_INCREMENT, --username varchar(20), --password varchar(255), --email varchar(30), html <form action="login.php" id="login_form" method="post"> <input type="text" name="account" placeholder="username or email"

Warning: mysqli_query() expects parameter 1 to be mysqli, object given in [class file] [duplicate]

北慕城南 提交于 2021-02-08 10:14:39
问题 This question already has answers here : mysqli_query() expects parameter 1 to be mysqli, object given (3 answers) Closed 16 days ago . I'm learning OOP, so I've probably done something stupid. I had code working with mysql, but read that mysqli is better, especially since I'm wanting to get an array of objects from the database. I've updated my code to try and work with mysqli now, and have solved some problems, but now I'm stuck. From my database class file: class Database { function _

SQL/PHP: Show top 3 most sold products from database

扶醉桌前 提交于 2021-02-08 08:39:25
问题 I have a database containing the following tables: - product (product_id / name / price / image_id / description) - order ( order_id / date / status / email ) - order_count ( order_id / product_id / number ) - image (image_id / image_link ) I'd like to show the 3 most sold products on my homepage, but can't wrap my head around doing this. I tried this: $sql = "SELECT" * FROM 'product' INNER JOIN 'afbeelding' WHERE 'product'.'image_id' = 'afbeelding'.'image_id' GROUP BY 'product_id' ORDER BY

Multiple queries dependent on each other

China☆狼群 提交于 2021-02-08 06:09:55
问题 I have two queries both dependent on each other, i.e. if first query is not executed the second shouldn't be executed, and the other way around if second can't be executed the first shouldn't be executed. INSERT INTO `table` VALUES (1,2,3) UPDATE `otherTable` SET `val1`=1 WHERE `id`=$idOfInsert ON DUPLICATE KEY UPDATE is not the answer. I tried using mysqli::multi_query but as it turned out it executes the first even though the second can't be executed (it stops on error). How can I achieve

Multiple queries dependent on each other

£可爱£侵袭症+ 提交于 2021-02-08 06:09:27
问题 I have two queries both dependent on each other, i.e. if first query is not executed the second shouldn't be executed, and the other way around if second can't be executed the first shouldn't be executed. INSERT INTO `table` VALUES (1,2,3) UPDATE `otherTable` SET `val1`=1 WHERE `id`=$idOfInsert ON DUPLICATE KEY UPDATE is not the answer. I tried using mysqli::multi_query but as it turned out it executes the first even though the second can't be executed (it stops on error). How can I achieve

Multiple queries dependent on each other

孤街醉人 提交于 2021-02-08 06:08:13
问题 I have two queries both dependent on each other, i.e. if first query is not executed the second shouldn't be executed, and the other way around if second can't be executed the first shouldn't be executed. INSERT INTO `table` VALUES (1,2,3) UPDATE `otherTable` SET `val1`=1 WHERE `id`=$idOfInsert ON DUPLICATE KEY UPDATE is not the answer. I tried using mysqli::multi_query but as it turned out it executes the first even though the second can't be executed (it stops on error). How can I achieve