I am having two php files, one contains a form and another to display the content entered and save button. After confirming the details are correct he has to save and the data should be inserted into the table. I have given the code below
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js">
</script>
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.1.1.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"> </script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"> </script>
</head>
<body>
<?php
$roll=$_POST['roll'];
$sname=$_POST['sname'];
$fname=$_POST['fname'];
$gender=$_POST['gender'];
$aadhar=$_POST['aadhar'];
$caste=$_POST['caste'];
?>
<div class="container container-center">
<!-------------total panel------------------------------------>
<div class="panel-info">
<!------panel heading------>
<div class="panel-heading">
<h2><center><u>STUDENT DETAILS</u></center></h2>
</div> <!-panel heading->
<div class="panel-body">
<form method="post" action="">
<table align="center" border="0">
<tbody>
<tr>
<td rowspan="7"><?php echo"<img src=/photo/$roll.jpg width='200px' height='300px' id='photo'>"; ?></td>
<td>1. Roll Number & Photo:</td>
<td><?php echo"".strtoupper($roll).""; ?></td>
</tr>
<tr>
<td>2. Name of the Student:</td>
<td><?php echo"".strtoupper($sname).""; ?></td>
</tr>
<tr>
<td>3. Name of the Father:</td>
<td><?php echo"".strtoupper($fname).""; ?></td>
</tr>
<tr>
<td>4. Gender:</td>
<td><?php
if($gender=='M')
{ echo"Male";}
else
{echo"Female";}
?></td>
</tr>
<tr>
<td>5. Aadhar Number:</td>
<td><?php echo"$aadhar"; ?></td>
</tr>
<tr>
<td>6. Caste:</td>
<td><?php echo"$caste"; ?></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" id="submit" name="submit" class="btn btn-info" value="save"></td>
</tr>
</tbody>
</table>
</form>
</div>
</div>
</div>
<?php
if(isset($_POST['submit']))
{
echo"<script>alert('success')</script>";
}
?>
</body>
when i click the save button then only the data must be saved. but even if not click the save the php code in isset is executing.
the data obtained by $_POST is from the form.
Please help me.
NOTE:
Actually Problem is that, you don't get the data on this page.. in your POST request with given variable so that Please Just Check it . Other Code Is Fine. !! ( Here I am Just Pass Dummy Data ) Like Below.
$roll= '1234';
$sname='XYZ';
$fname= 'ABC';
$gender= 'M';
$aadhar= '123456789100';
$caste= 'A12345';
Solution: You Have To Get DATA Here in post request from your first_php_page form where user enter the details regarding given fields: roll,sname,fname,gender,aadhar,caste
After here in secound_php_page check that Submit button is set then store the values in varable Like below Code:
NOTE: At The End YoU Have To Write The Insert Query On Save Button Click. To Store The data in Database.
<?php
if(isset($_POST['Submit'])){
$roll=$_POST['roll'];
$sname=$_POST['sname'];
$fname=$_POST['fname'];
$gender=$_POST['gender'];
$aadhar=$_POST['aadhar'];
$caste=$_POST['caste'];
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js">
</script>
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.1.1.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"> </script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"> </script>
</head>
<body>
<?php
/*
$roll=$_POST['roll'];
$sname=$_POST['sname'];
$fname=$_POST['fname'];
$gender=$_POST['gender'];
$aadhar=$_POST['aadhar'];
$caste=$_POST['caste'];
*/
// SET THE DUMMY DATA FOR Result check
$roll= '1234';
$sname='XYZ';
$fname= 'ABC';
$gender= 'M';
$aadhar= '123456789100';
$caste= 'A12345';
?>
<div class="container container-center">
<!-- total panel -->
<div class="panel-info">
<!-- panel heading -->
<div class="panel-heading">
<h2><center><u>STUDENT DETAILS</u></center></h2>
</div>
<!--panel heading -->
<div class="panel-body">
<form method="post" action="">
<table align="center" border="0">
<tbody>
<tr>
<td rowspan="7"><?php echo"<img src=/photo/$roll.jpg width='200px' height='300px' id='photo'>"; ?></td>
<td>1. Roll Number & Photo:</td>
<td><?php echo"".strtoupper($roll).""; ?></td>
</tr>
<tr>
<td>2. Name of the Student:</td>
<td><?php echo"".strtoupper($sname).""; ?></td>
</tr>
<tr>
<td>3. Name of the Father:</td>
<td><?php echo"".strtoupper($fname).""; ?></td>
</tr>
<tr>
<td>4. Gender:</td>
<td><?php
if($gender=='M')
{ echo"Male";}
else
{echo"Female";}
?></td>
</tr>
<tr>
<td>5. Aadhar Number:</td>
<td><?php echo"$aadhar"; ?></td>
</tr>
<tr>
<td>6. Caste:</td>
<td><?php echo"$caste"; ?></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" id="submit" name="submit" class="btn btn-info" value="save"></td>
</tr>
</tbody>
</table>
</form>
</div>
</div>
</div>
<?php
if(isset($_POST['submit']))
{
echo"<script>alert('success')</script>";
}
?>
</body>
</HTML>
OUTPUT: DATA Display
AND ONCLICK SAVE
There are few issues with your code, such as:
There's no point having a form and save button(in another page) if you don't have input elements and don't send your data using $_POST superglobal. Create input elements for each of your fields with type="hidden", for example like this:
<td><?php echo strtoupper($roll); ?><input type="hidden" name="roll" value="<?php echo strtoupper($roll); ?>"></td>
Here's the full form code,
// your code
<form method="post" action="">
<table align="center" border="0">
<tbody>
<tr>
<td rowspan="7"><?php echo"<img src=/photo/$roll.jpg width='200px' height='300px' id='photo'>"; ?></td>
<td>1. Roll Number & Photo:</td>
<td><?php echo strtoupper($roll); ?><input type="hidden" name="roll" value="<?php echo strtoupper($roll); ?>"></td>
</tr>
<tr>
<td>2. Name of the Student:</td>
<td><?php echo strtoupper($sname); ?><input type="hidden" name="sname" value="<?php echo strtoupper($sname); ?>"></td>
</tr>
<tr>
<td>3. Name of the Father:</td>
<td><?php echo strtoupper($fname); ?><input type="hidden" name="fname" value="<?php echo strtoupper($fname); ?>"></td>
</tr>
<tr>
<td>4. Gender:</td>
<td>
<?php
if($gender=='M'){
echo"Male";
}else{
echo"Female";
}
?>
<input type="hidden" name="gender" value="<?php echo $gender; ?>">
</td>
</tr>
<tr>
<td>5. Aadhar Number:</td>
<td><?php echo $aadhar; ?><input type="hidden" name="aadhar" value="<?php echo $aadhar; ?>"></td>
</tr>
<tr>
<td>6. Caste:</td>
<td><?php echo $caste; ?><input type="hidden" name="caste" value="<?php echo $caste; ?>"></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" id="submit" name="submit" class="btn btn-info" value="save"></td>
</tr>
</tbody>
</table>
</form>
// your code
I don't see any code where you're inserting the form data into the table, you should have a code block like this in another page(where you have displayed the form data and has the save button):
if(isset($_POST['submit'])){
$roll = $_POST['roll'];
$sname = $_POST['sname'];
$fname = $_POST['fname'];
$gender = $_POST['gender'];
$aadhar = $_POST['aadhar'];
$caste = $_POST['caste'];
// your INSERT operation
}
Related
I am making the modification for the query and already add and everything but in modifying it does not work with 'id' that I put after putting the address of the modification page
this is the table
<!DOCTYPE html>
<html>
<head>
<title> TABLA </title>
</head>
<body>
<center>
<table bgcolor="#85C1E9" border="3">
<thead>
<tr>
<th colspan="1">Nuevo</th>
<th colspan="5">Lista de usuarios</th>
</tr>
</thead>
<tbody>
<tr>
<td>Id</td>
<td>Nombre</td>
<td>Apellido</td>
<td>Correo</td>
<td colspan="2"><center>Operaciones</center></td>
</tr>
<?php
include("conexiones.php");
$query="SELECT * FROM usuarios";
$resultado=$conexion->query($query);
while ($row=$resultado->fetch_assoc()) {
?>
<tr>
<td><?php echo $row['id'];?></td>
<td><?php echo $row['nombre'];?></td>
<td><?php echo $row['apellido'];?></td>
<td><?php echo $row['correo'];?></td>
<td><a href="modificar.php?id=<?php echo $row['id'];
?>">Modificar</a></td>
<td><a href="eliminar.php?id=<?php echo $row['id']; ?
>">Eliminar</a></td>
</tr>
<?php
}
?>
</tbody>
</table>
</center>
</body>
</html>
here the modify page
<!DOCTYPE html>
<html>
<head>
<title>Guardar</title>
</head>
<body>
<center>
<form action="guardar.php" method="POST" name="guardar"><br><br><br>
<?php
$id=$_REQUEST['id'];
include("conexiones.php");
$query="SELECT * FROM usuarios";
$resultado=$conexion->query($query);
$row=$resultado->fetch_assoc();
?>
<input type="text" required="" name="nombre" placeholder="Nombre..."
value="<?php echo $row['nombre'];?>"><br><br>
<input type="text" required="" name="apellido"
placeholder="Apellido..." value="<?php echo $row['apellido'];?>">
<br><br>
<input type="text" required="" name="correo"
placeholder="Correo..." value="<?php echo $row['correo'];?>"><br>
<br>
<input type="submit" value="Aceptar">
</form>
</center>
</body>
</html>
the error is that when I press modify in the query I get like this:
http://localhost/modificar.php?id=%3C?echo%20$row[%27id%27];?%3E
and the way it should go (for example) is like this:
http://localhost/modificar.php?id=1
Try this:
<?php
include("conexiones.php");
$query="SELECT * FROM usuarios";
$resultado=$conexion->query($query);
?>
<?php while ($row=$resultado->fetch_assoc()): ?>
<tr>
<td><?= $row['id'] ?></td>
<td><?= $row['nombre'] ?></td>
<td><?= $row['apellido'] ?></td>
<td><?= $row['correo'] ?></td>
<td><a href="modificar.php?id=<?= $row['id'] ?>">
Modificar</a></td>
<td><a href="eliminar.php?id=<?= $row['id'] ?>">
Eliminar</a></td>
</tr>
<?php endwhile; ?>
hope it helps.
Ive been working on this issue for some time now, basically, i have a table and at the end of row is a button that submits that rows batchID and Priority value to my .php that handles post requests. the problem comes when i hit submit it takes the batchID column from the last row regardless of which button is pressed. i have this exact same code running on another site which works as intended. when i inspect the network data being sent it shows that all the data in column batchID is being sent to upload.php, but i only need the corresponding batchID to be sent.
<?php
$con = mysqli_connect("localhost", "root", "", "production_management");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
require('databaseDetails.php');
session_start();
$userNameTmp = $_SESSION["usrName"];
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Received Request Form</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<p><button class="button button2">Dashboard</button><p>
<form name="form" method="post" action="upload.php">
<div class="form">
<h1>Batch's</h1>
<p>Hello <?php echo $userNameTmp;?> </p>
<table class="responsive-table" width="100%" border="1" style="border-
collapse:collapse;">
<thead>
<tr>
<th><strong>Started By</strong></th>
<th><strong>Batch Type</strong></th>
<th><strong>Date</strong></th>
<th><strong>Batch ID</strong></th>
<th><strong>Quantity</strong></th>
<th><strong>Progress</strong></th>
<th><strong>Priority</strong></th>
</tr>
</thead>
<tbody>
<?php
$query = "SELECT * FROM batch";
$result = mysqli_query($con,$query);
while($row = mysqli_fetch_assoc($result)) { ?>
<td align="center"><?php echo $row["startedBy"]; ?></td>
<td align="center"><?php echo $row["batchType"]; ?></td>
<td align="center"><?php echo $row["date"]; ?></td>
<td align="center"><?php echo $row["batchID"]; ?></td>
<td align="center"><?php echo $row["quantity"]; ?></td>
<td align="center"><?php echo $row["progress"]; ?></td>
<td align="center"><?php echo $row["priority"]; ?></td>
<td align="center"><input type="hidden" name="postMethod" value="3"></td>
<td align="center"><input type="hidden" name="batchID" value="<?php echo
$row["batchID"]; ?>"></td>
<td align="center"><input type="submit" value="test"></td></tr>
<?php
}
?>
</tbody>
</table>
</div>
</form>
</body>
</html>
I make Jquery to read data from db and when I click the list it shown roe data on detail box.
But.... problem: I make div where I show content. I load page with Jquery to div.
but when I do this the row click dont work. I can not understan why. It is shild element but id i understan right when I use getElementById it should to take current row, but no.
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<?php include './config/init.php'; ?>
<html>
<head>
<meta charset="UTF-8">
<title>Biisilista</title>
<script src="./js/jquery-3.2.1.js"></script>
<link href="css/basic.css" rel="stylesheet" type="text/css">
</head>
<body>
<h1>KaraokeBiisit </h1>
<div id="edit" style="display:none">
<div>
<form name="formedit" method="post" action="">
<table id="edittable" border="1" cellspacing="2" cellpadding="1">
<tbody>
<tr>
<td>
<label>Nimi:</label>
</td>
<td>
<input id="nimi" name="nimi" placeholder="Kappaleen nimi" type="text">
</td>
<td>
<label>Levy:</label>
</td>
<td>
<input id="levy" name="levy" placeholder="Levyn tunnus" type="text" width="10px">
</td>
</tr>
<tr>
<td>
<label>Artisti:</label>
</td>
<td>
<input id="artisti" name="artisti" placeholder="Kappaleen esittäjä" type="text">
</td>
<td>
<label>Kieli:</label>
</td>
<td>
<input id="kieli" name="kieli" placeholder="Alkuperäiskieli" type="text" width="20">
</td>
</tr>
<tr>
<td>
<label>Numero:</label>
</td>
<td>
<input id="numero" name="numeron" placeholder="Numero" type="text">
</td>
</tr>
</tbody>
</table>
</form>
</div>
</div>
<div id="pageContent">
</div>
<script src="./js/jquery-3.2.1.js"></script>
<script src="./js/script.js"></script>
</body>
</html>
jQuery(document).ready(function ($) {
$("#pageContent").click(function () {
$('tr').removeClass('selected');
$(this).addClass('selected');
var selectedRow;
selectedRow = $(rivi);
var td = $(selectedRow).children('td');
$('#nimi').val(td[0].innerText);
$('#artisti').val(td[1].innerText);
$('#levy').val(td[2].innerText);
$('#kieli').val(td[3].innerText);
$('#numero').val(td[4].innerText);
console.log("test");
});
$(".clickable-row").on('click', () => {
$('#edit').show();
});
$('#pageContent').load('container.php');
// $('#pageContent').load('biisit.php');
});
function showBiisit() {
console.log("Näytetään sisältö");
$('#pageContent').load('container.php');
}
<?php include './config/init.php'; ?>
<?php
//luodaan tietokantaobjekti
$db = new DataBase();
// tehdään kysely
$db->query("SELECT * FROM kappaleet");
//query("SELECT `id`,`nimi`,`artisti`,`levy`,`kieli`,`numero` FROM `kappaleet`;");
//yhdistetään hakutulokseen
$kappaleet = $db->resultset();
?>
<table id="dataTable">
<tr>
<th>Nimi</th>
<th>Artisti</th>
<th width="100" align="left">Levy</th>
<th width="100" align="left">Kieli</th>
<th width="100" align="left">Numero</th>
</tr>
<?php foreach ($kappaleet as $biisi): ?>
<tr class='clickable-row' >
<td><?php echo $biisi->nimi ?></td>
<td><?php echo $biisi->artisti ?></td>
<td><?php echo $biisi->levy ?></td>
<td><?php echo $biisi->kieli ?></td>
<td><?php echo $biisi->numero ?></td>
</tr>
<?php endforeach; ?>
</table>
try this
...
$("body").on('click', '.clickable-row', function () { //i change this line
$('tr').removeClass('selected');
$(this).addClass('selected');
var selectedRow = $(this);
//selectedRow = $(rivi); idk what is this
var td = selectedRow.children('td');
$('#nimi').val(td[0].innerText);
$('#artisti').val(td[1].innerText);
$('#levy').val(td[2].innerText);
$('#kieli').val(td[3].innerText);
$('#numero').val(td[4].innerText);
console.log("test");
});
...
Hye there, can i ask some question. I want to update data in my database i using a id that had been set in my database. The data can be update, but i want in the update page. Information in database been view first than i can delete and change for the new input. The coding right here. Can you give me idea how to do it.
<?php
require "cn.php";
$query=mysql_query("select*from medicine");
$num=1;
?>
<!DOCTYPE HTML>
<head>
<style>
body
{
background:url("pharmacy.jpg");
background-size:2000px 1100px;
background-repeat:no repeat;
padding-top:40px;
}
</style>
<title>View Stock</title>
</head>
<table align="center" width="800" border="5" bgcolor="white" bordercolor="red">
<tr>
<td><div align="center"><a href="mainpage.php" >HOME</div></a></td>
<td><div align="center">STOCK</div></td>
<td><div align="center">REPORT</div></td>
<td><div align="center">UPDATE INFORMATION</div></td>
</tr>
</table>
<br>
<br>
<br>
<br>
<div align="middle">
<table border="5" bgcolor="white" bordercolor="red">
<tr align="middle">
<td>No</td>
<td>Code</td>
<td>Medicine</td>
<td>Stock</td>
<td>Price</td>
<td colspan="2">action</td>
</tr>
<?php
while($fetch=mysql_fetch_object($query))
{
?>
<tr>
<td><?php echo $num;?></td>
<td> <?php echo $fetch->code;?></td>
<td><?php echo $fetch->medicine;?></td>
<td><?php echo $fetch->stock;?></td>
<td><?php echo $fetch->price;?></td>
<td>update</td>
<td>delete</td>
</tr>
<?php
$num++;
}
?>
</div>
</table>
</html>
Update.php coding
<?php
if(isset($_GET['id']))
$id=$_GET['id'];
?>
<!DOCTYPE HTML>
<head>
<title>Update stock</title>
<style>
body
{
background:url("pharmacy.jpg");
background-size:2000px 1100px;
background-repeat:no repeat;
padding-top:40px;
}
</style>
</head>
<form Action="updateh.php" method="post">
<table align="center" width="800" border="5" bgcolor="white" bordercolor="red">
<div align="center"><h2>Enter New Update</h2></div>
<tr>
<td align="center" colspan=4>Name</td>
</tr>
<br>
<div align="right">
<font color="white">Back to Stock Update</font><br>
</div>
<tr>
<td><div align="center">Code</div></td>
<td><div align="center">Medicine</div></td>
<td><div align="center">Stock</div></td>
<td><div align="center">Price(RM)</div></td>
</tr>
<tr>
<td><div align="middle"><input type="textbox" name="code" required></div></td>
<td><div align="middle"><input type="textbox" name="medicine" required></div></td>
<td><div align="middle"><input type="textbox" name="stock" required></div></td>
<td><div align="middle"><input type="textbox" name="price" required></div></td>
</tr>
<tr>
<td align="middle" colspan=4><input type="submit" value="update">
<input type="hidden" name="id" value="<?php echo $id;?>">
</td>
</tr>
</table>
</Form>
</html>
updateh.php coding
<?php
session_start();
require "cn.php";
$id=$_POST['id'];
$code=$_POST['code'];
$medicine=$_POST['medicine'];
$stock=$_POST['stock'];
$price=$_POST['price'];
mysql_query("update medicine set code='$code', medicine='$medicine', stock='$stock',
price='$price' where id='$id'");
echo header("location: sucess2.php");
?>
if(isset($_POST['submit'])) {
$code= $_POST['code'];
$medicine= $_POST['medicine'];
$stock= $_POST['stock'];
$price= $_POST['price'];
$sql= mysql_query(UPDATE `your_table` SET `code`,`medicine`,`stock`,`price`) VALUES ('$code','$medicine','stock','$price') WHERE `id`='$id';
}
Use this and then read and use mysqli instead of mysql
I just made a PHP script to retrieve entry from database. When I retrieve entry from a table, the page look like this. The header and form below table is repeated. I need help, thanks.
Here's the whole code I'm using:
<?php
session_start();
include('connection.php');
$username='username';
mysql_query("SELECT * FROM regmember WHERE username='$username'");
$query=("SELECT * FROM product");
$result=mysql_query($query);
while($row=mysql_fetch_array($result))
{
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="index.css">
<title>Music Light</title>
<div align="center"><h1>Music Light</h1></div>
<div id="menu">
<ul>
<li><?php echo 'Welcome, '.$_SESSION['username']; ?></li>
<li>Home</li>
<li>Product</li>
<li>Profile</li>
<li>Cart</li>
<li>Testimony</li>
<li>Transaction</li>
<li>Logout</li>
</ul>
</div>
<br>
<br>
<div align="center">
<table border="0">
<tr>
<td>ID</td>
<td></td>
<td><?php echo $row[0];?></td>
</tr>
<tr>
<td>Brand</td>
<td></td>
<td><?php echo $row[1];?></td>
</tr>
<tr>
<td>Instrument Type</td>
<td></td>
<td><?php echo $row[2];?></td>
</tr>
<tr>
<td>Price</td>
<td></td>
<td><?php echo $row[3];?></td>
</tr>
<tr>
<td>Stock</td>
<td></td>
<td><?php echo $row[4];?></td>
</tr>
<tr>
<td>Image</td>
<td></td>
<td><img height="150" width="150" src="productimg/<?php echo $row[6];?>"/></td>
</table>
</div>
<div align="center">
<table>
<form name="deleteentry" action="delete.php" method="get">
<tr>
<td>Delete which entry? (enter product id)</td>
<td><input type="text" name="delete"></td>
<td><input type="button" name="deletebutton" value="Delete"></td>
</tr>
</form>
</table>
</div>
<?php
}
?>
<br>
<br>
<div align="center"><p>Description template</p></div>
<footer>
<p align="center">Copyright © 2013 Music Light</p>
</footer>
missing </head> and <body> and </body>
i would suggest that the <html> <head></head> and <body> to be used outside the loop if u donot actually want to repeat. by loop i mean the while loop
You didn't closed your header with </head>
<head>
<link rel="stylesheet" type="text/css" href="index.css">
<title>Music Light</title>
</head> <= Include this
.
.
.
</html> <= Include this as well at the end