0

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

3
Contributors
3
Replies
5
Views
8 Years
Discussion Span
Last Post by __avd
0

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?

Edited by phouse512: Added code

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.