PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 5th, 2013, 08:27 AM
just_cant_do_it just_cant_do_it is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2013
Posts: 1 just_cant_do_it User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 29 sec
Reputation Power: 0
Grabbing info from database and displaying content

I have been working on a project to establish if when a postcode entered is listed on my database. If the postcode is listed I want the information relayed back to the user confirming the postcode, level and if it is an area known for flooding (all the information is on the database).

I have a basic form
[code]
<form method="post" action="database.php">
<div align="center" class="style1">
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<table width="80%" border="1" class="style1" bordercolor="#80A0BB" bcellpadding="0">
<tr>
<td><p align="center">&nbsp;</p>
<p align="center">Enter postcode :
<input name="postcodes" type="text" id="postcodes" size="15" />
<?php echo $postcode ?> <br />
<br />
<br />
<input name="Submit" type="submit" value="Click to Check" />
</p>
<p>&nbsp;</p></td>
</tr>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
</div>
</form>

this is then feed to the database.php page which connects to the database but doesnt return the correct value. Infact, any postcode I put in returns a value saying not listed on the database.

My php code is
[php]
$postcode = "E9 7TR";
$result = mysql_query("SELECT * FROM `TABLE 1` WHERE postcode='$postcode' ")
or die(mysql_error());

$row = mysql_fetch_array( $result );
if(mysql_num_rows($row) >= 1)
{
echo "Postcode: ".$row['postcode'];
echo "Level: ".$row['level'];
echo "Floodlevel: ".$row['floodlevel'];
} // display success message

else { echo "The postcode entered is not listed on the database";
}

Any help would be appreciated!

Reply With Quote
  #2  
Old March 5th, 2013, 09:14 AM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,864 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 1 Day 20 h 33 m 18 sec
Reputation Power: 813
Hi,

this is a PHP issue, which has absolutely nothing to do with MySQL.

You apply mysql_num_rows() to an array (namely $row), which of course makes no sense. You need to pass $result to the function.

Apart from this bug, there are several other issues:
  • Whatever book or online tutorial you're learning from, throw it away. This style of writing HTML and PHP is hopelessly outdated -- since 15 years or so. Using tables for layouting was fine in the 90s, but in the 21. century, people use CSS. The same goes for the PHP code. The old MySQL extension is dead since 10 years. People today use PDO or MySQLi.
  • You have several big security holes. Check the link in my signature to avoid typical mistakes.
  • Turn on your error reporting during development: error_reporting(-1)
  • Don't use SELECT *. It's inefficient, error-prone and potentially dangerous (because it will fetch any column, no matter how critical it is). Select specific columns. Don't use nonstandard (and nonsense) table names like TABLE 1. Name the table according to its content. Maybe postcodes?

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Grabbing info from database and displaying content

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap