Link my php search results to another page - php

I am beginner in php, i have coded a search result function that is clickable . My problem is how to click a specific search item that can be clicked and open in another page by full details. Below my code for the searresults.php page or the target page after a client click one search item:
<!-- language: lang-html -->
<!DOCTYPE HTML>
<html>
<head>
<title>Search Results</title>
</head>
<body>
<h3>Search Results</h3>
<?php
$con = mysqli_connect("localhost","root","","1");
$excursion_id = $_GET['excursion_id'];
$sql = "select * from excursionitem where excursion_id = '$excursion_id'";
$result = mysqli_query($con,$sql);
while($row = mysqli_fetch_array($result))
{
$Item_Name = $row['Item_Name'];
$Description = $row['Description'];
$Price = $row['Price'];
$excursion_id = $row['excursion_id'];
echo '$excursion_id' ;
}
?>
</body>
</html>
Any help from your side will be highly appreciated.

If you want only list hyperlink clickable, and redirect to other page.
Try it:
while($row = mysqli_fetch_array($result))
{
$Item_Name = $row['Item_Name'];
$Description = $row['Description'];
$Price = $row['Price'];
$excursion_id = $row['excursion_id'];
?>
More datails<br />
<?php
}
Is it?

Related

PHP struggles. Error 404

Trying to make a crud function/contact list. The user is brought to this page after they log in:
With a click of the edit function, I hope to take the user to a page that allows them to edit the contact details. Currently struggling to have the link function properly.
The link photo is my /view file. Which looks like this:
<?php
session_start();
if(isset($_SESSION['u_uid'])){
$uid = $_SESSION['u_id'];
require_once('connect.php');
$ReadSql = "SELECT * FROM `contact` WHERE users_id=$uid ORDER BY Name";
$res = mysqli_query($connection, $ReadSql);
?>
<head>
<title>Motoko</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js">
</script>
</head>
<body>
<div class="container">
<div class="row">
<table class="table">
<tr>
<th><strong>Name</strong></th>
<th><strong>Company</strong></th>
<th><strong>Title</strong></th>
<th><strong>Phone</strong></th>
<th><strong>Email</strong></th>
<th><strong>Address</strong></th>
<th><strong>Extras</strong></th>
</tr>
<?php
while($r = mysqli_fetch_assoc($res)){
?>
<tr>
<td><?php echo $r['Name']; ?></td>
<td><?php echo $r['Company']; ?></td>
<td><?php echo $r['Title']; ?></td>
<td><?php echo $r['Phone']; ?></td>
<td><?php echo $r['Email']; ?></td>
<td><?php echo $r['Address']; ?></td>
<td>Edit</td>
<td><input type="button" onClick="deleteme(<?php echo $r['u_uid']; ?>)" name="Delete" value="Delete"></td>
</tr>
<!-- Javascript function for deleting data -->
<script language="Javascript">
function deleteme(delid)
{
if(confirm("Are you sure you want to Delete?")){
window.location.href='crud/delete.php';
}
}
</script>
<?php } ?>
</table>
</div>
</body>
</html>
<?php
}else{
header("Location: http://motoko.sorainsurance.com.au");
}
?>
This would then take them to the /update file. Which starts like:
<?php
error_reporting();
require_once('connect.php');
$id = $_GET['id'];
$SelSql = "SELECT * FROM `contact` WHERE id=$id";
$res = mysqli_query($connection, $SelSql);
$r = mysqli_fetch_assoc($res);
if(isset($_POST) & !empty($_POST)){
$name = mysqli_real_escape_string($connection,$_POST['name']);
$comp = mysqli_real_escape_string($connection,$_POST['comp']);
$title = mysqli_real_escape_string($connection,$_POST['title']);
$phone = mysqli_real_escape_string($connection,$_POST['urstel']);
$email = mysqli_real_escape_string($connection,$_POST['email']);
$location = mysqli_real_escape_string($connection,$_POST['location']);
$UpdateSql = "UPDATE `contact` SET Name='$name', Company='$comp',
Title='$title', Phone='$phone', Email='$email', Address='$location' WHERE id=$id";
$res = mysqli_query($connection, $UpdateSql);
if($res){
echo $smsg = "Successfully updated data.";
echo header('location: view.php');
}else{
echo $fmsg = "Failed to update data.";
}
}
Any idea why the error keeps popping up? So confused and struggling to progress :(
Many thanks!
404 error code indicate that, you are not request correct URL.
This would then take them to the /update file
You mentioned, the request will go to update file, But your request URL is crud/update.php.
Now, request URL depends on relativity of the file. So, whether you view file exists at root folder and update.php under crud folder ?
==Edited==
(referring your latest comment)It seems like, your update.php and view.php exists in same folder, then you should simply change the request
crud/update.php
to
update.php
You don't need to mention the folder path in your request.

edit table with php and jquery

I'm trying to modify the contents of a cell in a table with php and ajax.
the problem that the content has been changed in the page but it is not registered in the database.
this is the page index.php:
<?php
include 'connexion.php';
$sql = 'SELECT * FROM liste_user_tbl';
$result = mysql_query($sql) or die(__LINE__.mysql_error().$sql);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<title>Modification "inline" de données</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script>
$(function(){
var message_status = $("#status");
$("td[contenteditable=true]").blur(function(){
var field_userid = $(this).attr("id") ;
var value = $(this).text() ;
$.post('test1.php' , field_userid + "=" + value, function(data){
if(data != '')
{
message_status.show();
message_status.text(data);
setTimeout(function(){message_status.hide()},3000);
}
});
});
</script>
</head>
<body>
<h1>Utilisateurs</h1>
<table id="table-utilisateurs">
<tr>
<th>Nom</th>
<th>Prénom</th>
</tr>
<?php
while($user = mysql_fetch_assoc($result))
{
?>
<tr>
<td id="<?php echo $user['id']; ?>" contenteditable="true">
<?php echo $user['nom']; ?>
</td>
<td id="<?php echo $user['id']; ?>" contenteditable="true">
<?php echo $user['prenom']; ?>
</td>
</tr>
<?php
}
?>
</table>
</body>
</html>
<?php
mysql_close();
?>
this is test1.php:
<?php
if(!empty($_POST))
{
include "connexion.php";
foreach($_POST as $field_name => $val)
{
//clean post values
$field_userid = strip_tags(trim($field_name));
$val = strip_tags(trim(mysql_real_escape_string($val)));
//from the fieldname:user_id we need to get user_id
$split_data = explode(':', $field_userid);
$user_id = $split_data[1];
$field_name = $split_data[0];
if(!empty($user_id) && !empty($field_name) && !empty($val))
{
//update the values
mysql_query("UPDATE liste_user_tbl SET $field_name = '$val' WHERE id = $user_id") or mysql_error();
echo "Updated";
} else {
echo "Invalid Requests";
}
}
} else {
echo "Invalid Requests";
}
?>
this is my table :
First of all, $field_name is not defined in your code, that's why the query will produce an error if you enable debugging
Second of all, your code is very vulnerable to SQL injections. Your are using user's posted data as it is, without any filtering, and this can lead to loosing your entire database data.
Third of all, you are still using procedural php and "old schoool" database connection. Instead, you can use PDO and POO
use
print_r($_POST);
to receive post data and display
check if the post data has a problem

checking if a DOM var is empty in php

Hi this is my html code in a file:
<HTML>
<HEAD>
<div id="title"> Title </div>
<div id="city"> City </div>
<div id="country">Country</div>
<div id="company">Company </div>
</TITLE>
.................
and I am extractig the text from div's with this code:(the $file var has the correct path to the upmentioned file)
include('simple_html_dom.php');
$html = new simple_html_dom();
$html->load_file($file);
$title1 = $html->getElementById('title');
$title = $title1->innertext;
$city1 = $html->getElementById('city');
$city = $city1->innertext;
$country1 = $html->getElementById('country');
$country = $country1->innertext;
$company1 = $html->getElementById('company');
$company = $company1->innertext;
But I can't check if one of the div's is empty and implicit if one of the var ($title,$city,$country...) is empty. (as not always will be a city or a title...)
I have tried:
if(empty($title){...}
if(isset($title){...}
if(is_null($title){...}
if($title !== ""){...}
Any sugestions ?
Try this:
if(!strlen(trim($title))) {
// do something
}
The if block will execute when the <title> tag is empty.

jquery tabs with mysql and pgp

I am trying to make tabs that contain information about student, these information is stored in the database. I want the first tab to show the information of all students. and the the second tab to show the information of the students that thier grade is A and the the third tab to show the information of the students that thier grade is B.
I made this code but just the first tab shows the information of the students but the second and third tabs don't show anything.
what is wrong with the code?
<html>
<head>
<title>students table</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<script>
$(function() {
$( "#tabs" ).tabs();
});
</script>
</head>
<body>
<div id="tabs">
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
<?php
$connection = mysql_connect("","","");
if (!$connection)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("", $connection);
$result = mysql_query("SELECT * FROM studentTable");
while($row = mysql_fetch_array($result))
{
?>
<div id="tabs-1">
<?php
echo "Student id: '" . $row["id"];
echo "Student name: '" . $row["name"];
echo "Student grade: '" . $row["grade"];
echo '</table>';
}
?>
</div>
<?Php
$result2 = mysql_query("SELECT * FROM studentTable WHERE grade = 'A'");
while($row = mysql_fetch_array($result2))
{
?>
<div id="tabs-2">
<?php
echo "Student id: '" . $row["id"];
echo "Student name: '" . $row["name"];
echo "Student grade: '" . $row["grade"];
echo '</table>';
}
?>
</div>
<?php
$result3 = mysql_query("SELECT * FROM studentTable WHERE grade = 'B'");
while($row = mysql_fetch_array($result3))
{
?>
<div id="tabs-3">
<?php
echo "Student id: '" . $row["id"];
echo "Student name: '" . $row["name"];
echo "Student grade: '" . $row["grade"];
echo '</table>';
}
?>
</div>
</div>
</body>
</html>
I think your issue is because you have your tabs-# <div> opening tags inside your while() loops.
$result = mysql_query("SELECT * FROM studentTable");
while($row = mysql_fetch_array($result))
{
?>
<div id="tabs-1"> //this here needs to be above/outside while($row = mysql_fetch_array($result)){
This is creating n number of <div id="tabs-1">,<div id="tabs-2">,<div id="tabs-3">, without matching closing tags </div>, so now <div id="tabs-2"> & <div id="tabs-3"> are nested in <div id="tabs-1"> and jQuery doesn't know which one to bind tabs to.
try moving them before the while() loops -
<div id="tabs-1">
<?php
$result = mysql_query("SELECT * FROM studentTable");
while($row = mysql_fetch_array($result))
{
...
}
?>
</div>
<div id="tabs-2">
<?php
$result2 = mysql_query("SELECT * FROM studentTable WHERE grade = 'A'");
while($row = mysql_fetch_array($result2))
{
...
}
?>
</div>
<div id="tabs-3">
<?php
$result3 = mysql_query("SELECT * FROM studentTable WHERE grade = 'B'");
while($row = mysql_fetch_array($result3))
{
...
}
?>
</div>
Also, you have echo '</table>'; at the end of each tab div. May want to remove those if you don't actually have a table.
In your script you are trying to use Jquery's tab method.
<script>
$(function() {
$( "#tabs" ).tabs();
});
</script>
This is looking in the HTML for
<div id='tabs'>
You're tabs in here
</div>
Assuming that your SQL statments is not returing "NULL" then I would say you're issue is that you named you're div's tab-1, tab-2, tab-3. With ID's. This means that Jquery can't find anything to turn into tab's.
Change your jquery call to something like this
<script>
$(function() {
$( ".tabsclass" ).tabs();
});
</script>
and instead of using id's use classes.
<div class='tabsclass' id='tab-1'>
You're tabs in here
</div>
<div class='tabsclass' id='tab-2'>
You're tabs in here
</div>
<div class='tabsclass' id='tab-3'>
You're tabs in here
</div>

query was empty in search php

Im trying to make this search with a select option to select which site, or all the sites.
When i click on all sites it works. When i click on "4shared" it works. But when i click "putlocker" i get this. Query was empty.
I really dont know what i did wrong
<?php
include"inc/connect.php";
include"inc/functions.php";
error_reporting(0);
if(isset($_GET['s']) && $_GET['s'] != ""){
$s = $_GET['s'];
$w = $_GET['w'];
if($w == 'all'){
$sql = "SELECT * FROM result WHERE (`name` LIKE '%".$s."%') OR (`keywords` LIKE '%".$s."%')";
}else if($w == 'Sockshare'){
$sql = "SELECT * FROM result WHERE website='Sockshare' AND (`name` LIKE '%".$s."%') OR (`keywords` LIKE '%".$s."%')";
}else if($w == 'Putlocker'){
$sql == "SELECT * FROM result WHERE website='Putlocker' AND (`name` LIKE '%".$s."%') OR (`keywords` LIKE '%".$s."%')";
}else if($w == '4shared'){
$sql = "SELECT * FROM result WHERE website='4shared' AND (`name` LIKE '%".$s."%') OR (`keywords` LIKE '%".$s."%')";
}else if($w == 'Rapidshare'){
$sql = "SELECT * FROM result WHERE website='Rapidshare' AND (`name` LIKE '%".$s."%') OR (`keywords` LIKE '%".$s."%')";
}
$query = mysql_query($sql) or die(mysql_error());
$count = mysql_num_rows($query);
if($count > 1){
while($row = mysql_fetch_array($query)){
$name = $row["name"];
$details = $row["details"];
$url = $row["url"];
$results .= '
<div id="stitle">' .$name. '</div>
<div id="details">' .$details. '</div>
<div id="url"><a target="_blank" href="' .$url. '">' .$url. '</a></div>';
}
} else {
$results = 'Nothing found!';
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Findrfile.com - Putlocker Search | Sockshare search | Mediafire Search</title>
<link href='http://fonts.googleapis.com/css?family=Orienta' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="main.css" />
</head>
<body>
<script type="text/javascript" src="js/jquery-1.7.2.js"></script>
<script type="text/javascript" src="js/main.js"></script>
<?php include"header.php"; ?>
<div id="spacer"></div>
<?php include"litsearch.php"; ?>
<div id="nuresults"><span class="blue"><?php echo $count; ?> Results found</span></div>
<div id="spacerx"></div>
<div id="wrapper">
<div id="spacerx"></div>
<div id="content">
<?php echo $results; ?>
<div class="clear"></div>
</div>
<div id="spacerx"></div>
<div id="spacer"></div>
</div>
<?php include"footer.php"; ?>
</body>
</html>
You have $sql == "SELECT * FROM result WHERE website='Putlocker' AND (name LIKE '%".$s."%') OR (keyword LIKE '%".$s."%')"; notice the ==, this is a comparison operator so it won't set a value to $sql
I think that may be your issue.
Change
while($row = mysql_fetch_array($query)){
to
while($row = mysql_fetch_assoc($query)){
Because you use associative array.
$name = $row["name"];
$details = $row["details"];
$url = $row["url"];
If you want to use
while($row = mysql_fetch_array($query)){
like:
$name = $row[0];
$details = $row[1];
$url = $row[2];
Am I wrong?
ALSO:
you check if $_GET["s"] is set but you do not check $_GET["w"]

Categories