Hello there
Quick insight of what im trying to achieve here is.
User adds data to a database called property in (addproperty.php)
Then user can search for specific data in that property database
Here is the code
addproperty.php

<?php
  $dbhandle = sqlite_popen("property", 0666, $err_msg);
  if(!$dbhandle) die("Could not open the database");

  $query = "CREATE TABLE property(postcode VARCHAR(255),price VARCHAR(255),imagefile VARCHAR(255),visits VARCHAR(255))";     
  if(!sqlite_query($dbhandle, $query)){ echo "table not created (maybe already created)"; }
 
 $postcode = $_POST['postcode']; 
 $price = $_POST['price']; 
 $imagefile = $_POST['imagefile'];
 $visits = $_POST['visits'];
 $query = "INSERT INTO property VALUES ('$postcode', '$price', '$imagefile', '$visits')";

  if(!sqlite_query($dbhandle, $query)) { echo "Could not insert table row"; }
  
 
 $query = sqlite_query($dbhandle, 'SELECT * FROM property');  //result set goes into query
 $result = sqlite_fetch_all($query, SQLITE_ASSOC);  //calls columns by name (or NUM for col num eg 0,1..)

 // each result array element contains a row of table. The row holds pairs of row name, row value 
 //print_r( $result);  // useful debug - show all results

 foreach ($result as $arow) {
    echo '<br> <b>postcode:</b> ' . $arow['postcode'] . '  <b>price:</b> ' . $arow['price'] . ' <b>imagefile:</b> ' . $arow['imagefile'] . ' <b>visits:</b> ' . $arow['visits'];
   }
 sqlite_close($dbhandle);
?>

<form action='' method=post> 
    Postcode <input type='text' name='postcode' /> <br>
    Price <input type='text' name='price' /> <br>
	Imagefile <input type='text' name='imagefile' /> <br>
    Visits <input type='text' name='visits' /> <br>
    <input type='submit' value='Submit' /> 
</form>

And here is the code in search.php

<html>
<body>
<form action="" method="post"> 
Postcode: <input type="text" name="postcode" />
<input type="submit" />
</form>
<?php
$dbhandle = sqlite_popen("property", 0666, $err_msg);
if(!$dbhandle) die("Could not open the database");

sqlite_select_db("property", $dbhandle); // select my database "properties" 
// select from properties row postcode where postcode = user type data
$result = sqlite_fetch_all("SELECT * FROM property WHERE postcode='$_POST[postcode]'");

while($row = sqlite_fetch_array($result)) // when found display data
  {
  echo $row['postcode']; // display all matching post codes
  echo "<br />";
  }
?>
</body>
</html>

If any one could tell me what i am missing here, as it doesn't work :(. Help appreciated :) !

anyone ??

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.