Jump to content

Protecting Web Form From Showing Data From Database


arshad_1318

Recommended Posts

Well, First Of All Im A New Bee To Php . I've Just Started With It. I've Been Wondering How A Web Form Actually Posts Data Back From A Database. I've Found Several Online Resources And Atlast i've Suceeded In Making One Searchable Database At:

 

http://www.intl.in/search/

 

 

Everythings Just Working Fine. When i Click a Name Like Bob It Return Backs With Data. But When I Click The Web page Directly It Shows Off All The Data Present in Database Table . Like This:

 

http://www.intl.in/search/search.php

 

The Code I've Used Is

<?php
$host_name = "localhost";
$user_name = "";
$password = "";
$db_name = "";

mysql_connect("$host_name" , "$user_name" , "$password");
mysql_select_db("$db_name");

$term = $_POST['term'];


$sql = "SELECT * FROM resultstable WHERE FName like '%$term%' or LName like '%$term%'";
$query = mysql_query($sql) or die("Error: " . mysql_error() . "<br />In Query: " . $sql);


while ($row = mysql_fetch_array($query)){
    echo 'ID: '.$row['ID'];
    echo '<br/> First Name: '.$row['FName'];
    echo '<br/> Last Name: '.$row['LName'];
    echo '<br/> Phone: '.$row['Phone'];
    echo '<br/><br/>';
    }

?>

And I've Always Been Wondering How School Results Are Declared Like In This Website

 

http://results.bharatstudent.com/ssc-results-2012-10th-class-results.php

 

For Example If I Enter An ID Like 1236143276 It Returns Back With Results In Seconds

 

 

We've Actually Been Planning To Host Our School Results Online. Can Some One here With free Time can help us Do it.

 

I would appreciate any help over here.

 

Thanking You,

 

Regards & Wishes,

Arshad Mohammed

Edited by arshad_1318
Link to comment
Share on other sites

while ($row = mysql_fetch_array($query)){
    echo 'ID: '.$row['ID'];
    echo '<br/> First Name: '.$row['FName'];
    echo '<br/> Last Name: '.$row['LName'];
    echo '<br/> Phone: '.$row['Phone'];
    echo '<br/><br/>';
    }

These are the lines which are actually displaying that data from your database.

Link to comment
Share on other sites

When no search term is specified, your query looks like this:

SELECT * FROM resultstable WHERE FName like '%%' or LName like '%%'

This matches EVERY Fname and LName, hence the dump of your data.

 

If you don't want to allow this, you can simply validate the term string:

if (!$term)
   die(); //Or skip over your querying
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.