Submit data from PHP to HTML - php

I have created a search page on PHP that searches for user from database. After the results are retrieved, i have created a view button that would display profile information of that user in HTML page. I am not quite sure how to send information from PHP to HTML. Below is the code for your reference. I would appreciate if someone could shed some light on this.
retrieve.php
<?php
echo "<body style='background-color:#DCDCDC'>";
// echo '<img src="back to school.jpg'. $row['filename'] .'" style="width:600px; height:300px;" alt="" /><br />';
include ("account.php");
( $dbh = mysql_connect( $hostname, $username, $password ))
or die ( "unable to connect to MYSQL database" );
mysql_select_db( $project );
if (isset($_POST['search'])) {
$sql= "SELECT * FROM BPi_registration ";
$search_term = mysql_real_escape_string($_POST['search_box']);
$sql .= "WHERE first_name= '{$search_term}'";
$sql .= " OR last_name= '{$search_term}'";
$query=mysql_query($sql) or die(mysql_error());
}
?>
<html>
<head>
<title>Jon</title>
</head>
<body>
<form name="search_form" method="POST" action="retrieve.php">
<table width="599" border="2">
<tr>
<th>Search Here
<input type ="text" name ="search_box" value=""/>
<input type="submit" name="search" value="Find Users">
</tr>
</table>
</form>
<table width="600" border="2">
<tr>
<th width="91"> <div align="center">First Name </div></th>
<th width="98"> <div align="center">Last Name </div></th>
<th width="198"> <div align="center">Email </div></th>
<th width="97"> <div align="center">City </div></th>
<th width="97"> <div align="center">State </div></th>
<th width="59"> <div align="center">Country </div></th>
<th width="59"> <div align="center">View </div></th>
<tr>
<?php if (isset($_POST['search'])) {
while ($row=mysql_fetch_array($query)){ ?>
<tr>
<td><?php echo $row['first_name'];?></td>
<td><?php echo $row['last_name'];?></td>
<td><?php echo $row['email'];?></td>
<td><?php echo $row['address_city'];?></td>
<td><?php echo $row['address_state'];?></td>
<td><?php echo $row['address_country'];?></td>
<td><input type="button" value="view"/> <td>
<tr>
<?php }} ?>
</table>
handler.php
<?php
$userid = $_GET['id'];
?>

Maybe you can use PHP Sessions.
* edits *
In this part you nested a button inside a tag.
<td><input type="button" value="view"/> <td>
Try just adding text there, like:
<td>View<td>
This will appear as clickable text "View" in blue font color and will redirect to hander.php .
Hope that helps.

Related

Both buttons decrementing same value

I am buildingd a library management system in PHP and HTMl.
I have some problem with the borrowing system where user can borrow books.
Here is my emitere-carti.php:
<form action="imprumutare.php" method="POST">
<table class="table table-dark">
<thead>
<tr>
<th>Imprumutare</th>
<th scope="col">Titlu </th>
<th scope="col">Autor</th>
<th scope="col">Categorie</th>
<th scope="col">Stoc</th>
</tr>
</thead>
<tbody>
<?php
$selectare="SELECT * FROM carti";
$rezultat=mysqli_query($conn,$selectare);
if(mysqli_num_rows($rezultat)>0){
while($row=mysqli_fetch_assoc($rezultat)){
$carte_nume=$row['titlu'];
$disabled=$row['stoc']>0 ? "" :"disabled";
?>
<tr>
<td><input type="submit" name="test" class="btn btn-secondary"
value="Imprumutare" <?php echo $disabled;?>></input>
<td><input type="text" name="nume" value="<?php echo $row['titlu'];?
>"></input></td>
<td><?php echo $row['autor'];?></td>
<td><?php echo $row['categorie'];?></td>
<td><?php echo $row['stoc'];?></td>
</tr>
<?php
}
}
?>
</tbody>
</table>
</form>
Here is my imprumutare.php(that means borrowing):
include('conexiune.php');
//sfarsit if
//Imprumutare
if(isset($_POST['test'])){
$id=$_POST['identificator'];
$nume_carte=$_POST['nume'];
$sql_rezervare="UPDATE carti SET stoc=stoc-1 WHERE
titlu='$nume_carte' ";
if( mysqli_query($conn,$sql_rezervare)){
header('location:emitere_carti.php');
}
else{
die(mysqli_error($conn));
}
}
Here is a screenshot about what I am talking:
So my problem is both buttons are decrementeing the same value(the value of stoc).
Can someone help me?

Data not being pulled when typing keyword in the search box

I have search feature that I setup. When I type the keyword in I get no records back and no error message. Just the table header. I see the department other in the database. When I type it in the keyword box I get nothing back.
<html>
<head>
<title></title>
</head>
<body>
<form name="frmSearch" method="get" action="">
<table width="599" border="1">
<tr>
<th>Keyword
<input name="txtKeyword" type="text" id="txtKeyword" value="<?php echo $_GET["txtKeyword"];?>">
<input type="submit" value="Search"></th>
</tr>
</table>
</form>
<?php
if($_GET["txtKeyword"] != "")
{
$serverName = "localhost";
$objConnect = new PDO( "sqlsrv:server=$serverName ; Database=maintenance", "TestUser", "test") or die("Error Connect to Database");
// Search By lanId or department
$objQuery = $objConnect->prepare("SELECT * FROM requests WHERE (lanId LIKE '%".$_GET["txtKeyword"]."%' or department LIKE '%".$_GET["txtKeyword"]."%' ) ");
?>
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">lanId </div></th>
<th width="98"> <div align="center">Name </div></th>
<th width="198"> <div align="center">department </div></th>
</tr>
<?php
while( $objResult = $objQuery->fetch(PDO::FETCH_ASSOC))
{
?>
<tr>
<td><div align="center"><?php echo $objResult["lanId"];?></div></td>
<td><?php echo $objResult["name"];?></td>
<td><?php echo $objResult["department"];?></td>
<?php
}
?>
</table>
<?php
}
?>
</body>
</html>
When you use prepare() statement you should also use execute() :
http://coursesweb.net/php-mysql/pdo-prepare-execute

How do i link search result with HTML page in PHP

Below is the code that i have written that would display data from phpmyadmin table and display the result. Now once the search result is displayed, let's say if i wish to click on one of the search result for e.g. i clicked on "Jon Doe" then upon click i should be redirected to the profile page (HTML page) of Jon Doe. May i know how do i do that ?
<?php
echo "<body style='background-color:gray'>";
include ("account.php");
( $dbh = mysql_connect( $hostname, $username, $password ))
or die ( "uable to connect to MYSQL database" );
mysql_select_db( $project );
if (isset($_POST['search'])) {
$sql= "SELECT * FROM registration ";
$search_term = mysql_real_escape_string($_POST['search_box']);
$sql .= "WHERE first_name= '{$search_term}'";
$sql .= " OR last_name= '{$search_term}'";
$query=mysql_query($sql) or die(mysql_error());
}
?>
<html>
<head>
<title>jon</title>
</head>
<body>
<form name="search_form" method="POST" action="retrieve.php">
<table width="599" border="1">
<tr>
<th>Search
<input type ="text" name ="search_box" value=""/>
<input type="submit" name="search" value="Find Users">
</tr>
</table>
</form>
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">First Name </div></th>
<th width="98"> <div align="center">Last Name </div></th>
<th width="198"> <div align="center">Email </div></th>
<th width="97"> <div align="center">City </div></th>
<th width="59"> <div align="center">Country </div></th>
<tr>
<?php if (isset($_POST['search'])) {
while ($row=mysql_fetch_array($query)){ ?>
<tr>
<td><?php echo $row['first_name'];?></td>
<td><?php echo $row['last_name'];?></td>
<td><?php echo $row['email'];?></td>
<td><?php echo $row['address_city'];?></td>
<td><?php echo $row['address_country'];?></td>
<tr>
<?php }} ?>
</table>
As Funk Doc already suggested you should make a "profile.php" for example which then queries all informations.
First you need to link the profile page. You need a "id" from your database.
<td><?php echo $row['first_name'];?></td>
Now you will redirect your user to profile.php with a special id.
example: profile.php?id=87341
In your profile.php you now need to get the id variable.
profile.php
<?php
$userid = $_GET['id'];
?>
The id is now saved in ´$userid´. Just search your database for that id and you get all your informations.
Ok lets say you have 2 Users John and Nick. John has id=1 and Nick id=2
John
Nick
handler.php
<?php
$id=$_GET['id'];
$query='SELECT * FROM #__users where id='.$id;
//show your results
?>

row from bootstrap table does not post value

I am having trouble when bootstrap table is installed. When I use data-toggle="table" to activate bootstrap I am not able to post checked value it always display NULL that means it is not checked . If I create normal table everything works great.
Does anyone know how to solve this issue, is this a bug?
<form method="post" action="unos.php">
<button type="submit" class="btn btn-primary" name="izmjena">Izmjena</button>
<table data-toggle="table" data-show-columns="true" data-click-to-select="true"
data-search="true" data-show-refresh="true" data-show-export="true" >
<tr>
<th data-field="artikli" data-checkbox="true" name="artikli"> </th>
<th data-field="sifra" data-sortable="true">Sifra</th>
<th data-field="name" data-sortable="true">Naziv</th>
</tr>
$q = $conn->query($sql);
while ($r = $q->fetch()): ?>
<tr>
<td><input type="checkbox" name="artikli" value="<?php echo $r['ArtId'];?>"></td>
<td><?=$r['ArtSifra'] ?></td>
<td><?=$r['ArtNaziv'] ?></td>
</tr>
<?php endwhile; ?>
</table>
</form>
// unos.php file
if (isset($_POST["izmjena"])) {
$id=(!empty($_POST["artikli"])) ? $_POST["artikli"] : '';
var_dump($id);
echo $id;
}

search data from database with multiple textbox using php

search with multiple textbox using php
I am try this code for search with multiple textbox using php and i am using orcle database but this code is not work. and any one let me know what is the problem why this code not search with multiple text box field and also i have getting error Warning: oci_execute(): ORA-00920: invalid relational operator in
plz check .....my code..
<form action="Optr_Search.php" method="get">
<table width="500" border="0" align="center">
<tr>
<td width="203"><div align="right"><strong>Operator ID:</strong>
</div></td>
<td width="148"><input type="text" name="OPRID" /></td>
</tr>
<tr>
<td><div align="right"><strong>Operator Name:</strong></div></td>
<td><input type="text" name="OPRDEFNDESC" /></td>
</tr>
<tr>
<td><div align="right"><strong>Person ID:</strong></div></td>
<td><input type="text" name="EMPLID" /></td>
</tr>
<tr>
<td><div align="right"><strong>Email ID:</strong></div></td>
<td><input type="text" name="EMAILID" /></td>
</tr>
<tr>
<td colspan="2">
<div align ="center">
</br>
<input type="submit" align ="middle"value="Search" name ="submit" />
</div>
</td>
</tr>
</table>
</form>
<?php
$ora_conn = oci_connect('system','oracle','//localhost/XE');
if(!$ora_conn)
{
$m = oci_error();
echo $m['message'], "\n";
exit;
}
else
{
print "You are connected to the database!<br/>";
}
if(isset($_POST['submit']))
{
$optid = $_POST['OPRID'];
$optdec = $_POST['OPRDEFNDESC'];
$empid = $_POST['EMPLID'];
$empmail = $_POST['EMAILID'];
$query = "SELECT * FROM OPERATOR WHERE 1";
if(isset($optid) && $optid != '') {
$query .= " And OPRID Like'%$optid%'";
}
if(isset($optdec) && $optdec != '') {
$query .= " OR OPRDEFNDESC Like'%$optdec%'";
}
if(isset($empid) && $empid != '') {
$query .= " OR EMPLID Like '%$empid%'";
}
if(isset($empmail) && $empmail != '') {
$query .= " OR EMAILID Like '%$empmail%'";
}
$objParse = oci_parse($ora_conn,$query);
$objResult = oci_execute ($objParse, OCI_DEFAULT);
?>
<table width="500" border="1" align="center">
<tr>
<th width="98"> <div align="center">Operator ID</div></th>
<th width="98"> <div align="center">Operator Name</div></th>
<th width="98"> <div align="center">Person ID</div></th>
<th width="98"> <div align="center">Email ID</div></th>
<th width="98"> <div align="center">Edit</div></th>
</tr>
<?php
if(oci_execute($objParse,OCI_DEFAULT)){
while($objResult = oci_fetch_array($objParse, OCI_RETURN_NULLS+OCI_ASSOC))
{
?>
<tr>
<td><div align="center"><?=$objResult["OPRID"];?></div></td>
<td><?=$objResult["OPRDEFNDESC"];?></td>
<td><?=$objResult["EMPLID"];?></td>
<td><div align="center"><?=$objResult["EMAILID"];?></div></td>
<td align="center">Edit
</td>
</tr>
<?
}
?>
</table>
<?
oci_free_statement($objParse);
oci_close($ora_conn);
}
?>
You are mixing ands and ors in SQL and this is not a good idea. If you set them all to or, you will have an issue because where 1 will always be true. I would make your or conditional on the where clause not being empty.

Categories