my first post here so hope its not too dumb a question. Im including a search box in my nav bar and I want it to search by product title OR description, is this possible ? The code I have so far is as follows which works fine to search by one field but not two
<div class="search_box">
<form method="post" name="search" id="search" action="../admin/search_box.php">
<input type="submit" name="submit" value="Find" style="float: right" />
<div style="overflow: hidden; padding-right: .5em;">
<input type="text" name="description" style="width:100%;" />
</div>
</form>
</div>
and then for the data processing
<?php
require ('dbconnection.php');
$title = filter_var($_POST["title"], FILTER_SANITIZE_STRING);
$description = filter_var($_POST["description"], FILTER_SANITIZE_STRING);
if (isset($_POST['submit'])) // waits for user to enter data into the form
{
$sql_search_lookup = "SELECT * FROM item WHERE item.description LIKE '%$description%'";
$result=mysqli_query ($link, $sql_search_lookup) or die ('Problem:'.$sql_search_lookup);
if (mysqli_num_rows($result) > 0)
{
while ($row=mysqli_fetch_array($result))
{
?>
<div style="float: left; width: 98%; margin: 10px">
<p>
<div style="float:left; width: 20%;">
<a href="/products_detail.php?itemID=<?php print $row["itemID"]?>">
<img src="../images/products/<?php print $row['img_file_path'];?> " width="150" height="120">
</a>
</div>
<div style="float:left;width: 75%;vertical-align:middle; font-size:14px; padding:1%;">
<?php echo "Title: ". $row['title']?><br>
<?php echo "Description: ".$row['description']?>
</div>
</p>
</div>
<?php }
}
else
{
echo "We cant find what you're looking for sorry";
}
}
?>
Your HTML should be:
<div class="search_box">
<form method="post" name="search" id="search" action="../admin/search_box.php">
<input type="submit" name="submit" value="Find" style="float: right" />
<div style="overflow: hidden; padding-right: .5em;">
<input type="text" name="description" style="width:100%;" />
</div>
</form>
</div>
Your mysql query should be something like:
$sql_search_lookup = "SELECT * FROM item WHERE item.description LIKE '%"+$description+"%' or item.title LIKE '%"+$description+"%'";
Related
I have created a simple form type page as follows,
<form action="" method="GET" >
<div class="input-group mb-3">
<input type="text" name="search" required value="<?php if(isset($_GET['search'])){echo $_GET['search']; } ?>" class="form-control" placeholder="Search data">
<button type="submit" class="btn btn-primary">Search</button>
</div>
</form>
I need to type a text in search box(name ="search") and after clicking submit I need to filter the sql data as follows.
<?php
$con = mysqli_connect("10.62.96.133", "root", "", "cdrextend");
if(isset($_GET['search']))
{
$filtervalues = $_GET['search'];
$query="***";
$query_run = mysqli_query($con, $query);
if(mysqli_num_rows($query_run) > 0)
{
foreach($query_run as $items)
{
?>
<tr>
<td><?= $items['***']; ?></td>
<td><?= $items['***']; ?></td>
</tr>
<?php
}
}
else
{
?>
<tr>
<td colspan="2">No Record Found</td>
</tr>
<?php
}
}
?>
Whenever I hit submit button after typing something in text box, it redirects to login page and I am not getting any results.Can someone show me where I have messed up?
Hi change your forms submit action="" to action="<?php echo htmlspecialchars($_SERVER[" PHP_SELF "]);?>"
<form action="<?php echo htmlspecialchars($_SERVER[" PHP_SELF "]);?>" method="GET" >
<div class="input-group mb-3">
<input type="text" name="search" required value="<?php if(isset($_GET['search'])){echo $_GET['search']; } ?>" class="form-control" placeholder="Search data">
<button type="submit" class="btn btn-primary">Search</button>
</div>
</form>
I'm attempting to display a message in red colour if the data already exists in the database but it doesn't seem to be working. This is the code that I'm using.
PHP code:
<?php
/**
* Template Name: Add IP Address
*/
get_header();
?>
<?php
$sql="SELECT * FROM `wp_5wbtdj_ip_based_login` where (start='$start' or end='$end');";
$res=mysqli_query($mysqli,$sql);
if (mysqli_num_rows($res) > 0) {
$row = mysqli_fetch_assoc($res);
if($end==isset($row['end']))
{
echo " End IP already exists";
}
if($start==isset($row['start']))
{
echo "Start IP already exists";
}
}
else{
//do your insert code here or do something (run your code)
}
If($_POST['Submit']){
global $wpdb;
$username = $_POST['username'];
$start = ip2long($_POST['start']);
$end = ip2long($_POST['end']);
If($wpdb ->insert('wp_5wbtdj_ip_based_login',
array(
'username' => $username,
'start' => $start,
'end' => $end
)
)== false) wp_die ('<div class="errormessage">Database insertion failed </div>');
else echo '<div class="successmessage"> Database insertion successfull </div>';
?>
<?php
}
else{
}
?>
HTML code:
<main role="main">
<div class="section section_white section_nopadding_top">
<div class="container">
<div class="row">
<div class="col-md-12">
<br><br>
<div class="wrap">
<form action="" id="postjob" method="post">
<h3 style="margin-left:50px;">IP Based Login</h3>
<hr />
<h4 style="margin-left:50px;">Add IP Range</h4>
<table class="form-table" style="margin-left:50px;">
<tr>
<th scope="row" valign="top">
<label for="username">Username</label><br />
</th>
<td>
<input type="text" size="25" name="username" value="<?php echo do_shortcode('[show_loggedin_as]'); ?>"><br /><br>
</td>
</tr>
<tr>
<div class="wrapper">
<th scope="row" valign="top">
<label for="start_ip">Start IP </label>
</th>
<td>
<input type="text" minlength="7" maxlength="15" size="25" pattern="^((\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$" name="start" valign="top" required>
</div>
<br><br>
<tr>
<div class="wrapper">
<th scope="row" valign="top">
<label for="start_ip">End IP</label>
</th>
<td>
<input type="text" minlength="7" maxlength="15" size="25" pattern="^((\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$" name="end" valign="top" required>
</div>
</td>
</tr>
<br>
</table><br />
<input name="Submit" class="button" value="Add IP range" type="Submit" style="margin-left:50px;" />
</form>
</div>
<br /><br />
</div> <!-- /col-md-12 -->
</div> <!-- /row -->
</div><!-- /.container -->
</div> <!-- /section -->
</main><!-- /.container -->
</div>
<?php
get_footer();
Can anyone help to point what I'm doing wrong here?
I am sending in the fileName a hebrew word "הי"
and it return "??"
really need help on this,
thanks for the helpers!
for encoding I added the top of this html lines :
<%# page language="java" contentType="text/html; charset=windows-1255"
pageEncoding="windows-1255"%>
JSP:
<form name='DMform' id='DMform' style="height: 226px; " method="Post" >
<center>
<h2 id="titleID">title </h2>
<input type="button" value="button1" style="width: 116px; " onclick="setTextOnFile()">
<input type="text" name="filePath" id="filePath" style="width: 258px;" value="<%if(filePath!=null){
out.println(filePath[0].trim());
}%>" >
</br></br>
<input type="text" name="fileName" id="fileName" style="width: 258px;" value="<%if(fileName!=null){
out.println(fileName[0].trim());
}%>" >
<label>: שם המסמך </label>
</br></br>
<input type="button" value="send" onclick="checkData();" <%if(filePath!=null){
if(filePath[0].trim()!=""){ out.println(" disabled ");}
}%> >
</br></br>
<input type="button" value="איפוס הטופס" onClick="window.location=window.location.href ;">
</center>
</form>
Java script that past:
function checkData(){
document['DMform'].submit();
}
This is my form but when I click submit button it shows some error in the form. I am not able to identify it.
<div class="status alert alert-success" style="display: none"></div>
<form name="contactform" method="post" action="email.php">
<div class="row" style=" font-weight: lighter;">
<div class="col-lg-4" style="color:#000;">
First Name:<br><br><input type="text" name="firstname" value="">
</div>
<div class="col-lg-4" style="color:#000;">
Last Name:<br><br><input type="text" name="last" value="">
</div>
<div class="col-lg-4" style="color:#000;">
Email:<br><br><input type="text" name="email" value="">
</div>
</div>
<br>
<br>
<div class="row" style=" font-weight: lighter;">
<div class="col-lg-8" style="color:#000;">
Your Interest*<br><br><select name="interest">
<option selected disabled hidden style='display: none' value=''></option>
<option value="Individual">Individual</option>
<option value="Company">Company</option>
</select>
</div>
<div class="col-lg-4" style="color:#000;">
Phone*<br><br><input type="text" name="phone" value="">
</div>
</div>
<br>
<br>
<div class="row" style=" font-weight: lighter;">
<div class="col-lg-8" style="color:#000;">
Module Categoey*<br><br><select name="module">
<option selected disabled hidden style='display: none' value=''></option>
<option value="Accessory">Accessory</option>
<option value="Audio">Audio</option>
</select>
</div>
<div class="col-lg-4" style="color:#000;">
Role*<br><br><select name="role">
<option selected disabled hidden style='display: none' value=''></option>
<option value="Individual">Individual</option>
<option value="Company">Company</option>
</select>
</div>
</div>
<br>
<br>
<div class="row" style=" font-weight: lighter;">
<div class="col-lg-12" style="color:#000;">
Tell us about yourself:<br><br><textarea id="description" name="description"></textarea>
</div>
</div>
<br>
<br>
<div class="row" style=" font-weight: lighter;">
<div class="col-lg-12" style="color:#000;">
<div class="checkbox">
<label><input type="checkbox" value="">I accept the Terms and Conditions and acknowledge that my information will be used in accordance with Google Privacy Policy*</label>
</div>
</div>
</div>
<br>
<br>
<div class="row">
<div class="col-lg-12" style="color:#000;">
<!--<button type="button" class="btn btn-primary " style="color:#000;" aria-label="Play">Submit<i></i></button>-->
<input type="submit" class="btn btn-primary " style="color:#000;" value="Submit">
</div>
</div>
</form>
Help to identify the error. it shows "We are very sorry, but there were error(s) found with the form you submitted. These errors appear below.
We are sorry, but there appears to be a problem with the form you submitted.
Please go back and fix these errors. "
This is my php file email.php
<?php
header('Content-type: application/json');
$status = array(
'type'=>'success',
'message'=>'Email sent!'
);
$name = #trim(stripslashes($_POST['firstname']));
$email = #trim(stripslashes($_POST['email']));
$subject = #trim(stripslashes($_POST['interest']));
$message = #trim(stripslashes($_POST['module']));
$email_from = $email;
$email_to = 'pravakar#mrwebsiter.com';
$body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Subject: ' . $subject . "\n\n" . 'Message: ' . $message;
$success = #mail($email_to, $subject, $body, 'From: <'.$email_from.'>');
echo json_encode($status);
die;
?>
See if you fields in the form match your conditions here:
if(!isset($_POST['firstname']) ||
!isset($_POST['lastname']) ||
!isset($_POST['email']) ||
!isset($_POST['interest']) ||
!isset($_POST['phone']) ||
!isset($_POST['module']) ||
!isset($_POST['role']) ||
!isset($_POST['description'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
You can make error message better if you test each field separately.
I have an HTML template in my Apps Script project that I am trying to evaluate. I keep getting a server error (not very helpful), but I can't find anything while debugging. I tried the running result from getCode(), but no errors there. Then I also ran output.$out.getContent() (as described here https://developers.google.com/apps-script/html_service) which gives me the expected html output.
I would attach the HTML file but it contains a lot of variables and I have trouble creating a lean version with the error. I am hoping someone knows a better or the right way to debug these files.
The html file:
<html>
<body>
<form action="https://script.google.com/macros/s/AKfycbxHQDJoAtAjBF9uIctvmxBHv-QVpYf6f15UZf8aAnAh_1U_PzU/exec" method="POST" id="mail-form">
<table>
<tr style="background-color: #392303; font-size: large; line-height: 30px;">
<th>
<?= userForm.userName ?>
</th>
<th colspan="3">
<div width="250px" style="color: #e06c01; font-weight: lighter; float: left; text-indent: 10px;"><?= userForm.experience ?></div>
<div style="color: #FFFFFF; background-color: <?= userForm.pastColor ?>; border: 1px solid white; width: 28px; height: 28px; float: right;" title="<?= userForm.pastApplications ?>">
<center><?= userForm.pastNumber ?></center>
</div>
</th>
</tr>
<tr style="background-color: #9c9181">
<td width="100">
<center><p style="font-size:small; top: 5px; margin-bottom: 3px;">Thanks meter: <?= info.thanks ?></p></center>
<center><img alt="" src="" style="margin-bottom: 10px;"/></center>
<center><img src="<?= info.avatar ?>" style="height: 60px; margin-bottom: 10px;" /></center>
<center><p style="font-size:small; margin-bottom: 3px; margin-top: 3px;">Posts: <?= info.totalPosts ?></p></center>
<center><p style="font-size:small; margin-bottom: 3px; margin-top: 3px;">Per day: <?= info.postsPerDay ?></p></center>
<center><p style="font-size:small; margin-bottom: 3px; margin-top: 3px;">Join date: <?= info.joinDate ?></p></center>
<center><p style="font-size:small; margin-bottom: 3px; margin-top: 3px;">Last activity: <?= info.activity ?></p></center>
</td>
<td>
<center><?= userForm.onSite ?></center>
</td>
<td>
<center><?= userForm.tools + '\n' + '\n' + userForm.theHardPart ?></center>
</td>
<td width="100">
<center><?= userForm.development ?></center>
</td>
</tr>
<tr style="background-color: #392303; font-size: large; line-height: 30px;">
<td colspan="4" style="color: #e06c01; font-weight: lighter; text-indent: 10px;">Review</td>
</tr>
<tr style="background-color: #9c9181">
<td colspan="1" valign="top">
<label><input type="radio" name="review" value="approved" id="review_1">Accept</label>
</td>
<td colspan="1" valign="top">
<label><input type="radio" name="review" value="rejected" id="review_2">Reject</label><br><br>
<label><b>Reason(s) for user</b></label><br>
<label><input type="checkbox" name="reason" value="Reason1" id="requirements">Reason1</label><br>
<label><input type="checkbox" name="reason" value="Reason2" id="requirements">Reason2</label><br>
<label><input type="checkbox" name="reason" value="Reason3" id="requirements">Reason</label><br>
<label><input type="checkbox" name="reason" value="Reason4" id="requirements">Reason4</label><br>
<label><input type="checkbox" name="reason" value="Reason5" id="requirements">Reason5</label><br>
<label><input type="checkbox" name="reason" value="Reason6" id="requirements">Reason6</label><br>
</td>
<td colspan="1" style="text-indent: 3px;">
<label><b>Feedback</b></label><br>
<label><i>Rejections:</i> <b>WARNING</b> users will see this</label><br>
<label><i>Approvals:</i> only for us</label><br>
<textarea name="comments" rows="10" cols="35" id="comments"></textarea>
</td>
</tr>
</table>
<input type="hidden" name="userName" id="userName" value="<?= userForm.userName ?>"/>
<input type="hidden" name="reviewerName" id="reviewerName" value="<?= userForm.reviewer ?>"/>
<input type="hidden" name="link" id="link" value="<?= info.profile ?>"/>
<input type="hidden" name="row" id="row" value="<?= userForm.row ?>"/>
<input type="hidden" name="hash" id="hash" value="<?= userForm.hash ?>"/>
<div>
<div style="float: left;">
<input type="submit" name="submit" id="submit" value="Submit">
</div>
<div style="float: right;">
<a href="mailto:<?= mailTo ?>?subject=<?= subject ?>&body=<?= body ?>">
<b>Consult</b>
</a>
</div>
</div>
</form>
</body>
</html>
The relevant part of the script:
var htmlTemplate = HtmlService.createTemplateFromFile('DC Form');
htmlTemplate.userForm = userForm;
htmlTemplate.info = info;
htmlTemplate.mailTo = mailTo;
htmlTemplate.subject = 'CONSULT: ' + userForm.userName;
htmlTemplate.body = 'Profile link: ' + userForm.profile + '\n' + '\n';
var code = htmlTemplate.getCode();
Logger.log(code);
var html = htmlTemplate.evaluate().getContent();
EDIT:
After using the Caja Playground I found an error in this line:
<div style="color: #FFFFFF; background-color: <?= userForm.pastColor ?>; border: 1px solid white; width: 28px; height: 28px; float: right;" title="<?= userForm.pastApplications ?>">
Could it be that using scriptlets inside attributes isn't supported?
Well then, it looks like a simple missing of 'px' in the width attribute was the cause of all this trouble.
<td width="100">
It is fairly hard to locate as the error only appeared in certain conditions, probably only when that the size didn't match whatever it was. This would be why Corey G. though it had to be the variables, as the variables had to be of a certain length to trigger that width error. Headaches gone.
Without touching your html, I tried this slight variant of your .gs file:
function doGet() {
var htmlTemplate = HtmlService.createTemplateFromFile('DC Form');
var userForm = {userName: 'userName', profile: 'profile'};
htmlTemplate.userForm = userForm;
htmlTemplate.info = "info";
htmlTemplate.mailTo = "mailTo";
htmlTemplate.subject = 'CONSULT: ' + userForm.userName;
htmlTemplate.body = 'Profile link: ' + userForm.profile + '\n' + '\n';
var code = htmlTemplate.getCode();
Logger.log(code);
return htmlTemplate.evaluate();
}
This works fine for me. I suspect that something is wrong with one of the values in your variables.