I have 2 search forms. One is linked to my local db of records and the other one links through an API to another db.
I want to now when my db does not have the required record, have it use the second search form without the user needing to insert the data again.
Is this possible and how do I go about merging the two?
Thanks for all the help guys.
Combination of form functions:
<div class="article">
<h2>
<br>
SEARCH A REFERENCE
<br>
</h2>
</center>
<body>
<div id="formsearch">
<br>
<form method="post" action="" name="form1" id="form1" >
Enter the ID Number
<br><br>
<b>Search Record </b> <input type="text" name="term" /><br />
<br>
<input type="submit" name="submit" value="Search" class="btn" />
</form>
</div>
<h3> <center> Search Result (s) </h3>
<?php
if ($_REQUEST['submit']) {
$term = $_POST['term'];
$row ['employerid'] == $user_data ['user_id'];
$XX = "<br><br><div class='messagebox'><h2> <center> Oops! </h2> <p>We were only to retrieve a partial record on <strong>$term</strong> you have entered. Please make use of our contact form if you would like us to get you your reference. Be sure to enter the three required fields. <a href='Mailforms/refrequest.php' class='lightbox'>Click Here!</a> or to validate the id <a href='idverification.php'> Click here</a></p>
<br />
</div>";
$sql = mysql_query("SELECT idnumber,
firstname,
lastname,
companyname,
jobtitle,
dismissal,
terminationdate,
startdate,
CONCAT(TIMESTAMPDIFF(YEAR,startdate,terminationdate), ' years and ',
MOD(TIMESTAMPDIFF(MONTH,startdate,terminationdate),12), ' months ') AS time_diff
FROM ref_employees
WHERE idnumber= '$term'")
or die('Error in query : $sql. ' .mysql_error());
if (mysql_num_rows($sql) > 0 ) {
while ($row = mysql_fetch_array($sql)){
if ($row ['employed'] == '1') {
echo '<h4>Currently Employed By : '.$row['companyname'];
echo '</h4> ';
echo 'Any doubts? Enquire about this candidate ';
}
if ($row ['employed'] == '0') {
echo ' <h4>Some Available Options For:</h4>';
include 'includes/admenu.php';
echo '<h4>Not Currently employed '.$row['companyname'];
echo '</h4> ';
}
echo "<table border='1' cellpadding='10'>";
echo "<tr> <th>ID Number</th> <th>First Name</th> <th>Last Name</th><th>company</th> <th>Job Title</th> <th>Period</th><th>Reason for dismissal</th><th></th><th></th></tr>";
echo "<tr>";
echo '<td>' . $row['idnumber'] . '</td>';
echo '<td>' . $row['firstname'] . '</td>';
echo '<td>' . $row['lastname'] . '</td>';
echo '<td>' . $row['companyname'] . '</td>';
echo '<td>' . $row['jobtitle'] . '</td>';
echo '<td>' .($row['startdate'] + $row['terminationdate']).'</td>';
echo '<td>' . $row['dismissal'] . '</td>';
echo '<td>Achievements</td>';
echo '<td>training</td>';
echo "</tr>";
}
// close table>
echo "</table>";
}
}
else
{
$id_number = $_POST['term'];
$authenticate = authentication();
$login_message = $authenticate['error_code'];
$session_id = $authenticate['session_id'];
$id_verification = verify_id($session_id, $id_number);
}
if (!empty($id_verification)){
echo '<br/>';
echo '<h3>Search Information</h3>';
echo 'Time Stamp: ';
echo $id_verification['TIME_STAMP'];
echo 'SOAP Result: ';
echo $id_verification['LOGIN-MESSAGE'];
echo ' ';
echo $id_verification['SEARCH-MESSAGE'];
echo ' ';
echo $id_verification['SEARCH-RESULT'];
echo '<br/>';
echo '<h3>Data: </h3>';
echo '<br/>ID Number: ';
echo $id_verification['IDNUMBER'];
echo '<br/>First Names: ';
echo $id_verification['FIRSTNAMES'];
echo '<br/>Last Name: ';
echo $id_verification['SURNAME'];
echo '<br/>Birthday: ';
echo $id_verification['BIRTHDAY'];
echo '<br/>Age: ';
echo $id_verification['AGE'];
echo '<br/>Gender: ';
echo $id_verification['GENDER'];
echo '<br/>Citizen: ';
echo $id_verification['CITIZEN'];
echo '<br/>Death Status: ';
echo $id_verification['DEATH-STATUS'];
echo '<br/>Death Date: ';
echo $id_verification['DEATH-DATE'];
echo '<br/>Death Place: ';
echo $id_verification['DEATH-PLACE'];
unset($_SESSION['id_verification']);
}
mysql_free_result($sql);
mysql_close($connection);
?>
Send both search form into one location.
First you need to search into local if not again search it in API. Mean you need to do the search in single server file.
Hope this clear else post me in detail.
Related
My code:
<?php
if (isset($_GET["q"]))
{
$q= $_GET["q"]; # this is team name
$link=mysqli_connect("localhost","root","");
mysqli_select_db($link,"onesports");
$result=mysqli_query($link," select * from team where team_name='" .$q. " ' ");
$result2=mysqli_query($link,"select players.full_name, team.* from players,team where team.team_name='" .$q. " ' and players.team_name=team.team_name ");
while($row = mysqli_fetch_array($result)) {
?>
<table>
<tr>
<td style="font-size: 30px; font-variant-caps:petite-caps;" > <?php echo $row['team_name']; ?> </td>
<td style="text-transform: capitalize; "> <?php echo "("; echo $row['city'] ; echo ","; echo $row['prov']; echo ")"; ?> </td>
</tr>
<tr>
<td style="text-transform: capitalize;">
<?php echo $row['captain']; echo "(c)"; ?>
</td>
<td style="text-transform: capitalize;"> <?php echo $row['coach']; ?> </td>
</tr>
</table>
<hr>
<?php
}
echo '<table cellpadding="0" cellspacing="0" class="db-table">';
echo "<tr>";
echo "<th>";
echo "Players";
echo "</th>";
echo "</tr>";
while($row = mysqli_fetch_array($result2)) {
echo "<tr>";
echo "<td>";
echo '<a href= " " >' . $row['full_name'] . '</a>';
echo "</td>";
echo "</tr>";
}
echo "</table>";
The problem is that I'm getting full_name dynamically, every name has some details in db I want to get.
When I click on full_name, I want it to give me all the related data from the DB.
This is the part with the links:
echo '<table cellpadding="0" cellspacing="0" class="db-table">';
echo "<tr>";
echo "<th>";
echo "Players";
echo "</th>";
echo "</tr>";
while($row = mysqli_fetch_array($result2)) {
echo "<tr>";
echo "<td>";
echo '<a href= " " >' . $row['full_name'] . '</a>';
echo "</td>";
echo "</tr>";
}
echo "</table>";
So kindly help me. Do you suggest that I use any other tag rather than an anchor tag, or you can tell me how to get data this way?
As I got the point, you need to retrieve the information by clicking the relevant link.
You can use the following structure:
echo ''.$row["full_name"].'';
Then at your server-side code, get the data by using
$_GET['FN']
I hope this answer help you as well as.
browse image
db image
here is both pic browser and db onesports is my db name and players is table name,
in browser image you can see players name i want when i click on players name it show related data on same page
Here is the php code, please review
As I mentioned, because of setting "player_id" as your primary key, you have to fetch the information by using it.
echo ''.$row["full_name"].'';
Your Query should be in the following format:
Select * from `players` Where `player_id` = $_GET['player_id']
I am trying to develop a program that search in mysql database and return the search results but in when I hit the submit it displays all the results I don't know why this is happening, so any help will be appreciated
<?php
include('connect2.php');
?>
<?php
echo "<center>";
echo "<table border = '3'>";
echo "<thead>";
echo "<tr>";
echo "<th><u>id</u></th>";
echo "<th><u>name</u></th>";
echo "<th><u>countrycode</u></th>";
echo "<th><u>district</u></th>";
echo "<th><u>population</u></th>";
echo "</center>";
echo "</tr>";
echo "</thead>";
$name = isset($_POST['search']) ? $_POST['search'] : '';
$result = mysqli_query($conn, "SELECT id, name, district, population, countrycode FROM city WHERE concat(id, name, district, population, countrycode) LIKE '%$name%' ");
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_array($result)) {
echo "<tr><td>" . $row['id'] . "</td><td>" . $row['name'] . "</td><td>" . $row['countrycode'] . "</td><td>" . $row['district'] . "</td><td>" . $row['population'] . "</td></th>";
}
}
else {
header( "Location:error page.html" ); die;
}
echo "</table>";
mysqli_close($conm);
?>
the search page search.php
<?php
include('connect2.php') ;
?>
<!DOCTYPE html>
<head>
<title>city results</title>
<link href="style-table.css" rel="stylesheet">
<link href="animate.css" rel="stylesheet">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
<script>
function validateform() {
var x = document.forms["myform"]["input"].value;
if (x == "") {
alert("input must be filled out");
return false;
}
}
</script>
</head>
<body>
<form method="POST" action="display-results-city.php" name="myform" onsubmit="return validateform()">
<input type="text" name="input" placeholder="search.........">
<button name="submit" type="submit">go</button>
</form>
<?php
echo '<div class="animated fadeInUp">';
echo '<i class="fa fa-arrow-left fa-lg" aria-hidden="true" ></i>';
echo "<div id='records'>";
echo "<table border = '0'>";
echo "<tr>";
echo "<th>ID</th>";
echo "<th>name</th>";
echo "<th>countrycode</th>";
echo "<th>district</th>";
echo "<th>population</th>";
echo "</tr>";
echo "</div>";
echo '</div>';
$sql = "select * from city limit 50";
$result = $conn->query($sql);
if( $result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "<tr><td>" . $row['ID']. "</td><td>" . $row['Name']. "</td><td>" . $row['CountryCode'] . "</td><td>" . $row['District'] . "</td><td>" . $row['Population'] . "</td></tr>";
}
} else {
echo " 0 results";
}
echo '</table>';
$conn->close();
?>
</body>
</html>
Try running this query..
$result = mysqli_query($conn, "SELECT id, name, district, population, countrycode FROM city WHERE UPPER(concat(id, name, district, population, countrycode)) LIKE UPPER('%$name%') ");
It will match both "Name" and "name".
I want to update my database by using checkbox. But it seems like the code doesn't loop in a foreach. Where did I go wrong ? Is there have anything wrong with my foreach ?
<?php
foreach($_POST['listMenu'] as $checkBox1){
$strUpdateData = "
update tblMenuAkses
set MenuAkses = 'N'
where MenuAksesID = $checkBox1
";
$rsUpdateData = odbc_exec($dbconnVOT,$strUpdateData);
if($rsUpdateData){
echo "Success";
} else {
echo "ERROR <br>";
echo odbc_errormsg($dbconnVOT);
}
}
//It loops here
var_dump($_POST['listMenu']);
?>
<form method="post" action="skrinMenu.php" enctype="multipart/form-data">
<table align= "center" border="1" cellspacing="0" cellpadding="2">
<?php
$strgettable="select * from tblMenuAkses";
$varRecCount=0;
$rs=odbc_exec($dbconnVOT, $strgettable);
if($rs){
while (odbc_fetch_row($rs)) {// loop a table from database and checkbox too
$varRecCount++;
echo '<tr><td>';
echo '<center> '.$varRecCount.'</center>';
echo '</td>';
echo '<td>';
echo '<center> '.odbc_result($rs,"UsrGrpNama").'</center>';
echo '</td>';
echo '<td>';
echo '<center> '.odbc_result($rs,"MenuNama").'</center>';
echo '</td>';
echo '<td>';
echo '<center> '.odbc_result($rs,"MenuAkses").'</center>';
echo '</td>';
echo '<td>';
echo '<center> <input type="checkbox" name="listMenu[]" id="listMenu" value='.odbc_result($rs,"MenuAksesID").'> </center>';
echo '</td>';
echo '</td></tr>';
}
}
?>
</table>
<input type="submit" name="btnMenu" id="btnMenu" value = "Kemaskini">
</form>
The result of the var_dump($_POST['listMenu']) : NULL
I'm in the process of making a PHP website, where a user can input data, then search through it later, but I can't seem to organize the data :/
Heres my code:
<form action="uploads.php" method="GET"><input id="search" type="text" placeholder="Type here"><input id="submit" type="submit" value="Search"></form></body></html>
When a user searched for their name, it results as so:
firstname=Mickey lastname=Mouse item1= item2= item3= item4= item5= item6=
Is there any way I can add a CSS or something to get the entries to line break or seperate?
In Your display page while displaying the data you can use the <br> tag so that it will display each and every data in different line.
First Name: <?php echo $loopvariable['fname'].'<br />'; ?>
Last Name: <?php echo $loopvariable['lname'].'<br />'; ?>
Like this you can provide for all the data which you print.
Output:
First Name: Name One
Last Name: Name Two
And you can provide as such information using the break tags in separate lines.
Basically in PHP you can echo html code so you can echo <br> statements as in the previous answer you can also echo css and you can create a block of code that you include
<?php
include('SomeMoreCode.php');
?>
You can also echo formatting commands to create a table. Just place the html statements in'' and join html and mysql/php values with .
echo "<table border='1' cellpadding='10'>";
echo "<tr> <th>date</th> <th>Home Team</th> <th></th><th></th><th>Away Team</th> <th></th> </tr>";
while($row = mysql_fetch_array( $result )) {
echo "<tr>";
echo '<td>' . $row['date'] . '</td>';
echo '<td>' . $row['hometeam'] . '</td>';
echo '<td>' . $row['fthg'] . '</td>';
echo '<td>' . $row['ftag'] . '</td>';
echo '<td>' . $row['awayteam'] . '</td>';
echo '<td>Edit</td>';
echo "</tr>";
}
echo "</table>";
non mysql - php only
<?php
$date='19/6/16';
$hometeam='Man United';
$fthg='3';
$ftag='2';
$awayteam='Man City';
echo "<table border='1' cellpadding='10'>";
echo "<tr> <th>date</th> <th>Home Team</th> <th></th><th></th><th>Away Team</th> </tr>";
echo "<tr>";
echo '<td>' . $date . '</td>';
echo '<td>' . $hometeam . '</td>';
echo '<td>' . $fthg . '</td>';
echo '<td>' . $ftag . '</td>';
echo '<td>' . $awayteam . '</td>';
echo "</tr>";
echo "</table>";
?>
I'm having some display problems here.
I have a "backend.php" file where I ask for two inputs.
These inputs are processed by "Addproducts.php" file and this file redirects to backend.php.
Backend.php also shows the current records in the database.
Here's the code for backend.php
<html>
<head>
<title>Inventory - Backend</title>
</head>
<body>
<form action="addproducts.php" method="post">
<table>
<tr>
<td>Product Name : </td>
<td><input type="text" name="pname"/></td>
</tr>
<tr>
<td>Product Quantity : </td>
<td><input type="text" name="productq"/></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td><input type="submit" name="Add Product"/></td>
</tr>
</table>
</form>
<h2>Current Products</h2>
<?php
$db = mysql_connect('127.0.0.1', 'root', '') or die ('Unable to Connect.Check your connection parameters');
mysql_select_db('stock_inventory', $db) or die (mysql_error($db));
$query = 'SELECT * FROM PRODUCTS';
$result = mysql_query($query, $db) or die (mysql_error($db));
echo '<table>';
echo '<tr>';
echo '<th>Product ID </th>';
echo '<th>Producr Name </th>';
echo '<th>Product Stock </th>';
echo '</tr>';
while($row = mysql_fetch_assoc($result))
{
if(mysql_num_rows($result) > 0)
{
echo '<tr>';
echo '<td>' . $row['product_id'] . '</td>';
echo '<td>' . $row['product_name'] . '</td>';
echo '<td>' . $row['product_stock'] . '</td>';
echo '</tr>';
echo '<br/>';
echo '</table>';
}
else
{
echo "No products in the database";
}
}
?>
</body>
</html>
It displays something like this :-
Product ID Producr Name Product Stock
1 NewProduct 1
2HTC One5
3Samsung10
4Sony10
You see?
Only the first product is aligned, the rest are not.
How do I make them all align ?
Thanks.
The reason is you are closing your table tag within the loop, move it outside the loop like follows:
while($row = mysql_fetch_assoc($result))
{
if(mysql_num_rows($result) > 0)
{
echo '<tr>';
echo '<td>' . $row['product_id'] . '</td>';
echo '<td>' . $row['product_name'] . '</td>';
echo '<td>' . $row['product_stock'] . '</td>';
echo '</tr>';
}
else
{
echo "No products in the database";
}
}
echo '<br/>';
echo '</table>';
Update: A better fix (see Barmar's comment below):
if (empty(mysql_num_row($result))) {
echo "<tr><td colspan='3'>No products in the database</td></tr>";
} else {
while($row = mysql_fetch_assoc($result)) {
echo '<tr>';
echo '<td>' . $row['product_id'] . '</td>';
echo '<td>' . $row['product_name'] . '</td>';
echo '<td>' . $row['product_stock'] . '</td>';
echo '</tr>';
}
}
echo '</table>';
Also start looking into using mysqli(http://php.net/manual/en/book.mysqli.php) or PDO (http://php.net/manual/en/book.pdo.php), mysql_ is deprecated!
I would suggest removing the
<br/>
from within your table. I believe that putting markup like line breaks inside of table markup will break the layout.