Ebadly.Decipher
Ebadly.Decipher

Reputation: 81

Php is not printing database information

I just set up a mysql data base, although my php isn't printing out the information that I want printed.

Here's what my code looks like (I've already connected to mysql and created a database successfully, I just need it to print out what I had inserted into it):

// will insert into the table
mysqli_query ($con, "INSERT INTO alarms(Title, Description, DT)
VALUES(getSucked, Agha will smd, 2013-08-05 00:15:12)");

//will print out what we just insert into the table, ie agha smd's
$result = mysqli_query($con,"SELECT * FROM alarms");
while ($row = mysqli_fetch_array($result))
{
echo $row['alarmID'] . " <br> " . $row['Title'] . " <br> " . $row['Description'] . " <br> " . $row['DT'];
}

//closing connection
mysqli_close($con);
echo "<br><br>connection has been closed";

The warning/error I keep getting is:

"Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in B:\DropBox\Dropbox\EbadlyAgha\Ebad\reminders.php on line 83"

Line 83 is where the while loop begins.

Upvotes: 0

Views: 103

Answers (4)

Chris Hayes
Chris Hayes

Reputation: 12050

Your query failed to run. mysqli_query will return false if the query does not execute, hence the warning of mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given. You should always check the return value when interacting with the database, to make sure you are aware of what's going on. PHP will happily coerce many types into other types silently, so you have to be very proactive in your error checking.

Upvotes: 1

iiro
iiro

Reputation: 3118

mysqli_query returns FALSE on failure.

try

if ($result) {
    while ($row = mysqli_fetch_array($result))
    {
    echo $row['alarmID'] . " <br> " . $row['Title'] . " <br> " . $row['Description'] . " <br> " . $row['DT'];
    }
}

Upvotes: 0

Bindiya Patoliya
Bindiya Patoliya

Reputation: 2764

Use

mysqli_query ($con, "INSERT INTO alarms(Title, Description, DT)
VALUES(getSucked, 'Agha will smd', '2013-08-05 00:15:12')");

and try to echoed query and run into phpmyadmin.because your value is with space so you have to use it in ''.

Upvotes: 0

GautamD31
GautamD31

Reputation: 28753

Change your Insert query to

mysqli_query ($con, "INSERT INTO alarms(Title, Description, DT)
VALUES('getSucked', 'Agha will smd', '2013-08-05 00:15:12')");

Your Insert query will fails when you gave the spaces.Try to put them in quotes..

Upvotes: 0

Related Questions