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?
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 have one view candidate details form in my application.
In that I gave one button called scheduled interview.
So when I click on the button it redirect the page to candidate process page with the candidate_id and user_id in the url.
And in the candidate_process page I have one form with some details and under the form I display all the records from database in data table.
I want to display the records only for the particular candidate.I don't want to display all the records.
Here is my view:
<form method="post" action="" id="form">
<b>Date </b>:<input type="text" name="date" id="date"><br><br>
<input type="hidden" name="candidate_id" value="<?php echo $getCandidate['candidate_id']; ?>">
<input type="hidden" name="user_id" value="<?php echo $getCandidate['user_id']; ?>">
<div class="form-group">
<label><b>Select Interview Type:</b></label>
<select class="form-control" id="interview_type_id" name="interview_type_id" >
<option value="" disabled selected>Interview Type</option>
<?php foreach($interviewtype as $rows) { ?>
<option value="<?php echo $rows->interview_type_id?>"><?php echo ucfirst($rows->interview_type_name)?></option>
<?php } ?>
</select>
</div><br>
<div class="form-group">
<label><b>Select Status:</b></label>
<select class="form-control" id="status_type_id" name="status_type_id" >
<option value="" disabled selected>Status Type</option>
<?php foreach($statustype as $rows) { ?>
<option value="<?php echo $rows->status_type_id?>"><?php echo ucfirst($rows->status)?></option>
<?php } ?>
</select>
</div><br>
<button type="submit" name="submit" value="submit" class="btn btn-primary" value="submit">Submit</button>
<button type="submit" id="submit" name="submit" class="btn btn-primary" value="schedule" onclick="ScheduleNextRound();">Schedule Next Round</button><br></br>
</form>
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<h3>Reports</h3>
</section>
<!-- Main content -->
<section class="content">
<div class="row">
<div class="col-xs-12">
<div class="box">
<div class="box-body">
<table id="example1" class="table table-bordered table-hover">
<thead>
<tr>
<th>Interview Date</th>
<th>Candidate</th>
<th>interview</th>
<th>status</th>
<th>Vendor</th>
</tr>
</thead>
<?php foreach ($view_candidates as $idata){ ?>
<tbody>
<tr id="domain<?php echo $idata->candidate_seletion_id;?>">
<td><?php echo $idata->date;?></td>
<td><?php echo $idata->f_name;?></td>
<td><?php echo $idata->interview_type_name;?></td>
<td><?php echo $idata->status;?></td>
<td><?php echo $idata->first_name;?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<!-- /.box-body -->
</div>
<!-- /.box -->
</div>
</div>
</section>
</div>
Controller:
function candidate_process($candidateid,$userid){
$data["msg"]="";
$this->load->model('CandidateModel');
$data['statustype']=$this->CandidateModel->getstatustypes();
$data['interviewtype']=$this->CandidateModel->getinterviewtypes();
$data['candidate']=$this->CandidateModel->getcandidates();
$data['usertype']=$this->CandidateModel->getvendors();
$data['getCandidate'] = $this->CandidateModel->get_candidate_detail($candidateid);
$data['view_candidates'] = $this->CandidateModel->getcandidateselection();//this is my table view
if($this->input->post('submit')=="submit"){
$this->CandidateModel->add_candidate_selection($this->input->post());
redirect(base_url('Candidate/view_candidate_selection'));
}
$this->load->view('Candidates/candidate_process',$data);
}
Model1:
public function add_candidate_selection($data){
$data=array(
'candidate_id'=>$this->input->post('candidate_id'),
'user_id'=>$this->input->post('user_id'),
'status_type_id'=>$this->input->post('status_type_id'),
'interview_type_id'=>$this->input->post('interview_type_id'),
'date'=>$this->input->post('date')
);
$this->db->insert('candidate_selection', $data);
//print_r($data);
}
MOdel2:
public function getcandidateselection(){
$this->db->select('*');
$this->db->from('candidate_selection');
$this->db- >join('candidates_details','candidates_details.candidate_id=candidate_selection.candidate_id');
$this->db->join('interview_types','interview_types.interview_type_id=candidate_selection.interview_type_id');
$this->db->join('status_types','status_types.status_type_id=candidate_selection.status_type_id');
$this->db->join('users','users.user_id=candidate_selection.user_id');
$query = $this->db->get();
//echo $this->db->last_query();
return $query->result();
}
Can anyone help me how to do this..
Thanks in advance.
Replace the Following code in your model function
function getcandidateselection($candidateid)
{
$this->db->join('candidate_selection as cs','cs.candidate_id = cd.candidate_id');
$this->db->join('status_types as st','st.status_type_id = cs.status_type_id');
$this->db->where('cd.candidate_id',$candidateid);
$q = $this->db->get('candidates_details as cd');
return $q->result();
}
Hope it will solve your problem
I am getting the details of product from the database. Here is my sample code I am unable to display images of the products! Can anyone help me out please?
The code to insert the product details in the database:
<!DOCTYPE>
<?php
include("includes/db.php");
?>
<html>
<head>
<title> Inserting product</title>
<script src="//tinymce.cachefly.net/4.1/tinymce.min.js"></script>
<script>
tinymce.init({ selector:'textarea' });
</script>
</head>
<body bgcolor="skyblue">
<form action="insert_product.php" method="post" enctype="multipart/form-data">
<table align="center" width="700" border="2" bgcolor="orange">
<tr align="center">
<td colspan="7"><h2>Insert New Post Here.</h2></td>
</tr>
<tr>
<td align="right"><b>Product Title:</b></td>
<td><input type="text" name="product_title" size="50" required /></td>
</tr>
<tr>
<td align="right"><b>Product Category:</b></td>
<td>
<select name="product_cat" required>
<option>Select a categogory</option>
<?php
$get_cats = "select * from categories";
$run_cats = mysqli_query($con, $get_cats);
while($row_cats=mysqli_fetch_array($run_cats)){
$cat_id = $row_cats['cat_id'];
$cat_title = $row_cats['cat_title'];
echo "<option value='$cat_id'>$cat_title</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td align="right"><b>Product Brand:</b></td>
<td>
<select name="product_brand" required>
<option>Select a Brand</option>
<?php
$get_brands = "select * from brands";
$run_brands = mysqli_query($con, $get_brands);
while($row_brands=mysqli_fetch_array($run_brands)){
$brand_id = $row_brands['brand_id'];
$brand_title = $row_brands['brand_title'];
echo "<option value='$brand_id'>$brand_title</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td align="right"><b>Product Image:</b></td>
<td><input type="file" name="product_image" required/></td>
</tr>
<tr>
<td align="right"><b>Product Price:</b></td>
<td><input type="text" name="product_price" size="50" required/></td>
</tr>
<tr>
<td align="right"><b>Product Description:</b></td>
<td><textarea name="product_desc" cols="20" rows="10"></textarea></td>
</tr>
<tr>
<td align="right"><b>Product Keywords</b></td>
<td><input type="text" name="product_keywords" size="50" required/></td>
</tr>
<tr align="center">
<td colspan="7"><b><input type="submit" name="insert_post" value="Insert Product Now"/></b></td>
</tr>
</table>
</form>
</body>
</html>
<?php
if(isset($_POST['insert_post'])){
//getting the text data from the fields.
$product_title = $_POST ['product_title'];
$product_cat = $_POST ['product_cat'];
$product_brand = $_POST ['product_brand'];
$product_price = $_POST ['product_price'];
$product_desc = $_POST ['product_desc'];
$product_keywords = $_POST ['product_keywords'];
//getting the image data from the fields.
$product_image = $_FILES['product_image'][name];
$product_image_tmp = $_FILES['product_image']['tmp_name'];
move_uploaded_file($product_image_tmp,"product_images/$product_image");
$insert_product = "insert into products (product_cat,product_brand,product_title,product_price,product_desc,product_image,product_keywords) values ('$product_cat','$product_brand','$product_title','$product_price','$product_desc',' $product_image','$product_keywords')";
$insert_pro = mysqli_query($con,$insert_product);
if($insert_pro) {
echo "<script>alert('Product has been inserted!')</script>";
echo "<script>window.open('insert_product.php','_self')</script>";
}
}
?>
The function part.
<?php
$con = mysqli_connect("localhost","root","","ecommerce");
//getting the categories
function getcats(){
global $con;
$get_cats = "select * from categories";
$run_cats = mysqli_query($con, $get_cats);
while($row_cats=mysqli_fetch_array($run_cats)){
$cat_id = $row_cats['cat_id'];
$cat_title = $row_cats['cat_title'];
echo "<li><a href='#'>$cat_title</a></li>";
}
}
//getting the Brands
function getBrands(){
global $con;
$get_brands = "select * from brands";
$run_brands = mysqli_query($con, $get_brands);
while($row_brands=mysqli_fetch_array($run_brands)){
$brand_id = $row_brands['brand_id'];
$brand_title = $row_brands['brand_title'];
echo "<li><a href='#'>$brand_title</a></li>";
}
}
function getpro() {
global $con;
$get_pro = "select * from products order by RAND() LIMIT 1,6";
$run_pro = mysqli_query($con, $get_pro);
while($row_pro=mysqli_fetch_array($run_pro)){
$pro_id = $row_pro['product_id'];
$pro_cat = $row_pro['product_cat'];
$pro_brand = $row_pro['product_brand'];
$pro_title = $row_pro['product_title'];
$pro_price = $row_pro['product_price'];
$pro_image = $row_pro['product_image'];
echo "
<div id='single_product'>
<h3>$pro_title</h3>
<img src='\\ecommerce\admin_area\product_images\$pro_image' width='180' height='180' />
<p><b> $pro_price </b></p>
</div>
";
}
}
?>
**The web page to display all details**
<!DOCTYPE>
<?php
include("functions/functions.php");
?>
<html>
<head>
<title>Gal Baking Services LTD online Shop.</title>
<link rel="stylesheet" href="admin_area/product_images/style.css" media="all" />
</head>
<body>
<div class="main_Wrapper">
<div class="header_wrapper">
<img id="logo" src="images/ad bunner.jpg" />
<img id="bunner" src="images/ad bunner.jpg" />
</div>
<div class="menubar">
<ul id="menu">
<li>Home</li>
<li>All products</li>
<li>My account</li>
<li>Sign up</li>
<li>Shopping cart</li>
<li>Contact Us</li>
</ul>
<div id="form">
<form method="get" action="result.php" enctype="multipart/form-data">
<input type="text" name="user_query" placeholder="Search a product" />
<input type="submit" name="search" value="search" />
</form>
</div>
</div>
<div class="content_wrapper">
<div id="sidebar">
<div id="sidebar_title">Categories</div>
<ul id="carts">
<?php getcats();?>
</ul>
<div id="sidebar_title">Brands</div>
<ul id="carts">
<?php getBrands();?>
</ul>
</div>
</div>
<div id="content_area">
<div id="products_box">
<?php getpro(); ?>
</div>
</div>
</div>
<div id="footer">
<h2 style="text-align:center; padding-top:30px;">©2016 by www.krumblefresh.com </h2>
</div>
</div>
</body>
</html>
I would wish to thank everyone for your participation and for your support .
After straggling with my code on how to display images from mysql database,i came to realize that my code was perfect only that i had made some silly mistakes on the following lines of the insert_product.php file,
"$product_image = $_FILES['product_image'][name];".I failed to enclose the 'name' inside the single quotes ''.It should be,
$product_image = $_FILES['product_image']['name'];.
Also,on the following line
*
$insert_product = "insert into products
(product_cat,product_brand,product_title,product_price,product_desc,product_image,product_keywords)
values
('$product_cat','$product_brand', '$product_title','$product_price','$product_desc',
' $product_image','$product_keywords')";
*, i had included a blank space inside the single quotes near $product_image.Its supposed to be ,
$insert_product = "insert into products
(product_cat,product_brand,product_title,product_price,product_desc,product_image,product_keywords)
values
('$product_cat','$product_brand','$product_title','$product_price','$product_desc','$product_image','$product_keywords')";
Thank you all.
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+"%'";
I have two forms on my page, I wrapped the first with a new class just to restrict it to span5, and from that the forms now appear next to each other horizontally but the first is not allowing you to click into or on the elements at all.
<div class="row">
<div class="greybg-container">
<div class="span5">
<div id="login-container">
<div class="inner-content">
<h4>Login</h4>
<div class="basket-login"><div class="basket-login-text"><?php $seintro = new Page($db,'SiteElements','Login'); echo $seintro->row['pageCopy']; ?></div>
<form method="post" action="<?php echo HTTP_HOST; ?>Site/MyAccount/Login/?basketId=<?php echo $_REQUEST['basketId'] ? $_REQUEST['basketId'] : $basket->row['orderId']; ?>&wishlist=<?php echo $_GET['wishlist']; ?>&categoryId=<?php echo $_GET['categoryId']; ?>&addToBasketSize=<?php echo $_GET['addToBasketSize']; ?>">
<?php if ($errorLogin){ ?>
<span class="error"><?php echo $errorLogin; ?></span>
<?php } ?>
<table class="basket">
<?php foreach($form_login as $each){ ?>
<tr><td class="title"><?php $each->writeLabel(); ?></td>
<td><?php $each->write(); ?></td></tr>
<?php } ?>
<tr>
<td class="title">
<label for="login_userSubmit"></label>
</td>
<td class="form_button">
<input id="login_userSubmit" type="submit" size="" value="Send" onclick="" name="login_userSubmit">
<br>
<a class="grey-link" href="<?php echo HTTP_HOST; ?>Site/MyAccount/ForgotPassword">Forgot Password ?</a>
</td>
</tr>
</table>
</form>
</div>
</div>
</div>
</div>
<div id="left">
<div class="inner-content">
<h4>Register</h4>
<div class="basket-login"><div class="basket-login-text"><?php $seintro = new Page($db,'SiteElements','Register'); echo $seintro->row['pageCopy']; ?><?php echo $page->row['pageCopy']; ?></div></div>
<form method="post" enctype="multipart/form-data">
<?php if (is_array($error)){ ?>
<strong>Please Note :</strong> The following errors have occurred
<ul>
<?php foreach($error as $id=>$each){ ?>
<li class="error"><?php $form_signup[$id]->writeLabel($each); ?></li>
<?php } ?>
</ul>
<?php } ?>
<table class="basket">
<?php if($form_signup){ foreach($form_signup as $each){ ?>
<tr>
<td class="title"><?php $each->writeLabel(); ?></td>
<td><?php $each->write(); ?></td>
<?php } } ?>
<tr>
<td class="title">
<label for="signup_submit"></label>
</td>
<td class="form_button">
<input style="width:auto;" id="signup_submit" type="submit" size="" value="Continue Registration" onclick="document.getElementById('action_submit').value='1';document.submit();" name="signup_submit">
</td>
</tr>
</table>
</form>
</div>
</div>
</div>
the second form starts where there is div id="left". ignore the fact it says left, that's the form on the right as you'll see.
http://bit.ly/19fegdi
Span5 is overlapped by the form which on the right side. Add the following css style will fix it.
#left{
float: left;
}