Hi guys. I'm kinda new into MySQL and PHP. but im in this challenge and im slowly getting things done.
I was about to test the website and I get this error:
Fatal error: Uncaught TypeError: mysqli_connect(): Argument #1 ($hostname) must be of type ?string, array given in C:\xampp\htdocs\scandiweb-test-assignment\connect.php:8 Stack trace: #0 C:\xampp\htdocs\scandiweb-test-assignment\connect.php(8): mysqli_connect(Array, Array, Array, Array) #1 C:\xampp\htdocs\scandiweb-test-assignment\index.php(3): include('C:\\xampp\\htdocs...') #2 {main} thrown in C:\xampp\htdocs\scandiweb-test-assignment\connect.php on line 8
connect.php
<?php
$host =['localhost'];
$dbusername =['root'];
$password =[''];
$dbname =['test'];
$tblname =['products'];
$conn = mysqli_connect('$host','$dbusername','$password','$dbname');
if(!$conn->connect_error){
die('Could not Connect MySql Server: '.$conn->connect_error );
}
?>
add.php
<?php
$sku = $_POST['sku'];
$name = $_POST['name'];
$price = $_POST['price'];
$productType = $_POST['productType'];
$size = $_POST['size'];
$weight = $_POST['weight'];
$height = $_POST['height'];
$width = $_POST['width'];
$length = $_POST['length'];
include "connect.php";
$sql = "INSERT INTO products(sku, name, price, productType, size, weight, height, width, length) values('$sku','$name','$price','$productType','$size','$weight','$height','$width','$length')";
if ($conn->query($sql) === TRUE) {
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
header("Location: ./index.php", TRUE, 301);
exit();
What I have tried:
I've tried changing the code several times, tried a lot of things i got from google and it didn't work (yet)
I know i need to keep reading the manual but it's basic chinese to me. It helps me a lot when i follow tutorials from youtube, but sometimes i dont find my specific error so i don't get an explanation of what's happening (a translated explanation, to me, a beginner)