This script works with require_once and produces warnings for line 6 when I try to use $mysqli = new... (which I've commented out). Please help me with this script:

[codebox]<?php

require_once "connect_to_mysql.php";

//$mysqli = new mysqli("localhost","user","pw","db");

$result = mysql_query("SELECT * FROM example")

or die(mysql_error());

echo "<table border='1'>";

echo "<tr> <th>Name</th> <th>Age</th> </tr>";

while($row = mysql_fetch_array( $result )) {

echo "<tr><td>";

echo $row;

echo "</td><td>";

echo $row;

echo "</td></tr>";

}

echo "</table>";

//mysqli_close($mysqli);

?> [/codebox]

Thank-you

For require_once, I thought the syntax was like this:

require_once('connect_to_mysql');

And also, couldn't you use this function to connect to MySQL?

$cn = mysqli_connect("localhost", "user", "pw", "db");

So to connect and request info from the database you could do something like this

$cn = mysqli_connect("localhost", "user", "pw", "db");

//set the query in a variable
$query = "SELECT * FROM table";

$result = mysqli_query($cn, $query);

if(!$result) die("Query fail");

Then you could just continue with your while loop, since there isn't an error with that, right?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.