I have an issue with my code because when I press the update button I want it to display on the redirected page only the field that are checked in the checkbox.
I will post the code from the first page , then the code from the second page , where the update code is and some pictures of the website page .
First page :
firstpage
code firstpage:
<?php
if (isset ($_POST['search'])){
$ValueToSearch=$_POST['valueToSearch'];
$query1="SELECT * FROM `customer` AS cust,`type` AS type,`valability` AS val WHERE cust.Customer_ID=val.Customer_ID AND val.Insurance_ID=type.Insurance_ID AND CONCAT(cust.Customer_ID,cust.Employee_ID,cust.Name_c,cust.Surname_c,cust.brth,cust.phone,cust.adress,cust.email,type.series,type.type,type.name_i,type.Company_N,type.value,val.nr,val.entry_d,val.exp_d) LIKE '%".$ValueToSearch."%'";
echo "<!-- ". $query1 ." -->";
$search_result=filterTable($query1);
}else{
$query1 = "SELECT * FROM `customer`,`type`,`valability` WHERE customer.Customer_ID=valability.Customer_ID AND valability.Insurance_ID=type.Insurance_ID";
$search_result=filterTable($query1);
}
function filterTable($query1){
$connect=mysqli_connect("localhost" ,"root", "","asig");
$filter_Result=mysqli_query($connect,$query1);
return $filter_Result;
}
?>
<?php
if (isset($_POST['update'])) {
//$connect=mysqli_connect("localhost" ,"root", "","asig");
//$update_id=$_POST['checkbox'];
Header("Location: displayupdate.php");
//die();
//exit;
}else{
echo"can't redirect";
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Display Table </title>
<style>
table {
width: 100%;
background-color: #f1f1c1;
}
table ,tr, th, td
{
border:1px solid black;
border-collapse: collapse;
}
th,td{
padding: 5px;
}
</style>
</head>
<!--Beginning of CSS page-->
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<body>
<div class="w3-display-container" style="margin-bottom:50px">
<img src="image2/Insurance-2.jpg" style="width:100%">
<div class="w3-display-bottomleft w3-container w3-amber w3-hover-orange w3-hide-small"
style="bottom:10%;opacity:0.7;width:70%">
<h2><b>4 Good Reasons<br>For being a SafeAsig client</b></h2>
</div>
</div>
<!--Buton pentru display timp-->
<button type="button"
onclick="document.getElementById('demo').innerHTML = Date()">
Click me to display Date and Time.</button>
<p id="demo"></p>
<form action="display.php" method="post">
<input type="text" name="valueToSearch" placeholder="ValueToSearch">
<input type="submit" name="search" value="Filter">
<input type="submit" name="delete" value="Delete">
<input type="submit" name="update" value="Update">
<hr>
<h1 style="text-align:center;"> Date Clienti</h1>
<table>
<tr>
<th></th>
<th>id</th>
<th>Nume</th>
<th>Prenume</th>
<th>DataNastere</th>
<th>telefon</th>
<th>Adresa</th>
<th>email</th>
<th>serie</th>
<th>type</th>
<th>numeAsig</th>
<th>Companie</th>
<th>Valoare></th>
<th>Numar</th>
<th>DataIntrare</th>
<th>DataExpirare</th>
</tr>
<?php while ($row=mysqli_fetch_array($search_result)):?>
<tr>
<td><input type="checkbox" name="checkbox[]" value="<?php echo $row['Customer_ID']; ?>"/></td>
<td><?php echo $row['Customer_ID']; ?></td>
<td><?php echo $row['Name_c']; ?></td>
<td><?php echo $row['Surname_c']; ?></td>
<td><?php echo $row['brth']; ?></td>
<td><?php echo $row['phone']; ?></td>
<td><?php echo $row['adress']; ?></td>
<td><?php echo $row['email']; ?></td>
<td><?php echo $row['series']; ?></td>
<td><?php echo $row['type']; ?></td>
<td><?php echo $row['name_i']; ?></td>
<td><?php echo $row['Company_N']; ?></td>
<td><?php echo $row['value']; ?></td>
<td><?php echo $row['nr']; ?></td>
<td><?php echo $row['entry_d']; ?></td>
<td><?php echo $row['exp_d']; ?></td>
</tr>
<?php endwhile;?>
</table>
</form>
<!--Link pentru inserari-->
Inserare Clienti <br><br>
Inserare angajati <br><br>
<div class="w3-row w3-container" style="margin:50px 0">
<div class="w3-half w3-container">
<div class="w3-topbar w3-border-amber">
<img src="image2/profesionalism.jpg" style="width:100%">
<h2>Profesionalism and dedication</h2>
<p>Only for our clients , the best services provided.</p>
</div>
</div>
<div class="w3-half w3-container">
<div class="w3-topbar w3-border-amber">
<img src="image2/protection.jpg" style="width:100%">
<h2>100% protection</h2>
<p>Up to 100% protection with our wide varaity insurances.</p>
</div>
</div>
</div>
<div class="w3-row w3-container" style="margin:50px 0">
<div class="w3-half w3-container">
<div class="w3-topbar w3-border-orange">
<img src="image2/stability.jpg" style="width:100%">
<h2>Stability all times</h2>
<p>Wherever you travel our services provide stability.</p>
</div>
</div>
<div class="w3-half w3-container">
<div class="w3-topbar w3-border-orange">
<img src="image2/support.jpg" style="width:100%">
<h2>For good and worst</h2>
<p>Don't wait until it is to late.</p>
</div>
</div>
</div>
<?php
if (isset($_POST['delete'])) {
$connect=mysqli_connect("localhost" ,"root", "","asig");
$del_id = $_POST['checkbox'];
while(list($key, $val) = #each($del_id)){
mysqli_query($connect, "delete from customer where customer_id = $val");
}
}
?>
</body>
</html>
picture second page:
secondpage
code second page:
<html>
<?php
//Connect to database
$connect=mysqli_connect("localhost" ,"root", "","asig");
//Select database
mysqli_select_db($connect,'asig');
//Select Query
$sql = "SELECT * FROM `customer`,`type`,`valability` WHERE customer.Customer_ID=valability.Customer_ID AND valability.Insurance_ID=type.Insurance_ID";
//Execte query
$records=mysqli_query($connect,$sql);
?>
<head>
</head>
<body>
<table>
<tr>
<th>id</th>
<th>Nume</th>
<th>Prenume</th>
<th>DataNastere</th>
<th>telefon</th>
<th>Adresa</th>
<th>email</th>
<th>serie</th>
<th>type</th>
<th>numeAsig</th>
<th>Companie</th>
<th>Valoare></th>
<th>Numar</th>
<th>DataIntrare</th>
<th>DataExpirare</th>
</tr>
<?php
while($row=mysqli_fetch_array($records)){
echo "<tr><form action=update.php method=post>";
// echo "<td><input type=checkbox name=checkbox[] value='".$row['Customer_ID']."'></td>";
echo "<td><input type=hidden name =id value='".$row['Customer_ID']."' ></td>";
echo "<td><input type=text name= name value='".$row['Name_c']."'> </td>";
echo "<td><input type=text name=prenume value='".$row['Surname_c']."'> </td>";
echo "<td><input type=text name=brth value='".$row['brth']."'> </td>";
echo "<td><input type=text name=phone value='".$row['phone']."'> </td>";
echo "<td><input type=text name=adress value='".$row['adress']."'> </td>";
echo "<td><input type=text name=email value='".$row['email']."'> </td>";
echo "<td><input type=text name=serie value='".$row['series']."'> </td>";
echo "<td><input type=text name=type value='".$row['type']."'> </td>";
echo "<td><input type=text name=namei value='".$row['name_i']."'> </td>";
echo "<td><input type=text name=compn value='".$row['Company_N']."'> </td>";
echo "<td><input type=text name=value value='".$row['value']."'> </td>";
echo "<td><input type=text name=nr value='".$row['nr']."'> </td>";
echo "<td><input type=text name=entryin value='".$row['entry_d']."'> </td>";
echo "<td><input type=text name=entryout value='".$row['exp_d']."'> </td>";
echo "<td><input type=submit>";
echo "</form></tr>";
}
?>
</table>
</body>
</html>
Since your action goes to display.php, I will assume that your 'second page' is display.php. If that is the case then you need to retrieve the submitted checked values with $_POST[].
In your example the check boxes are named 'checkbox' so your POST should look like below...
<?php
$customer_id_arr = $_POST['checkbox'];
$customer_id_str = implode(",", $customer_id_arr);
//Connect to database
$connect=mysqli_connect("localhost" ,"root", "","asig");
//Select database
mysqli_select_db($connect,'asig');
//Select Query
$sql = "SELECT * FROM `customer`,`type`,`valability` WHERE customer.Customer_ID IN(" . $customer_id_str . ") AND valability.Insurance_ID=type.Insurance_ID";
//Execte query
$records=mysqli_query($connect,$sql);
?>
<html>
Your code overall needs a good bit of work/cleanup.
Hope that helps.
I have the following scenario. A card reader that reads an ID card and gets the data and displays them in a table (webpage). What I am doing now is removing the table, inserting the ID Card image in the background and superimposing the card data on the image in the appropriate position, i.e. the user photo on the card's photo position, the user's name on the card's Name position etc.
When I try to put the card image in the background either directly as table/form background image, or through css, most of the time it doesn't show right or does not show at all. when it shows, I can not get the data to superimpose correctly. I have tried through css, divs with z-index etc, and nothing works correctly. I can see the data but can not arrange them on the ID card image. Here's the code I have been working on. This is a php webpage we are talking about.
<div id="login" class="login">
<form id="iform" name="iform" method="post" action="<?php echo $_SERVER['SCRIPT_NAME'];?>">
<table class="tabcont" width="100%" valign="center" border="0" cellpadding="0" cellspacing="0" summary="main area">
<tr><td align="center" class="listlr" colspan="2">
</td></tr>
<tr><td align="center" class="listlr" colspan="2">
</td></tr>
<?php if (is_array($result) && count($result) > 0):
foreach ($result as $reskey => $resvalue) {
if ($reskey == 'Surname')
echo "<input class='formfld' value='{$resvalue}'/>";
if ($reskey == 'FirstName')
echo "<input class='formfld' value='{$resvalue}'/>";
if ($reskey == 'DateOfBirth')
echo "<input class='formfld' value='{$resvalue}'/>";
if ($reskey == 'PlaceOfBirth')
echo "<input class='formfld' value='{$resvalue}'/>";
if ($reskey == 'NationalID')
echo "<input class='formfld' value='{$resvalue}'/>";
if ($reskey == 'Sex')
echo "<input class='formfld' value='{$resvalue}'/>";
if ($reskey == 'Nationality')
echo "<input class='formfld' value='{$resvalue}'/>";
if ($reskey == 'DocumentNumber')
echo "<input class='formfld' value='{$resvalue}'/>";
if ($reskey == 'CardEffectiveDate')
echo "<input class='formfld' value='{$resvalue}'/>";
if ($reskey == 'CardExpirationDate')
echo "<input class='formfld' value='{$resvalue}'/>";
echo "<tr><td width='0%'></td>";
echo "<td width='0%'>";
if ($reskey == 'CardholderPortraitImage')
echo "<img id='{$reskey}' src='{$resvalue}' value=''/>";
if ($reskey == 'CardholderHandwrittenSignatureImage')
echo "<img id='{$reskey}' src='{$resvalue}' value=''/>";
echo "</td></tr>";
}
else: ?>
<tr> <td>
<?php
echo "<div align=\"center\" class=\"listtopic\" id=\"iderror\">{$errormsg}</div>";
?>
</td>
</tr>
<?php endif; ?>
</table>
</form>
</div>
I am also trying to wrap php in DIVs like so to get to arrange the data files through css and z-index, but nothing happens:
echo '<div class="image">';
echo '</div>';
<div class="foto">';
<?php if ($reskey == 'CardholderPortraitImage')
echo "<img id='{$reskey}' src='{$resvalue}' value=''/>";
?>
</div>
What am I doing wrong?
I am working on a Zip Code search, and have successfully built the search. Now, I need to have the ability to click on an image map of a map, and hardcode an href to a dynamic URL
So for example, the search works well displaying contact information for a zip code in PA. But if I have an image map, I'd like the ability for it to display the same contact information if I click the image map of PA on the map image.
Here is the code I'm using to do the search, and at the bottom is the code I need help with for the image map.
<form action="search6.php" method="post">
<p><span class="orange16">Zip Code:</span>
<input type="text" name="search_name"> <input type="submit" value="Search" />
</p>
</form>
<br />
<table width="700" border="0">
<?php
if (isset($_POST['search_name'])) {
$search_name = $_POST['search_name'];
if (!empty($search_name)) {
if (strlen($search_name)>=5) {
$query = "SELECT * FROM `search4` WHERE `ZipCode` LIKE '%".mysql_real_escape_string($search_name)."%'";
$query_run = mysql_query($query);
if (mysql_num_rows($query_run)>=1) {
echo "<table width=700' border='0'>";
echo "<tr>";
echo "<td width='700' valign='top'><table width='100%' border='0'>";
echo "<tr>";
echo "<td><p><strong>Results found: </strong></p>";
while ($query_row = mysql_fetch_assoc($query_run)) {{
echo $query_row['ZipCode'].', ';
echo $query_row['ZipCity'].', ';
echo $query_row['ZipState'].'<br><br>';
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>";
echo '<span class="productdescription"><p>Office: </p></span></h2>';
echo $query_row['Office'].'<br>';
echo $query_row['Address1'].'<br>';
if(!empty($query_row['Address2'])) // This will skip if the field if it's empty
echo $query_row['Address2'].'<br>';
echo $query_row['City'].', ';
echo $query_row['State'].' ';
echo $query_row['Zip'].'<br>';
echo '<p><strong>Phone Number: </strong></p>';
echo $query_row['Phone'].'<br>';
echo '<p><strong>Fax Number: </strong></p>';
echo $query_row['Fax'].'<br><br>';
echo "</td>";
echo "</tr>";
echo "</table>";
echo "</td>";
//BeginImage display result
$res=mysql_query("select * from Images");
{
echo "<td width='703' align='right' valign='top'>";?> <img src="<?php echo $query_row["Image"]; ?>"> <?php echo "</td>";
echo "</tr>";
}
//EndImage display result
echo ("<table width='700px' border='0' cellpadding='5' cellspacing='1'>
<tr>
<td width='13%' align='left' bgcolor='#C1DDF4'><p><strong>Service Type:</strong></p></td>
<td width='13%' align='left' bgcolor='#C1DDF4'><p><strong>Name:</strong></p></td>
<td width='13%' align='left' bgcolor='#C1DDF4'><p><strong>Phone:</strong></p></td>
<td width='13%' align='left' bgcolor='#C1DDF4'><p><strong>Email:</strong></p></td>
</tr>");
echo ("
<td align='left'><p><strong>Sales</strong></p></td>
<td align='left'><p>$query_row[SalesName]</p></td>
<td align='left'><p>$query_row[SalesPhone]</p></td>
<td align='left'><p><a href='mailto:$query_row[SalesEmail]'class='admin_links'>$query_row[SalesEmail]</p></a></td>
</tr>");
echo ("
<td align='left'><p><strong>Service</strong></p></td>
<td align='left'><p>$query_row[ServiceName]</p></td>
<td align='left'><p>$query_row[ServicePhone]</p></td>
<td align='left'><p><a href='mailto:$query_row[ServiceEmail]'class='admin_links'>$query_row[ServiceEmail]</p></a></td>
</tr>");
echo ("
<td align='left'><p><strong>Service Coordinator</strong></p></td>
<td align='left'><p>$query_row[ServiceCoorName]</p></td>
<td align='left'><p>$query_row[ServiceCoorPhone]</p></td>
<td align='left'><p><a href='mailto:$query_row[ServiceCoorEmail]'class='admin_links'>$query_row[ServiceCoorEmail]</p></a></td>
</tr>");
echo ("</table>");
}
}
}else{
echo 'No results found.';
}
}else{
echo 'Your search must be a 5-digit zip code.';
}
}
}
?>
</table>
This is the code for the Image map I need help with. I'd like to use the "CustClassID" data row for my value of lets say "23-LA".
<?php
$query = "SELECT * FROM search4 WHERE CustClassID = {$_GET['CustClassID']}";
echo ("<table width='600' border='0'>
<tr>
<td align='center'> <img src='images/greymap.png' border='0' usemap='#Map' />
<map name='Map' id='Map'>
<area shape='rect' coords='42,21,136,98' href='search6.php?CustClassID=23-LA' />
</map></td>
</tr>
</table>
");
?>
Basically, is there another way to get the same results as the search, by clicking on specific areas on the imagemap? Please point me in right direction.
I am using php / mysql and protype.js to delete record from a table. problem is that after deleting record from grid, grid is not updating automatically in template.
This is my code:
Step 1: index.php
<?php
require("Connection.php");
$sql = "SELECT * from tbluser";
$result=mysql_query($sql);
?>
<html>
<head>
<script src="prototype.js" type="text/javascript"></script>
<script src="scriptaculous-js/src/scriptaculous.js" type="text/javascript"></script>
<script language="javascript">
function fnDeleteRecord(id)
{
new Ajax.Request('delete.php?action=Delete&id='+id,{method:'get'});
}
</script>
</head>
<body>
<table id="userrecords" border="1" cellpadding="0" cellspacing="0" width="700">
<tr>
<th> User Name </th>
<th> Password </th>
<th> Address </th>
<th> Phone Number </th>
<th> Action </th>
<th> Status </th>
</tr>
<?php
while($row = mysql_fetch_array($result))
{
echo "<tr id='".$row[id]."'>";
echo "<td>".$row['user_name']."</td>";
echo "<td>".$row['pass']."</td>";
echo "<td>".$row['address']."</td>";
echo "<td>".$row['phone_no']."</td>";
echo "<td><img src='images/spinner.gif' id='a[$row[id]]' alt=icon border=0 /><a href='javascript:void(0);' onclick=fnDeleteRecord('".$row['id']."'); >Delete</a></td>";
if($row['status'] == 'enabled')
echo "<td><img src='images/spinner.gif' id='a[$row[id]]' alt=icon border=0 style='display:none;' /><img src='images/enable.png' alt=icon border=0 onClick=fnUpdateStatus('".$row['id']."','disabled') /></td>";
else if ($row['status'] == 'disabled')
echo "<td><img src='images/spinner.gif' id='a[$row[id]]' alt=icon border=0 style='display:none;' /><img src='images/disable.png' alt=icon border=0 onClick=fnUpdateStatus('".$row['id']."','enabled') /></td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
</body>
</html>
Step 2: delete.php
<?php
require_once('connection.php');
if ($_GET['action'])
{
switch($_GET['action'])
{
case 'Delete':
$sql = "Delete from tbluser where id ='".$_GET['id']."'";
$result = mysql_query($sql);
if(!$result)
echo "some problem occured during delete operation";
break;
}
}
?>
You can remove that table row with prototype:
<script language="javascript">
function fnDeleteRecord(id)
{
new Ajax.Request('delete.php?action=Delete&id='+id,{method:'get'});
$(id).remove(); // because <tr id='".$row[id]."'> :)
}
</script>
Sorry for asking an implement my feature question type question last time. I am new to Stackoverflow.com and also to php that's why.
What I was trying to ask is:
I have made a admin account. Members have registration page so a member will register. When user registers in the database table I will have a field for which 0 value will be initialised which means he is not approved. In admin account I have code to get the list of members. The code is given below:
<h2><?php echo "User list"; ?></h2>
<table border="0" cellpadding="0" cellspacing="0">
<tr bgcolor="#f87820">
<td><img src="img/blank.gif" alt="" width="10" height="25"></td>
<td class="tabhead"><img src="img/blank.gif" alt="" width="150" height="6"><br><b><?php echo "first name"; ?></b></td>
<td class="tabhead"><img src="img/blank.gif" alt="" width="150" height="6"><br><b><?php echo "lastname name"; ?></b></td>
<td class="tabhead"><img src="img/blank.gif" alt="" width="150" height="6"><br><b><?php echo "member id"; ?></b></td>
<td class="tabhead"><img src="img/blank.gif" alt="" width="50" height="6"><br><b><?php echo "delete"; ?></b></td>
<td><img src="img/blank.gif" alt="" width="10" height="25"></td>
</tr>
<?php
}
$result=mysql_query("SELECT member_id,firstname,lastname,login FROM members ORDER BY firstname");
$i = 0;
while($row = mysql_fetch_array($result)) {
if ($i > 0) {
echo "<tr valign='bottom'>";
echo "<td bgcolor='#ffffff' height='1' style='background-image:url(img/strichel.gif)' colspan='6'></td>";
echo "</tr>";
}
echo "<tr valign='middle'>";
echo "<td class='tabval'><img src='img/blank.gif' alt='' width='10' height='20'></td>";
echo "<td class='tabval'><b>".$row['lastname']."</b></td>";
echo "<td class='tabval'>".$row['firstname']." </td>";
echo "<td class='tabval'>".$row['member_id']." </td>";
echo "<td class='tabval'><a onclick=\"return </span></a></td>";
echo "<td class='tabval'></td>";
echo "</tr>";
$i++;
}
?>
</table>
in this i wanna add tho more things in the table 1 to delete a member and 2 to have approved or denied option for that i made two functiom
below code is to delete
if($_REQUEST['action']=="del")
{
$memberId = mysql_real_Escape_string($_REQUEST['member_id']);
mysql_query("DELETE FROM members WHERE member_id=$memberId");
}
below one for approving members
But my problem is I don't know how to include a button or radio button in the table which can pass value delete or approve to these functions.
Please tell me how the syntax is to add this button so that for approving I can change the value 0 that I gave in the database to 1 so that member get approved.
Try this:
echo '<td><a href="http://yourwebsite/yourscriptname.php?action=del&member_id='
. htmlspecialchars($row['member_id']) . '">Delete</a>';
if ($row['approved'] == 0) {
echo ' <a href="http://yourwebsite/yourscriptname.php?action=approve&member_id='
. htmlspecialchars($row['member_id']) . '">Approve</a>';
}
echo '</td>';
And make sure ALL of your database values are being sent to the browser in htmlspecialchars().
On the flipside,
$member_id = 0;
if (isset($_GET['member_id'])) $member_id = intval($_GET['member_id']);
$action = '';
if (isset($_GET['action'])) $action = $_GET['action'];
$sql = '';
switch($action) {
case 'approve':
$sql = "UPDATE members SET approval = 1 WHERE member_id = $member_id";
break;
case 'delete':
$sql = "DELETE FROM member WHERE member_id = $member_id";
break;
}
if (!empty($sql) && !empty($member_id)) {
// execute the sql.
}
What I would do is to set up a form inside of the table.
?> <form name="deleteUser" id="deleteUser" method="post" action="">
<input type="hidden" name="member_id" id="member_id" value="<?php echo $row['member_id'] ?>
<input type="submit" name="action" id="action" value="del" />
</form><?php
I would insert that in between your <td> tag.
<td class='tabval'>INSERT HERE</td>";