CageyJ0nnY Posted May 17, 2010 Share Posted May 17, 2010 I have created an array to store data extracted from a dedicated database. I cannot get the code to work and keep geeting an error on line 9; however i cannot see what the error is 8-S. Heres the code: <?php $conn = mysql_connect('jjennings3db.bimserver2.com', 'jjennings3db', 'bullet234345'); mysql_select_db(“jjennings3db”, $conn); $sql = "SELECT * FROM tblProperties WHERE xxx=xxx"; echo "Here are all the properties that match your search:<br>"; $result1 = mysql_query($sql, $conn); while ($array1 = mysql_fetch_array($result1)) { echo "<p>Property Name: " . $array1[PropertyName] . "<br>"; echo "Location: " . $array1[Location] . "</p>"; } ?> p.s I have changed log on details many thanks Jonny Quote Link to comment https://forums.phpfreaks.com/topic/202015-array-help/ Share on other sites More sharing options...
trq Posted May 17, 2010 Share Posted May 17, 2010 You should always check your queries actually execute successfully and return results before trying to use them. $sql = "SELECT * FROM tblProperties WHERE xxx=xxx"; echo "Here are all the properties that match your search:<br>"; if ($result1 = mysql_query($sql, $conn)) { if (mysql_num_rows($result1)) { while ($array1 = mysql_fetch_array($result1)) { echo "<p>Property Name: " . $array1['PropertyName'] . "<br>"; echo "Location: " . $array1['Location'] . "</p>"; } } else { echo "No results found"; } } else { trigger_error(mysql_error() . "<br />" . $sql); } Now, what error are you getting? ?> Quote Link to comment https://forums.phpfreaks.com/topic/202015-array-help/#findComment-1059391 Share on other sites More sharing options...
CageyJ0nnY Posted May 17, 2010 Author Share Posted May 17, 2010 I have inserted the new code and connected to the DB. I am getting a new error message: Notice: No database selected SELECT * FROM tblProperties WHERE xxx=xxx in /home/jjennings3/jjennings3.bimserver2.com/search.php on line 19 line 19 is : trigger_error(mysql_error() . "<br />" . $sql); I am confused 8-S thanks for the help Quote Link to comment https://forums.phpfreaks.com/topic/202015-array-help/#findComment-1059395 Share on other sites More sharing options...
trq Posted May 17, 2010 Share Posted May 17, 2010 See where the Notice states 'No database slected'? That is your problem. In your previous code you have odd quotes around your database name. Quote Link to comment https://forums.phpfreaks.com/topic/202015-array-help/#findComment-1059397 Share on other sites More sharing options...
CageyJ0nnY Posted May 17, 2010 Author Share Posted May 17, 2010 what do you mean by odd quotes? are they the wrong type or not the correct amount? Quote Link to comment https://forums.phpfreaks.com/topic/202015-array-help/#findComment-1059407 Share on other sites More sharing options...
CageyJ0nnY Posted May 17, 2010 Author Share Posted May 17, 2010 okay, i have sorted some things out but i have a new error message: Notice: Unknown column 'xxx' in 'where clause' SELECT * FROM tblProperties WHERE xxx=xxx in /home/jjennings3/jjennings3.bimserver2.com/search.php on line 18 heres how the code looks at the moment: <?php $conn = mysql_connect('jjennings3db.bimserver2.com', 'jjennings3db', 'bullet3475783'); mysql_select_db('jjennings3db', $conn); $sql = "SELECT * FROM tblProperties WHERE xxx=xxx"; echo "Here are all the properties that match your search:<br>"; if ($result1 = mysql_query($sql, $conn)) { if (mysql_num_rows($result1)) { while ($array1 = mysql_fetch_array($result1)) { echo "<p>Property Name: " . $array1['PropertyName'] . "<br>"; echo "Location: " . $array1['Location'] . "</p>"; } } else { echo "No results found"; } } else { trigger_error(mysql_error() . "<br />" . $sql); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/202015-array-help/#findComment-1059430 Share on other sites More sharing options...
trq Posted May 17, 2010 Share Posted May 17, 2010 The field xxx does not exist within your database. Read the error messages, its not rocket science. Quote Link to comment https://forums.phpfreaks.com/topic/202015-array-help/#findComment-1059436 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.