...from MySQL
Here is my code...
$sqlquery = "SELECT * FROM liecon63_bizdir WHERE bizcategory = '".$category."'";
$sqlresult = mysql_query($sqlquery);
$sqlmyrow = mysql_fetch_array($sqlresult, MYSQL_ASSOC);
but I'm getting errors on the third line...
Need help with my crappy code to get PHP to return some data
Moderator: General Moderators
-
prototype18
- Forum Commoner
- Posts: 25
- Joined: Wed Aug 18, 2010 9:52 am
Re: Need help with my crappy code to get PHP to return some
What errors?prototype18 wrote:...from MySQL
Here is my code...
$sqlquery = "SELECT * FROM liecon63_bizdir WHERE bizcategory = '".$category."'";
$sqlresult = mysql_query($sqlquery);
$sqlmyrow = mysql_fetch_array($sqlresult, MYSQL_ASSOC);
but I'm getting errors on the third line...
On all mysql_ commands, it is helpful to trap the MySQL server error message if there is one, by using or die(mysql_error()), which will have no effect if the command ends successfully, but will halt execution and print the MySQL server error message if it fails. Like this:
Code: Select all
$sqlresult = mysql_query($sqlquery) or die(mysql_error();
$sqlmyrow = mysql_fetch_array($sqlresult, MYSQL_ASSOC) or die(mysql_error();-
prototype18
- Forum Commoner
- Posts: 25
- Joined: Wed Aug 18, 2010 9:52 am
Re: Need help with my crappy code to get PHP to return some
Okay, I trappedthe mysql error message and its saying that there is no db selected...
Re: Need help with my crappy code to get PHP to return some
Ensure once you have made a connection to the database host, you select the correct database.
See here:
See here:
Code: Select all
<?php
//Database credentials
$dbHost = 'localhost';
$dbUser = 'username';
$dbPass = 'password';
$dbName = 'databasename';
//Connect to MySQL database server
$connection = mysql_connect($dbHost, $dbUser, $dbPass) or die(mysql_error());
//Select Database
mysql_select_db($dbName, $connection) or die(mysql_error());
?>