...

View Full Version : php error please help



Snitz
03-30-2007, 08:43 AM
This is the code to fetch data from the database, but it's giving me an error.


<?php
$mysql = mysql_connect("localhost", "revoluti_darkquo", "bymyside", "revoluti_darkquote");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
} else {
$sql = "SELECT * FROM data ORDER BY id desc LIMIT 5";
// $result = "SELECT * FROM data";
// $num_rows = mysql_num_rows($result);
$res = mysqli_query($mysqli, $sql);
if ($res) {
while ($newArray = mysqli_fetch_array($res, MYSQLI_ASSOC)) {
$id = $newArray['id'];
$quote = $newArray['quote'];
$email = $newArray['email'];
$name = $newArray['name']; ?>
<fieldset class="fieldset">
<legend>Quote #<?php echo "".$id."" ?></legend>
<table border="0" cellpadding="0" cellspacing="3" width="100%">
<tbody><tr>
<td>
<div align="center"><?php echo"".$quote."" ?></div><br />
<div align="right"<b><i>By <a href="mailto:<?php echo "".$email."" ?>"><?php echo "".$name."" ?></a></i></b><br /></div>
</td>
</tr>
</tbody></table>
</fieldset>
<br />
<?php
// echo"".$quote." - <i>By ".$name."</i><br />Thought #".$id."<br/><br />";
}
} else {
printf("Could not retrieve records: %s\n", mysqli_error($mysqli));
}
mysqli_free_result($res);
mysqli_close($mysqli);
}
?>

And this is the error I'm getting!


Fatal error: Call to undefined function: mysqli_connect() in /home/revoluti/public_html/darkquote/index.php on line 81

can you please help?

david_kw
03-30-2007, 05:06 PM
I don't know if it was your intention or not, but do you see you are using mysql_connect and assigning it to $mysql?

if seems like it should be



<?php
$mysqli = mysqli_connect("localhost", "...", "...", "...");
if (mysqli_connect_errno()) {
.
.
.


http://livedocs.phpdoc.info/index.php?l=en&q=function.mysqli-connect

I don't understand why it would cause that error though, but it's something to look at.

david_kw



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum