0

I have this code:

include "config.php";
if (isset($connect)) {
    echo "connected";
} else {
    echo "not connected";
}

And this is the config.php file:

$localhost = "localhost";
$db_username = "*****";
$db_password = "*****";
$db_name = "*****"; 
If($connect = mysqli_connect("$localhost ","$db_username ","$db_password ","$db_name ")){}or die{}  

I dont know why, but when I try to do some queryIi dont get anything

$sql="SELECT * FROM table_name ORDER BY column_name ASC";
$query=($connect,$sql);
While($row = mysqli_fetch_object($query)) {
    Echo $row>column;
}

the error is:

 Parse error: syntax error, unexpected '}' in /path/index.php on line 6
1stthomas
  • 731
  • 2
  • 15
  • 22
Iris Tako
  • 133
  • 10

1 Answers1

2

i see a more than one problem in your codes,

First from config.php

If($connect = mysqli_connect("$localhost ","$db_username ","$db_password ","$db_name ")){}or die{}  

This is not right code, error in {}or die{} it must be {} else {die();}

But i recommended you to use this one instead,

$connect = mysqli_connect("$localhost", "$db_username", "$db_password", "$db_name") or die(mysqli_connect_error());

And about the third code have some problems, first

$query=($connect,$sql);

You forgot to use mysqli_query

$query=mysqli_query($connect, $sql);

And in printing the data you must use -> not >

Echo $row->column;

I hope this helps.

Mohammed Alhanafi
  • 886
  • 1
  • 9
  • 22
  • 1
    Please read: [Should we ever check for mysqli_connect() errors manually?](https://stackoverflow.com/q/58808332/1839439) – Dharman Jan 03 '20 at 22:01