Search Query using PHRETS not Working - php

I am new to PHRETS. And need to build one search panel which could search and display using PHRets and Rets Server. Here its getting connected but doesn't show results. I want something that can show results nicely.
SEARCH.PHP
<?php
$rets_login_url = "http://connectmls-rets.mredllc.com/rets/server/login";
$rets_username = "xxxxxxxx";
$rets_password = "xxxxxxxx";
require_once("phrets.php");
$rets = new phRETS;
//echo "+ Connecting to {$rets_login_url} as {$rets_username}<br>\n";
$connect = $rets->Connect($rets_login_url, $rets_username, $rets_password);
//echo "<pre>";
//print_r($rets);
//echo "</pre>";
if ($connect) {
echo "<p class=\"success\">Connected</p>";
////////////////////////////////////////////////////////
$search = $rets->SearchQuery("Property","ResidentialProperty","(ListDate=1990-01-01+)",array("StandardNames" => 1));
while ($listing = $rets->FetchRow($search)) {
echo "Address: {$listing['StreetNumber']} {$listing['StreetName']}, ";
echo "{$listing['City']}, ";
echo "{$listing['State']} {$listing['ZipCode']} listed for ";
echo "\$".number_format($listing['ListPrice'])."\n";
}
$rets->FreeResult($search);
////////////////////////////////////////////////////////
}
else {
echo "<p class=\"error\">Not connected:<p>";
print_r($rets->Error());
exit;
}
if (!empty($rets->err)) {
echo "HTTP {$rets->err}\n";
}
$last_req = $rets->LastRequest();
if ($last_req['ReplyCode'] != 0) {
echo "RETS {$last_req['ReplyCode']}: {$last_req['ReplyText']}\n";
}
//echo "Server reports: ".$rets->GetServerVersion()."\n";
?>
NOT SHOWING RESULTS. PLEASE HELP AS SOON AS POSSIBLE.

Try this
$search = $rets->SearchQuery("Property","ResidentialProperty",
"(ModificationTimestamp=2011-01-01T00:00:00+) ,
(ListPrice=300000)", array("Limit" => "20",
"Format" => "COMPACT","StandardNames" => "1","Count"=>1) );

Related

PHP Ajax to Display Clicked Result

I have the codes to search autocomplete from MySQL and the match query can be clicked and direct me to a new page. How can i have the result of the clicked queries to be displayed in the new page w/out using any URL from database because I need to avoid using lots of HTML files. Thank you.
<p id="searchresults">
<?php
// PHP5 Implementation - uses MySQLi.
// mysqli('localhost', 'yourUserbookTitle', 'yourPassword', 'yourDatabase');
$db = new mysqli('localhost', 'root', '', 'book');
if(!$db) {
// Show error if we cannot connect.
echo 'ERROR: Could not connect to the database.';
} else {
// Is there a posted query string?
if(isset($_POST['queryString'])) {
$queryString = $db->real_escape_string($_POST['queryString']);
// Is the string length greater than 0?
if(strlen($queryString) >0) {
$query = $db->query("SELECT * FROM bookinfo WHERE bookTitle LIKE '%" . $queryString . "%'");
if($query) {
// While there are results loop through them - fetching an Object.
// Store the category id
$bookTitle = 0;
while ($result = $query ->fetch_object()) {
if($result->bookTitle != $bookTitle) { // check if the category changed
echo '<span class="category">'.$result->bookTitle.'</span>';
$bookTitle = $result->bookTitle;
}
echo '<a href="'.$result->url.'">';
echo '<img src="search_images/'.$result->bookimage.'" alt="" />';
$bookTitle = $result->bookTitle;
if(strlen($bookTitle) > 35) {
$bookTitle = substr($bookTitle, 0, 35) . "...";
}
echo '<span class="searchheading">'.$bookTitle.'</span>';
$author = $result->author;
if(strlen($author) > 80) {
$author = substr($author, 0, 80) . "...";
}
echo '<span>'.$author.'</span></a>';
}
echo '<span class="seperator">Nothing interesting here? Try the sitemap.</span><br class="break" />';
} else {
echo 'ERROR: There was a problem with the query.';
}
} else {
// Dont do anything.
} // There is a queryString.
} else {
echo 'There should be no direct access to this script!';
}
}
?>
</p>
I don't know if I get your problem right, but if you need to display a new page with the selected book data/review/comments, I would add :
echo '<span>'.$author.'</span></a>'; /* after this line */
echo '<span>Read more > click here</span>'; /* where $bookID id the ID column in your DB */
Then, on the new page, retrieve data from DB according to $bookID value and display it...

"Cannot POST " php

I have obviously seen other threads related to the matter and couldn't solve my problem. I am not experienced with php. My file structure is like:
-search/
-index.jade
-search.php
css/
index.css
My index.jade code:
html
head
script(src='https://code.jquery.com/jquery-3.1.0.min.js')
link(href="css/index.css", rel="stylesheet", type="text/css")
body
form(id="search", method="POST", action="search.php")
input(type="text",placeholder="Search for...",name="search_bar")
input(type="submit",name="submit")
My search.php code:
<?php
$SQL_HOST = "peanuts";
$SQL_PSWD = "more_peanuts";
$SQL_USER = "peanuts_again";
$SQL_DB = "no_peanuts";
// jk...
try {
$link = new mysqli($SQL_HOST, $SQL_USER, $SQL_PSWD, $SQL_DB);
} catch (Exception $e) {
echo "PDO connection error: " . $e->getMessage();
exit(1);
}
$search = $_POST['search_bar']."*";
$search_query = $link->prepare("SELECT name FROM products WHERE MATCH(name) AGAINST (? IN BOOLEAN MODE)");
$search_query->bind_param('s', $search);
$search_query->execute();
$search_query->store_result();
$search_rows = $search_query->num_rows;
$search_query->bind_result($product_name);
if($search_rows > 0) {
while($search_query->fetch()) {
echo "Your search returned $search_rows results";
echo "$product_name <br>";
}
}
else {
echo "Your search returned no results, sorry :(";
}
?>
I keep getting: "Cannot POST /search/search.php". Help?

Error while parsing JSON from Database for Android App. (No tag defined)

I have created a json for getting mysql data for a news app in android & ios. Whenever I am parsing the json.php file it returns "No tag defined" and the app stopped working both android and ios. Here is the code sample that I was trying to work out.
<?php
header('content-type: application/json; charset=utf-8');
$con = mysql_connect("localhost","####","###");
if (!$con){
die('Could not connect: ' . mysql_error());
}
mysql_select_db("###", $con);
$date = date('Y-m-d');
//$date = '2014-02-01';
$year = substr($date, 0, -6);
$month = substr($date, 5, -3);
$day = substr($date,-2, 10);
if($month==01) $month1="january";
else if($month==02) $month1="february";
else if($month==03) $month1="march";
else if($month==04) $month1="april";
else if($month==05) $month1="may";
else if($month==06) $month1="june";
else if($month==07) $month1="july";
else if($month==08) $month1="august";
else if($month==09) $month1="september";
else if($month==10) $month1="october";
else if($month==11) $month1="november";
else if($month==12) $month1="december";
$table=$month1.$year;
//$table = $february2014;
if(isset($_REQUEST['tag']) && $_REQUEST['tag'] != ''){
$tag = $_REQUEST['tag'];
if($tag =='category_page' && isset($_REQUEST['menu_id']) && $_REQUEST['menu_id'] !='' ) {
$menu_id = $_REQUEST['menu_id'];
try{
$i=0;
$query = mysql_query("SELECT * FROM $table WHERE menu_id=1 AND news_date ='$date'");
if($query === FALSE) {
die(mysql_error());
}
while($data=mysql_fetch_array($query)){
$responce[$i]['news_id'] = $data['news_id'];
$responce[$i]['news_title'] = str_replace("\t",'',str_replace("\r\n\t",'', substr(strip_tags($data['news_title']),0,110)));
$responce[$i]['news_reporter'] = str_replace("\t",'',str_replace("\r\n\t",'', substr(strip_tags($data['news_reporter']),0,110)));
$responce[$i]['news_details'] = str_replace("\t",'',str_replace("\r\n\t",'', substr(strip_tags($data['news_details']),0,110)));
$responce[$i]['photo'] = $data['photo'];
$responce[$i]['path'] = 'admin/'.str_replace('\\','',$data['path']);
$responce[$i]['menu_id'] = $data['menu_id'];
$responce[$i]['menu_type'] = $data['menu_type'];
$responce[$i]['news_publish_status'] = $data['news_publish_status'];
$responce[$i]['news_order'] = $data['news_order'];
$responce[$i]['news_date'] = $data['news_date'];
$responce[$i]['news_time'] = $data['news_time'];
$responce[$i]['added_by'] = $data['added_by'];
$responce[$i]['directory'] = $data['directory'];
$responce[$i]['read_number'] = $data['read_number'];
$responce[$i]['comment_number'] = $data['comment_number'];
$responce[$i]['news_comment_table_name'] = $data['news_comment_table_name'];
$i++;
}
} catch(Exception $e) {
$responce = 'Exception: '.$e->getMessage();
}
}else{
$responce = "category or Menu id is not Defined";
}
echo json_encode($responce);
}else{
echo json_encode("No tag Defined");
}
?>
not getting any way to fix it up. can any one help me out.Would appreciate your kind assistance.
Try this
if(isset($_REQUEST['tag'])){
Instead of
if(isset($_REQUEST['tag']) && $_REQUEST['tag'] != ''){

PHP certain part of code is not executing

Hi I am facing a unique issue with my PHP script.Here is my code. After writeToDB() is executed I dont see the echo ("<script> top.location.href=www.facebook.com</script>");
Can someone let me know why my script stops executing after writing to db?
<?php
function writeToDB($access_token,$uid,$username,$birthday,$gender,$age)
{
/* Database Connection */
$user = "xxxx";
$password = "xxxx";
$host = "xxxxxxxxxxxxxxxxxx";
//connect to database, where tsnames.ora is setup
$connect_obj = oci_connect($user, $password, $host);
if ($connect_obj) {
error_log("connected okay");
} else {
$err = OCIError();
echo "Oracle connection error " . $err[text];
return;
}
$select_query = "SELECT USER_ID FROM FBTABLE WHERE USER_ID= '$uid'";
$select_sql_stmt = oci_parse($connect_obj, $select_query);
//execute statement
try {
$r = oci_execute($select_sql_stmt, OCI_DEFAULT);
if (!$r) {
$p = oci_error($select_sql_stmt);
echo "Oci Execute error";
}
} catch (Exception $e) {
echo "<br>Failed to get database info" . $e->getMessage();
}
$user_id_in_db = null;
while (oci_fetch($select_sql_stmt)) {
$user_id_in_db = oci_result($select_sql_stmt, 'USER_ID');
}
// User already exists in db so update instead of insert
if ($user_id_in_db != null) {
$query ="UPDATE FBTABLE SET ACCESS_TOKEN='$access_token' WHERE USER_ID='$uid'";
} else {
$query = "INSERT INTO FBTABLE(ACCESS_TOKEN, USER_ID,USER_NAME,BIRTHDAY,GENDER,AGE)
VALUES
('$access_token','$uid','$username','$birthday','$gender','$age')";
}
//create sql statement
$sql_statement = oci_parse($connect_obj, $query);
//execute statement
try {
$r = oci_execute($sql_statement, OCI_DEFAULT);
if (!$r) {
$p = oci_error($sql_statement);
echo "Oci Execute error";
}
} catch (Exception $e) {
echo "<br>Failed to get database info" . $e->getMessage();
}
//Commit transaction
$committed = oci_commit($connect_obj);
//Test whether commit was successful. If error occurred, return error message
if (!$committed) {
$error = oci_error($conn);
echo 'Commit failed. Oracle reports: ' . $error['message'];
}
//close the connection
$oci_free_statement($sql_statement);
if (oci_close($connect_obj)) {
echo " oci connection not closed!!!";
}
//close the connection
$oci_free_statement($sql_statement);
}
?>
<html>
<body>
<?php
$access_token = $_GET['access_token'];
$uid = $_GET['uid'];
$username = $_GET['username'];
$birthday = $_GET['birthday'];
$gender = $_GET['gender'];
$age = $_GET['age'];
echo $username;
writeToDB($access_token,$uid,$username,$birthday,$gender,$age);
echo ("<script> top.location.href=www.facebook.com</script>");
?>
</body>
</html>
i think error is in $oci_free_statement($sql_statement); must be oci_free_statement($sql_statement); extra $ before oci_free_statement
http://php.net/manual/en/function.oci-free-statement.php
no any error show because of error_display is off
Your JavaScript code should be
echo ("<script> top.location.href='http://www.facebook.com';</script>");
It's happen because writeToDB() causes error. You don't see this error because error_display is off or error_reporting = 0
Also maybe you didn't install OCI8. So when you call oci_connect it will cause error.
Thanks.
you are not using quotes around the string:
www.facebook.com should be 'www.facebook.com'

Search Multiple AD DN's withPHP

Hi I have a PHP script that searches my AD, but how can I make it search more than one DN. I've tried the exmample on php.net and cannot get it to work.
Help appreciated:
<?php echo "<?xml version='1.0' encoding='utf-8' ?>" ?><?php echo "<ul class='LSRes'>" ?>
<?php
if( isset($_GET['q']) &&!empty($_GET['q']) ){
// all your ldap code
// Designate a few variables
$host = "10.10.10.10"; // Add in your AD host name or IP
$user = "DOMAIN\user"; // Add in your AD access account user name
$pswd = "password"; // Add in your AD access account user name password
$ds = ldap_connect($host)
or die( "Could not connect!" );
// Set version number
ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3)
or die ("Could not set ldap protocol");
// Binding to ldap server
$bd = ldap_bind($ds, $user, $pswd)
or die ("Could not bind");
// Create the DN - Add in the OU of your AD
$dn[] = "OU=uk,OU=Accounts,DC=mywebsite,DC=com";
$dn[] = "OU=us,OU=Accounts,DC=mywebsite,DC=com";
$id[] = $ds;
$id[] = $ds;
//$filter = 'samaccountname='.$_POST['username'];
$filter = "(|(givenName=".$_GET['q']."*) (sn=".$_GET['q']."*) (displayname=".$_GET['q']."*) (samaccountname=".$_GET['q']."*))";
$result = ldap_search($id,$dn,$filter);
$search = false;
foreach ($result as $value) {
if(ldap_count_entries($ds,$value)>0){
$search = $value;
break;
}
}
if($search){
$entries = ldap_get_entries($ds, $search);
}
if ($entries["count"] > 0) {
for ($i=0; $i<$entries["count"]; $i++) {
echo "<span class='LSstyle'>Name: <strong>".$entries[$i]["displayname"][0]." ".$entries[$i]["sn"][0]."</strong></span><br />";
echo "<span class='LSstyle'>Short name: <strong>".$entries[$i]["samaccountname"][0]."</strong></span><br />";
echo "<span class='LSstyle'>Phone: <strong>".$entries[$i]["telephonenumber"][0]."</strong></span><br />";
echo "<span class='LSstyle'>Title: <strong>".$entries[$i]["title"][0]."</strong></span><br />";
echo "<span class='LSstyle'>Dept: <strong>".$entries[$i]["department"][0]."</strong></span></p>";
}
} else {
echo "<span class='LSstyle_noresults'><strong>No results found</strong></span>";
}
ldap_unbind($ad);
}
?>
Seeing as ldap_search does not take an array as $base_dn, you will probably have to loop $dn as Viper_Sb suggested.

Categories