close ad
Install the LAtest Updates to Work with CC 2017 and CC 2018
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Mysqli Recordset search Like Session not working

Thread began 2/19/2015 1:56 pm by hbibizadeh396670 | Last modified 2/20/2015 11:38 am by Jason Byrnes | 1230 views | 9 replies |

hbibizadeh396670

Mysqli Recordset search Like Session not working

I have created a Hashtag system and need to search based on a url par

my url looks like this:

untitled4.php?SearchTag=#great

I have created this code to create the session and remove the # from the par

<?php
if(isset($_GET['SearchTag'])) {
$SearchTerm = $_GET['SearchTag'];
$SearchTerm = preg_replace("#[^0-9a-z]#i","",$SearchTerm);
}
?>

I now have the mysqli recordset searching based on the var


<?php require_once('Connections/Connections.php'); ?>
<?php require_once('webassist/mysqli/rsobj.php'); ?>
<?php
$Search = new WA_MySQLi_RS("Search",$Connections,1);
$Search->setQuery("SELECT * FROM siteezy_posts WHERE Post = ?");
$Search->bindParam("s", "".(isset($_SESSION['SearchTerm'])?$_SESSION['SearchTerm']:"") ."", "-1"); //colname
$Search->execute();
?>

for some reason it is not working and i only get a blank page?

Thanks in advance

Sign in to reply to this post

Jason ByrnesWebAssist

a blank page means that a php error is occurring but error reporting is turned off.

to turn error reporting on, add the following code at line 1:

<?php
error_reporting(E_ALL);
ini_set('display_errors','on');
?>



once we know what the error is, we will be able to troubleshoot the cause.



one obvious issue i see is that you are trying to use a session variable in the recordset, but i don't see where the session is being created.

Sign in to reply to this post

hbibizadeh396670

Thank you for your reply.

Here is the updated first part of the code

<?php
if(isset($_GET['SearchTag'])) {
$_SESSION["$SearchTerm"] = $_GET['SearchTag'];
$_SESSION["$SearchTerm"] = preg_replace("#[^0-9a-z]#i","",$SearchTerm);
}
?>

I am getting these errors

Notice: Undefined variable: SearchTerm in C:\wamp\www\siteroot111\untitled4.php on line 7
Notice: Undefined variable: SearchTerm in C:\wamp\www\siteroot111\untitled4.php on line 8

thanks again :)

Sign in to reply to this post

Jason ByrnesWebAssist

this code:
$_SESSION["$SearchTerm"] = $_GET['SearchTag'];
$_SESSION["$SearchTerm"] = preg_replace("#[^0-9a-z]#i","",$SearchTerm);

doesn't look right. you can't use a variable in the session name.

try:
$_SESSION["SearchTerm"] = $_GET['SearchTag'];
$_SESSION["SearchTerm"] = preg_replace("#[^0-9a-z]#i","",$_SESSION["SearchTerm"]);

when reporting an error, I need a copy of the page so i can see what the code in the error is.

Sign in to reply to this post

hbibizadeh396670

Ok I am getting results however it is not returning records that contain the value of the session

the results only return if the field contains nothing but the value of the session

In the SQL I changed the = to LIKE but it did not work


Here is the code

<?php
error_reporting(E_ALL);
ini_set('display_errors','on');
?>
<?php
session_start();
if(isset($_GET['SearchTag'])) {
$_SESSION["SearchTerm"] = $_GET['SearchTag'];
$_SESSION["SearchTerm"] = preg_replace("#[^0-9a-z]#i","",$_SESSION["SearchTerm"]);
}
?>
<?php require_once('Connections/Connections.php'); ?>
<?php require_once('webassist/mysqli/rsobj.php'); ?>
<?php
$Search = new WA_MySQLi_RS("Search",$Connections,0);
$Search->setQuery("SELECT * FROM siteezy_posts WHERE Post LIKE ?");
$Search->bindParam("s", "".(isset($_SESSION['SearchTerm'])?$_SESSION['SearchTerm']:"") ."", "-1"); //colname
$Search->execute();
?>

Sign in to reply to this post

Jason ByrnesWebAssist

in the recordset, change the filter type to Contains Text.

currently the data type for the colname variable is set to Text, it needs to be set to Contains Text.

Sign in to reply to this post

hbibizadeh396670

In the webassist window.. i select filter post -> contains -> my session

But it is still not working

Here is the code

<?php
session_start();
if(isset($_GET['SearchTag'])) {
$_SESSION["SearchTerm"] = $_GET['SearchTag'];
$_SESSION["SearchTerm"] = preg_replace("#[^0-9a-z]#i","",$_SESSION["SearchTerm"]);
}
?>
<?php require_once('Connections/Connections.php'); ?>
<?php require_once('webassist/mysqli/rsobj.php'); ?>
<?php
$Search = new WA_MySQLi_RS("Search",$Connections,0);
$Search->setQuery("SELECT * FROM siteezy_posts WHERE Post LIKE ?");
$Search->bindParam("s", "".(isset($_SESSION['SearchTerm'])?$_SESSION['SearchTerm']:"") ."", "-1"); //colname
$Search->execute();
?>
<?php

error_reporting(E_ALL);
ini_set('display_errors','on');
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
<?php
while(!$Search->atEnd()) {
?>
<?php echo($Search->getColumnVal("Post")); ?>
<?php
$Search->moveNext();
}
$Search->moveFirst(); //return RS to first record
?>
</body>
</html>

Sign in to reply to this post

Jason ByrnesWebAssist

this line:
$Search->bindParam("s", "".(isset($_SESSION['SearchTerm'])?$_SESSION['SearchTerm']:"") ."", "-1"); //colname

should be:
$Search->bindParam("c", "".(isset($_SESSION['SearchTerm'])?$_SESSION['SearchTerm']:"") ."", "-1"); //colname

Sign in to reply to this post

hbibizadeh396670

Thank you.. all is working! :)

Sign in to reply to this post

Jason ByrnesWebAssist

you're welcome.

Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...