MySQL Forums
Forum List  »  PHP

Help with changing a mysql script to mysql code
Posted by: Dawn Sheppard
Date: December 10, 2007 12:47PM

Hello,

I wonder if anyone can help me I am trying to set up an online catalog and I am practicing with the scripting with the 'for dummies' books which have been a help but now I'm stuck. This is the script I have been given


<?php
/* Program: villaCatalog.php
* Desc: Displays a list of villa categories from the
villaCatalog table. Includes descriptions.
* Displays radio buttons for user to check.
*/
?>
<html>
<head><title>Villa Types</title></head>
<body>
<?php
$host="localhost";
$user="";
$password="";
$database="";

$cxn = mysql_connect($host,$user,$password,$dbname)
or die ("couldn't connect to server");

/* Select all categories from villaCatalog table */
$query = "SELECT * FROM villaCatalog ORDER BY villaType";
$result = mysqli_query($cxn,$query)
or die ("Couldn't execute query.");

/* Display text before form */
echo "<div style='margin-left: .1in'>\n
<h1 style='text-align: center'>Villa Catalog</h1>\n
<h2 style='text-align: center'>The following villas are waiting for you.</h2>\n
<p style='text-align: center'>Find your perfect villa</p>
<h3>Which villa are you interested in?</h3>\n";

/* Create form containing selection list */
echo "<form action='ShowVillas.php' method='POST'>\n";
echo "<table cellpadding='5' border='1'>";
$counter=1;
while($row = mysqli_fetch_assoc($result))
{
extract($row);
echo "<tr><td valign='top' width='15%'
style='font-weight: bold;
font-size: 1.2em'\n>";
echo "<input type='radio' name='interest'
value='$villaType'\n";
if( $counter == 1 )
{
echo "checked";
}
echo ">$petType</td>";
echo "<td>$villaDescription</td></tr>";
$counter++;
}
echo "</table>";
echo "<p><input type='submit' value='Select Pet Type'>
</form></p>\n";
?>
</div>
</body></html>

It should display a page from which people choose their villa type.

When I point my browser to it it says the following error

Fatal error: Call to undefined function: mysqli_query() in "my website" on line 22

Which is this line;

/* Select all categories from villaCatalog table */
$query = "SELECT * FROM villaCatalog ORDER BY villaType";
$result = mysqli_query($cxn,$query) ******THIS LINE****
or die ("Couldn't execute query.");

So because my web host is supplying me with mysql I took out the 'i' and it come up with this error;

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in "my website" on line 22
Couldn't execute query.

I am presuming I have a problem with the translation from mysqli to mysql in the script. I am really new and rubbish at this! so if there is anyone who is really good and wants to share their talent by telling me what my script should look like that would be really helpful!

Thank you very much. Please don't use jargon with me either because it will go out my ears :O)

Thanks Dawn

Options: ReplyQuote


Subject
Written By
Posted
November 16, 2005 06:02PM
November 16, 2005 07:41PM
November 20, 2005 09:28AM
d c
December 01, 2005 07:43PM
September 09, 2008 12:08PM
Help with changing a mysql script to mysql code
December 10, 2007 12:47PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.