So I have created a form that takes in entries and stores them in a SQL database called Warehouse_Maitenence (yes I know it is mispelled and I did that on purpose). The goal for this set of code is to connect to the database and display the table accordingly
<?php include("nav.php") ?>
<body style='background-color:#C0C0C0'>
<style>
.top{
text-align: Left;
}
.Headers_Inputs{
padding-top: 20px;
padding-bottom: 20px;
border-style: solid;
border-width: 1px;
}
input{
width: 100%;
}
.PRIMARY_TABLE{
padding-left: 20px;
padding-right: 20px;
width: 100%;
}
body{
padding-left: 20px;
padding-right: 20px;
padding-top: 20px;
padding-bottom: 60px;
}
.PRIMARY_TRAY{
border-style: solid;
border-width: 2px;
}
</style>
<body>
<table width="100%" border="1">
<tr>
<th style="text-align: center; font-size: 16px;"> ID </th>
<th style="text-align: center; font-size: 16px;"> MACHINE </th>
<th style="text-align: center; font-size: 16px;"> LABEL </th>
<th style="text-align: center; font-size: 16px;"> CONDITION </th>
<th style="text-align: center; font-size: 16px;"> ACTION </th>
<th style="text-align: center; font-size: 16px;"> ADDRESS </th>
<th style="text-align: center; font-size: 16px;"> DATE </th>
<th style="text-align: center; font-size: 16px;"> COMMENT </th>
<th style="text-algin: center; font-size: 16px;"> DELETE </th>
</tr>
<?php
$username="";
$password="";
$database="";
$servername = "";
$conn = mysqli_connect($servername, $username, $password, $database);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = 'SELECT ID, MACHINE, LABEL, COND, ACTION, ADDRESS, DATE, COMMENT FROM Warehouse_Maitenence ORDER BY `Warehouse_Maitenence`.`MACHINE` ASC, `Warehouse_Maitenence`.`LABEL` ASC, `Warehouse_Maitenence`.`ID` ASC';
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "<tr>";
echo "<td style='text-align: center; font-size: 16px;' id=".$row["ID"].">".$row["ID"]."</td>";
echo "<td style='text-align: center; font-size: 16px;'>".$row["MACHINE"]."</td>";
echo "<td style='text-align: center; font-size: 16px;'>".$row["LABEL"]."</td>";
echo "<td style='text-align: center; font-size: 16px;'>".$row["COND"]."</td>";
echo "<td style='text-align: center; font-size: 16px;'>".$row["ACTION"]."</td>";
echo "<td style='text-align: center; font-size: 16px;'>".$row["ADDRESS"]."</td>";
echo "<td style='text-align: center; font-size: 16px;'>".$row["DATE"]."</td>";
echo "<td style='text-align: center; font-size: 16px;'>".$row["COMMENT"]."</td>";
echo "<td style='text-align: center; font-size: 16px;'><input type='button' onclick=delete_entry(".$row["ID"].")</td>";
echo "</tr>";
}
} else { echo "0 results"; }
echo "</table>";
mysqli_close($conn);
?>
So This level of code does work as intended up to the deletion point. I want to be able to load buttons on the end of each row of the table and onclick delete that row from the table and SQL Database.
For the table I have a JS already which works in another set of code I have been working on.
function deleteRow(r) {
var i = r.parentNode.parentNode.rowIndex;
document.getElementById("dataTable").deleteRow(i);
}
I know that onclick I will need to reconnect to the database (no issues there since it is already in this code) and then run
DELETE FROM `Warehouse_Maitenence` WHERE `Warehouse_Maitenence`.`ID` = whatever row was selected
but I am not sure how to put it all together, since I am not doing a form submission.
Am only good with php and i will advice you to do this..
add this to the list of the table
<td>
<form action="delete.php" method="post" enctype="multipart/form-data">
<input type="text" name="id" value="<?php echo $id; ?>" style="display:none;" />
<input type="submit" name="delete" value="Delete" class="btn btn-danger" />
</form>
</td>
then create a page call delete.php
<?php
if(!isset($_SERVER['HTTP_REFERER'])){ //This is to stop direct access to this delete.php page
header('location: /404.php'); //where to be redirected to
exit;
}
session_start();
include("connect.php"); //your database connection declaration page
if(isset($_POST['delete'])){ //name from the form from table
$id = mysqli_real_escape_string($con, $_POST['id']); //id of the row
$variable = $con->query("DELETE FROM tablename WHERE id = '$id'") or die(mysqli_error($con)); //connecting to the db to the table to delete
if($variable == TRUE){
echo"<script>alert('Deletion Completed!');</script>";
echo"<meta http-equiv='refresh' content='0 url=page.php' />"; //where to be redirected to after deleting.
}else{
echo"<script>alert('Error');</script>";
print_r("Error, Lets go back and Try again");
echo"<meta http-equiv='refresh' content='0 url=page.php' />";
}
exit();
}
?>
I hope am able to solve your issues.!
this is my first post and im already totally confused about my project right now :x
im able to make a successful connection to the sql db and also receive my data which displays on the top left, BUT its supposed to display in a html table, not somewhere on the screen :O
Here is the website to see the code in action, though there is none yet!
http://blackskill.square7.ch/
Here is the code which is running fine, but maybe im just too stupid and new for coding yet xd
<!DOCTYPE html>
<?php
$connection=mysqli_connect("localhost","username","password","db_name");
if ($connection) {
echo "database online <br>";
} else {
die("Connection failed. Reason: ".mysqli_connection_error());
}
$sql="SELECT * FROM blackskill_playerdb";
$results=mysqli_query($connection,$sql);
if (mysqli_num_rows($results)>0) {
while($row=mysqli_fetch_array($results)) {
echo '<tr>
<td>'.$row[0].'</td>
<td>'.$row[1].'</td>
<td>'.$row[2].'</td>
<td>'.$row[3].'</td>
</tr>';
echo "<br>";
}
}
mysqli_close($connection);
?>
<html>
<head>
<style>
* {
box-sizing: border-box;
}
#myInput {
background-image: url('/searchicon.png');
background-position: 10px 10px;
background-repeat: no-repeat;
width: 20%;
font-size: 16px;
padding: 12px 20px 12px 40px;
border: 1px solid #ddd;
margin-bottom: 12px;
}
#myTable {
border-collapse: collapse;
width: 100%;
border: 1px solid #ddd;
font-size: 18px;
}
#myTable th, #myTable td {
text-align: left;
padding: 12px;
}
#myTable tr {
border-bottom: 1px solid #ddd;
}
#myTable tr.header, #myTable tr:hover {
background-color: #f1f1f1;
}
</style>
</head>
<body>
<h2><center>Inofficial S.K.I.L.L. - Special Force 2 - Dishonor List</center></h2>
<input type="text" id="myInput" onkeyup="aa" placeholder="Search for player..." title="Type in a name">
<table id="myTable">
<tr class="header">
<th style="width:40%;">Player</th>
<th style="width:20%;">Clan</th>
<th style="width:20%;">Evidence</th>
<th style="width:20%;">Added to list</th>
<?php while($row=mysqli_fetch_array($results)) : ?>
<tr>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['clan']; ?></td>
<td><?php echo $row['rulebreak']; ?></td>
<td><?php echo $row['addlist']; ?></td>
</tr>
<?php endwhile ?>
</tr>
</table>
<tbody>
</body>
</html>
i hope we can find an answer together with friendship, emotions and friendship!
regards
I am creating a user interface for managing a database. Each entry has two radio buttons, one for validation (and subsequent emailing to concerned authorities) and one for deleting the entry. The code is given below, and the bold parts are the ones which concern this functionality.
A couple of questions:
1) Is it possible to do so without the form attribute? If so, how would I do it?
2) With the form attribute, I use 'handle.php' to delete each entry. The syntax in the 'handle.php' includes this line
$sql="DELETE FROM rti WHERE ID=x"; //x here is the ID number to delete.
Now, how do I pass the value of the ID as well from my interface, so that the above line of code deletes the entry corresponding to the button that was pressed?
<html>
<head>
<style>
* {
margin: 0px;
padding: 0px;
}
div.topbar {
position: relative;
background-color: black;
height: 45px;
text-align: center;
font-family: Calibri;
font-size: 30px;
padding-top: 10px;
}
div.topbar img {
position: absolute;
left: 10px;
top: 0px;
}
div.topbar span {
color: white;
}
div.container {
background-color: #a5a5a5;
width: 100%;
height: 100%;
color: white;
}
div.data {
padding: 20px;
}
table {
background-color: #b1b1b1;
border-collapse: collapse;
}
th, td {
text-align: center;
border: solid 1px black;
margin: 0px;
}
th.one {
width: 50px;
}
th.two{
width: 150px;
}
th.three {
width: 75px;
}
th.four {
width: 200px;
}
div.validation {
background-color: #b5b5b5;
width: 200px;
height: 100%;
position: relative;
left: 1100px;
bottom: 300%;
text-align: center;
border-left: solid 1px black;
}
</style>
</head>
<body>
<div class = "topbar"><img src="logo.png"><span>RTI DATABASE</span></div>
<div class = "container">
<div class ="data">
<?php
$servername="localhost";
$username="root";
$password='';
$conn=mysql_connect($servername, $username, $password) or die ("Error connecting to mysql server: ".mysql_error());
$dbname = 'bsp';
mysql_select_db($dbname, $conn) or die ("Error selecting specified database on mysql server: ".mysql_error());
$sql="SELECT * FROM rti";
$result=mysql_query($sql) or die ("Query to get data from firsttable failed: ".mysql_error());
echo "<table>";
echo "<tr>";
echo '<th class="one">ID</th>
<th class="two">Name</th>
<th class="three">Board</th>
<th class="four">Query</th>
<th class="five">Validate</th>
<th class="six">Delete</th>
<th class="seven">Submit</th>';
echo "</tr>";
while ($row=mysql_fetch_array($result)) {
$id=$row["ID"];
$name=$row["name"];
$board=$row["board"];
$query=$row["query"];
echo "<tr>";
echo "<td>$id</td>
<td>$name</td>
<td>$board</td>
<td>$query</td>
**<form action='handle.php' method='POST'>
<td><input type='radio' name='option' value='validate'></td>
<td><input type='radio' name='option' value='delete'></td>
<td><input type='submit' value='Submit' name='submit'>
</form></td>";
echo "</tr>";**
}
echo "</table><br>";
?>
</div>
</div>
</body>
</html>
**<form action='handle.php' method='POST'><td><input type='radio' name='option' value='validate'></td>
<td><input type='radio' name='option' value='delete'>
<input type='hidden' name="id" value='".$id."'>
</td>
<td><input type='submit' value='Submit' name='submit'></form></td>";
In handle.php:
$id = $_POST['id'];
inside your form add an hidden type input with the id value for each item , so each time user click the button the id sent. just like this :
<form action='handle.php' method='POST'><td><input type='radio' name='option' value='validate'></td>
<input type = 'hidden' name="id" value='".$row['id']."'><td>
<input type='radio' name='option' value='delete'></td>
<td><input type='submit' value='Submit' name='submit'></form></td>";
use something like <input type='radio' name='option[your_id]' value='validate'> to identify the item.
Like: <input type='radio' name='option[$id]' value='validate'>
have tried uploading .avi video formats but the page just refreshes and the file is not uploaded all other types type images and everything is getting uploaded im posting my code here look for file uploding sections with cwf and ve
<?php
$n=5;
$exp_no="";
$shot_no="";
$file_name1="";
$file_name2="";
$remarks="";
$cwf="";
$vedio="";
$conn=mysqli_connect("localhost","root","","project");
if(!$conn){
die("connection failed");
echo "<br/>";
}
$query="select stage from experimentdetails where NO='{$exp_no}'";
$res=mysqli_query($conn,$query);
if(mysqli_num_rows($res)>0){
$r=mysqli_fetch_row($res);
$n=$r[0];
}
session_start();
$exp_no=$_SESSION["expno_add"];
$s=mysqli_query($conn,"select ShotNo from shotdetails where ExpNo='{$exp_no}'");
$res=mysqli_fetch_row($s);
$shot_no=$res[0];
if(isset($_POST["submit"]))
{
$remarks=$_POST["remarks"];
$cap=array(8);
$off=array(8);
$cv=array(8);
$cptp=array(8);
$pul=array(8);
$del=array(8);
$vel=array(8);
for($i=0;$i<8;$i++)
{
if($i<$n)
{
$j=$i+1;
$cap[$i]=$_POST["cv{$j}"];
$off[$i]=$_POST["off{$j}"];
$cv[$i]=$_POST["cc{$j}"];
$cptp[$i]=$_POST["cpt{$j}"];
$pul[$i]=$_POST["pw{$j}"];
$del[$i]=$_POST["del{$j}"];
$vel[$i]= $_POST["vel{$j}"];
}
else{
$cap[$i]=0;
$off[$i]=0;
$cv[$i]=0;
$cptp[$i]=0;
$pul[$i]=0;
$del[$i]=0;
$vel[$i]=0;
}
}
if($_FILES['cwf']['name']!="")
{
$fname=$_FILES["cwf"];
$uploaddir = 'cwf/';
if (is_uploaded_file($fname['tmp_name']))
{
$filname = basename($fname['name']);
$uploadfile = $uploaddir . basename($fname['name']);
if (move_uploaded_file ($fname['tmp_name'], $uploadfile))
$r = "File " . $filname . " was successfully uploaded and stored.<br>";
else
$r = "Could not move ".$fname['tmp_name']." to ".$uploadfile."<br>";
}
else
$r = "File ".$fname['name']." failed to upload.";
$file_name1='cwf/'.$file_name1;
}
if($_FILES['ve']['name']!="")
{
$fname=$_FILES["ve"];
$uploaddir = 'upload/';
if (is_uploaded_file($fname['tmp_name']))
{
$filname = basename($fname['name']);
$uploadfile = $uploaddir . basename($fname['name']);
if (move_uploaded_file ($fname['tmp_name'], $uploadfile))
$r = "File " . $filname . " was successfully uploaded and stored.<br>";
else
$r = "Could not move ".$fname['tmp_name']." to ".$uploadfile."<br>";
}
else
$r = "File ".$fname['name']." failed to upload.";
$file_name2='upload/'.$file_name2;
}
$query="insert into shotdetails values($shot_no,$cap[0],$cap[1],$cap[2],$cap[3],$cap[4],$cap[5],$cap[6],$cap[7],$off[0],$off[1],$off[2],$off[3],$off[4],$off[5],$off[6],$off[7],$cptp[0],$cptp[1],$cptp[2],$cptp[3],$cptp[4],$cptp[5],$cptp[6],$cptp[7],$pul[0],$pul[1],$pul[2],$pul[3],$pul[4],$pul[5],$pul[6],$pul[7],$del[0],$del[1],$del[2],$del[3],$del[4],$del[5],$del[6],$del[7],$vel[0],$vel[1],$vel[2],$vel[3],$vel[4],$vel[5],$vel[6],$vel[7],$file_name1,$file_name2,$remarks,$exp_no,$cv[0],$cv[1],$cv[2],$cv[3],$cv[4],$cv[5],$cv[6],$cv[7])";
mysqli_query($conn,$query);
}
mysqli_close($conn);
?>
<html>
<head>
<title>ADD Shot</title>
<style>
select {
padding:3px;
margin: 0;
-webkit-border-radius:4px;
-moz-border-radius:4px;
border-radius:4px;
-webkit-box-shadow: 0 3px 0 #ccc, 0 -1px #fff inset;
-moz-box-shadow: 0 3px 0 #ccc, 0 -1px #fff inset;
box-shadow: 0 3px 0 #ccc, 0 -1px #fff inset;
background: #f8f8f8;
color:#888;
border:none;
outline:none;
display: inline-block;
-webkit-appearance:none;
-moz-appearance:none;
appearance:none;
cursor:pointer;
}
/* Targetting Webkit browsers only. FF will show the dropdown arrow with so much padding. */
#media screen and (-webkit-min-device-pixel-ratio:0) {
select {padding-right:18px}
}
label {position:relative}
label:after {
content:'<>';
font:11px "Consolas", monospace;
color:#aaa;
-webkit-transform:rotate(90deg);
-moz-transform:rotate(90deg);
-ms-transform:rotate(90deg);
transform:rotate(90deg);
right:8px; top:2px;
padding:0 0 2px;
border-bottom:1px solid #ddd;
position:absolute;
pointer-events:none;
}
label:before {
content:'';
right:6px; top:0px;
width:20px; height:20px;
background:#f8f8f8;
position:absolute;
pointer-events:none;
display:block;
}
.c ul li {
margin-top: 11px;
margin-right: 6px;
padding: 0px;
display: inline-block;
font-family: open-sans, Araial, Helvetica, sans-serif;
font-size:14px;
}
.c li a {
margin-left: 10px;
color:black;
padding-right: 20px;
text-decoration: none;
}
.c{
margin-left: 20px;
border-right: 1px solid rgba(1,1,1,0.20);
border-left: 1px solid rgba(1,1,1,0.20);
border-radius:5px;
width:98%;
margin-top: 10px;
}
#nav {
height: 40px;
border-radius:3px;
background-color: #f2f2f2;
border-bottom: 1px solid #ccc;
border-top: 1px solid #ccc;
}
</style>
</head>
<body>
<div class="c">
<ul id="nav">
<li style="border-right:1px solid rgba(1,1,1,0.65);">
Add Experiment
</li>
<li style="border-right:1px solid rgba(1,1,1,0.65);">
Modify Experiment
</li>
<li style="border-right:1px solid rgba(1,1,1,0.65);">
Delete Experiment
</li>
<li style="border-right:1px solid rgba(1,1,1,0.65);">
Create New Shot
</li>
<li style="border-right:1px solid rgba(1,1,1,0.65);">
Delete Shot
</li>
<li style="border-right:1px solid rgba(1,1,1,0.65);">
Add Component
</li>
<li style="border-right:1px solid rgba(1,1,1,0.65);">
Modify Component
</li>
<li style="border-right:1px solid rgba(1,1,1,0.65);">
Delete Component
</li>
</ul>
</div>
<center style="margin-top:5%">
<form action="add_shot1.php" method="POST" name="add" enctype="multipart/form-data">
<table cellspacing="4" cellpadding="4" class="cap">
<tr>
<th>Stage No.</th>
<th>Charging Voltage(kV)</th>
<th>Offset(mm)</th>
<th>Coil Current(kA)</th>
<th>Current Pulse Time period(ms)</th>
<th>Pulse Width(ms)</th>
<th>Delay(ms)</th>
<th>Velocity</th>
</tr>
<?php
for ($x = 1; $x <= $n; $x++) {
echo "<tr>";
echo "<td align='center'>" . $x . "</td>";
echo "<td align='center' ><input type='number' class='text' name='cv{$x}' value='' style=' height:30px;'/></td>";
echo "<td align='center'><input type='number' class='text' name='off{$x}' value=''style=' height:30px;'/></td>";
echo "<td align='center' ><input type='number' class='text' name='cc{$x}' value=''style=' height:30px;'/></td>";
echo "<td align='center' ><input type='number' class='text' name='cpt{$x}' value=''style=' height:30px;'/></td>";
echo "<td align='center' ><input type='number' class='text' name='pw{$x}' value=''style=' height:30px;'/></td>";
echo "<td align='center' ><input type='number' class='text' name='del{$x}' value=''style=' height:30px;'/></td>";
echo "<td align='center' ><input type='number' class='text' name='vel{$x}' value=''style=' height:30px;'/></td>";
echo"</tr>";
}
?>
<tr>
<td colspan='4'> Current wave form file:   <input type='file' name='cwf' value='' class='text'/> </td>
</tr>
<tr >
<td colspan='4' >Video File: <input type='file' name='ve' value='' class='text'/></td>
<td></td>
<td></td>
</tr>
<tr>
<td>Remarks</td>
<td><textarea rows="10" cols="40" name="remarks" value=""></textarea></td>
</tr>
<tr>
<td colspan=4 align='center'><input type="submit" name="submit" value="submit" /></td>
</tr>
</table>
</form>
</center>
</body>
</html>
Having a problem in IE with CSS nowrap in IE, works perfectly in Chrome. Can anyone help out so it renders without any wrapping in IE and Chrome?
HTML
<div id="sub_cont"></div>
CSS
#content{
height:14px;
text-align: left;
text-decoration: none;
width: 450px;
padding-top:25px;
white-space: nowrap;
}
#content #sub_cont{
width: 450px;
display:none;
height:14px;
}
#content .no-rec{
color:#000;
font-family:Arial, Helvetica, sans-serif;
font-size:14px;
padding:5px;
border-bottom:solid #000;
text-align:left;
background:#EBEBEB;
}
#content .each_rec {
background: none repeat scroll 0 0 #EBEBEB;
border-bottom: medium solid #000000;
color: #000;
font-family: Arial,Helvetica,sans-serif;
font-size: 14px;
padding: 5px;
height:12px;
}
PHP
<?php
echo "<h2>Search Result</h2>";
echo "<table border='0' id='content' cellspacing='2' cellpadding='5'>
<tr bgcolor='#FFFFCC'>
<th>VM Name</th>
<th>vCenter Name</th>
</tr>";
while ($row = sqlsrv_fetch_array($result))
{
echo "<tr class='each_rec'>";
echo "<td>" . $row['VM_NAME'] . "</td>";
echo "<td>" . $row['VCENTER_NAME'] . "</td>";
echo "</tr>";
}
echo "</table>";
if($total==0){ echo '<div class="no-rec">No Record Found !</div>';}?>
In internet explorer we must use the whiteSpace property in order to nowrap text, the documentation for the usage of whiteSpace is linked below. Good luck, and remember to use the most recent version of IE in order to maintain accuracy.
Link: http://msdn.microsoft.com/en-us/library/ie/ms531182(v=vs.85).aspx
Reference url
https://stackoverflow.com/a/18129006/1312610
http://css-tricks.com/almanac/properties/w/whitespace/
Try it for ie
white-space: normal;