Problems with logging in

Codes here !

Moderators: egami, macek, gesf

Post Reply
NeilWylie
New php-forum User
New php-forum User
Posts: 2
Joined: Wed Mar 01, 2017 3:56 am

Wed Mar 01, 2017 4:16 am

Firstly, let me say that I am very new to this, so please excuse any inane questions I may ask.
The current position is:
  • I have a hosting provider
    I have created a mysql database on their site - the database name is cl22-neil
    I have a simple table in the database - table1 - with 2 fields and 2 records..
    I have uploaded 2 files - connect1.php and test1.php to the public.html folder on their site.
The code for connect1.php is:

Code: Select all

<?php
$servername = "localhost";
$username = "cl22-neil";
$password = "kD4UxhHF-";

// Create connection
$conn = new mysqli($servername, $username, $password);

if (!$conn) {
    echo "Could not connect to server";
    } else {
    echo "Successfully connected";
    }
?>

The code for test1 is:

Code: Select all

<?php
require ('connect1.php');
$q = "Select * from table1";
$result =@mysqli_query($conn,$q);
if ($result) {
    echo "RESULT!";
    } else {
    echo "There are no results";
    }
?>
Connect1 tells me I am successfully connected, but test1 returns "there are no results".

I have 2 questions:
Should the connect1 file not include the database name as a constant?
Why is test1 not working?

Thanks for your help with this.

chorn
php-forum Fan User
php-forum Fan User
Posts: 559
Joined: Fri Apr 01, 2016 2:18 am

Wed Mar 01, 2017 4:48 am

stop supressing error mesage with the @-character. mysqli_query - as to the documentation - may have different result types. one of it is FALSE, so you always have to check for errors first. after that its unclear what you want, you do not fetch any results with mysqli_fetch_object and its unclear what what you mean with $result as it may be error or empty result set.

NeilWylie
New php-forum User
New php-forum User
Posts: 2
Joined: Wed Mar 01, 2017 3:56 am

Thu Mar 02, 2017 12:49 am

Firstly, thank you for replying, and my apologies for not responding sooner. I assumed that I would get a email notification of your post. I think my problem lies in uploading the files to my host provider, rather than the code itself. With a view to proving this, I will export the database and files to a local environment and test them there. I will keep you posted on results.

NigelRen
php-forum Fan User
php-forum Fan User
Posts: 622
Joined: Fri Aug 05, 2011 9:53 am

Thu Mar 02, 2017 1:27 am

The immediate issue may be as a result of the environment, but in the long term it's important to be able to pick up database errors and do something with them. At the moment you are just saying 'ignore any errors' which isn't helpful in debugging and doesn't provide the information which could help in solving your errors.
If an error was displayed/logged and you could post it on here, I'm sure you would get a fix for your problem much quicker!

Post Reply