Brendon Wells
Brendon Wells

Reputation: 83

php page coming up blank when trying to access the database

I am having an issue where it seems my insert code is wrong but i do not know how to fix it.

It keeps resorting to my page being blank with no error_log and error reporting is not working either, below is the code

<?php
$connect = mysqli_connect("localhost","dfhdfhd","dfhdfh","fhgdfh");

$url = 'url';
$banner = 'banner';
$title = 'title';
$date = 'date';
$time = 'time';
$description = 'description';
$region = 'region';
$sponsors = 'sponsors';

mysqli_query($connect,"INSERT INTO information (url, banner, title, date, time, description, region, sponsors)
VALUES ('$url', '$banner', '$title', '$date' '$time', '$description', '$region', '$sponsors')";
?>

Upvotes: 1

Views: 41

Answers (2)

Funk Forty Niner
Funk Forty Niner

Reputation: 74217

There's a few things wrong here.

First, a missing comma after '$date' and a missing bracket for your opening $connect,

Here:

mysqli_query($connect,"INSERT INTO information (url, banner, title, date, time, description, region, sponsors)
VALUES ('$url', '$banner', '$title', '$date', '$time', '$description', '$region', '$sponsors')");

Having checked for errors, it would have told you about those errors.

Consult these following links http://php.net/manual/en/mysqli.error.php and http://php.net/manual/en/function.error-reporting.php


Your present code is open to SQL injection. Use prepared statements, or PDO with prepared statements.

Upvotes: 2

Jester
Jester

Reputation: 1408

you should add error_reporting and show mysqli error if a query for some reason doesn't work:

<?php
error_reporting(-1);
$connect = mysqli_connect("localhost","dfhdfhd","dfhdfh","fhgdfh");
if (mysqli_connect_errno())
{
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$url = 'url';
$banner = 'banner';
$title = 'title';
$date = 'date';
$time = 'time';
$description = 'description';
$region = 'region';
$sponsors = 'sponsors';

$result = mysqli_query($connect,"INSERT INTO information (url, banner, title, date, time, description, region, sponsors)
VALUES ('$url', '$banner', '$title', '$date', '$time', '$description', '$region', '$sponsors')");
if (!result)
{
    echo("Error description: " . mysqli_error($connect));
}
?>

See for more information: http://www.w3schools.com/php/func_mysqli_error.asp

Also make sure that the php is not executed somewhere, where errors would be echoed but not visible because they are outside html or hidden by css.

You also forgot a comma inbetween '$data' and '$time' and closing the mysqli_query function.

Upvotes: 0

Related Questions