I want edit record in db table but it doesn't save in db table and nothing changed after i submit this form.
Here codes that i forgot to put.
<?php
require('db.php');
include("auth.php"); //include auth.php file on all secure pages
$id_doc=$_REQUEST['id_doc'];
$query = "SELECT * from doc where id_doc='".$id_doc."'";
$result = mysqli_query($connection, $query) or die ( mysqli_error());
$row = mysqli_fetch_assoc($result);
?>
This is my php codes
<?php
if(isset($_POST['new']) && $_POST['new']==1)
{
$id_doc=$_REQUEST['id_doc'];
$query = "SELECT * from doc where id_doc='".$id_doc."'";
$result = mysqli_query($connection, $query) or die ( mysqli_error());
$row = mysqli_fetch_assoc($result);
$title =$_REQUEST['title'];
$date = $_REQUEST['date'];
$from_to = $_REQUEST['from_to'];
$details = $_REQUEST['details'];
$d_location = $_REQUEST['d_location'];
$d_stat = $_REQUEST['d_stat'];
$update="update doc set title='".$title."', date='".$date."', from_to='".$from_to."', details='".$details."', d_location='".$d_location."', d_stat='".$d_stat."' where id_doc='".$id_doc."'";
mysqli_query($connection, $update) or die(mysql_error());
$status = "File Record Updated Successfully. </br></br><a href='v_doc.php'>View Updated Record</a>";
echo '<p style="color:#FF0000;">'.$status.'</p>';
}else {
// here some else code
}
?>
Not an answer. Too long for a comment.
The issue of parametrised queries aside, I find this easier to read:
UPDATE doc
SET title = '$title'
, date = '$date'
, from_to = '$from_to'
, details = '$details'
, d_location = '$d_location'
, d_stat = '$d_stat'
WHERE id_doc = '$id_doc'
And now see about parametrised queries
Try below:
<?php
if(isset($_POST['new']) && $_POST['new']==1)
{
$id_doc=$_REQUEST['id_doc'];
$query = "SELECT * from doc where id_doc='".$id_doc."'";
$result = mysqli_query($connection, $query) or die ( mysqli_error());
$row = mysqli_fetch_assoc($result);
$title =$_REQUEST['title'];
$date = $_REQUEST['date'];
$from_to = $_REQUEST['from_to'];
$details = $_REQUEST['details'];
$d_location = $_REQUEST['d_location'];
$d_stat = $_REQUEST['d_stat'];
$update="update doc set title='".$title."', date='".$date."', from_to='".$from_to."', details='".$details."', d_location='".$d_location."', d_stat='".$d_stat."' where id_doc='".$id_doc."'";
if(mysqli_query($connection, $update)) {
$status = "File Record Updated Successfully. </br></br><a href='v_doc.php'>View Updated Record</a>";
} else {
die(mysqli_error($connection));
}
echo '<p style="color:#FF0000;">'.$status.'</p>';
} else {
// here some else code
}
?>
This should show you exact error, once you get it. show it here, so we can check and do correction.
Related
I try to run multiple queries inside while loop, and nothing happens, not showing error and not showing success. anyone can explain or help me solve this?
here's my code
<?php
include('config.php');
$sql = 'SELECT * FROM inventory_masuk_dummy';
$query = mysqli_query($conn, $sql);
while($row = mysqli_fetch_array($query)) {
$jumlah = $row['jml'];
$size = $row['size'];
$nama_barang = $row['nama_barang'];
$status = $row['status'];
$sql2 = "UPDATE inventory_dummy SET jumlah = jumlah+$jumlah WHERE nama_barang = '$nama_barang' AND size = '$size'";
$sql3 = "UPDATE inventory_masuk_dummy SET status = '2' WHERE status='1'";
while($row = mysqli_fetch_array($sql2) && $row = mysqli_fetch_array($sql3)) {
echo "Berhasil di ubah, anda akan segera dialihkan";
}
}
echo "Nothing...";
?>
The problem is your code does not execute the $sql2 and $sql3, you can execute it again with mysqli_query
<?php
include('config.php');
$sql = 'SELECT * FROM inventory_masuk_dummy';
$query = mysqli_query($conn, $sql);
while($row = mysqli_fetch_array($query)) {
$jumlah = $row['jml'];
$size = $row['size'];
$nama_barang = $row['nama_barang'];
$status = $row['status'];
$sql2 = "UPDATE inventory_dummy SET jumlah = jumlah+$jumlah WHERE nama_barang = '$nama_barang' AND size = '$size'";
$sql3 = "UPDATE inventory_masuk_dummy SET status = '2' WHERE status='1'";
if ( mysqli_query($conn, $sql2) && mysqli_query($conn, $sql3) ) {
echo "Berhasil di ubah, anda akan segera dialihkan";
}
}
echo "Nothing...";
i have two button on my homepage one is time-in and the other is time-out,
i want to prevent the user/student to time-in using same id if he did not put time-out on his last time-in to create valid entry. Hope you can help me.
here is my php code:
<?php
include_once('connection.php');
if(isset($_POST['submit0'])){
$rfid = $_POST['rfid'];
$time=date("H:i:s");
$sql = mysqli_query($conn, "SELECT * FROM stud WHERE rfid_num = '$rfid'");
$count = mysqli_num_rows($sql);
if ($count == 0 ) {
header("location:notexist.php");
} elseif (empty($row['timeout'])) {
header("location:page say the user/student need to put timeout first before time-in again");
} else {
while( $row = mysqli_fetch_array($sql)) {
$rfid=$row['rfid_num'];
$id=$row['id'];
$name0 = $row['name'];
$course0 = $row['course'];
$image = $row['image'];
$InsertSql = "INSERT INTO student_att(rfid_num,id,name,course,image,timein) VALUES ('$rfid','$id','$name0','$course0','$image','$time')";
$res = mysqli_query($conn, $InsertSql);
}
}
}
?>
this is my answer just wanna share it, i just add select student_att table
to fetch the data and check if timeout column is empty.
<?php
include_once('connection.php');
if(isset($_POST['submit0'])){
$rfid = $_POST['rfid'];
$time=date("H:i:s");
$sql = mysqli_query($conn,"select * from stud where rfid_num ='$rfid' ");
$count = mysqli_num_rows($sql);
if ($count == 0) {
header("location:notexist.php");
}else{
while( $row = mysqli_fetch_array($sql)) {
$rfid=$row['rfid_num'];
$id=$row['id'];
$name0 = $row['name'];
$course0 = $row['course'];
$image = $row['image'];
$sql1 = mysqli_query($conn,"select * from student_att where rfid_num ='$rfid' order by number DESC limit 1 ");
while( $row = mysqli_fetch_array($sql1)) {
if(empty($row['timeout'])){
header("location:logout.php");
}else{
$InsertSql = "INSERT INTO student_att(rfid_num,id,name,course,image,timein) VALUES ('$rfid','$id','$name0','$course0','$image','$time')";
$res = mysqli_query($conn, $InsertSql);
}
}
}
}
}
?>
How can I perform a autocompute in my database ex. the value of Stock and Quantity(Quantity-Stock) the answer will be save in CarryO column
create.php
<?php
require_once 'dbconfig.php';
$con = mysql_connect("localhost","root","");
if($con)
{
mysql_select_db("testproduct",$con);
}
if($_POST)
{
$sql = mysql_query("SELECT * FROM tblproduct WHERE id = '".$_POST['pid']."'");
$prod = mysql_fetch_array($sql);
$pname = $prod['name'];
$actualprice = $prod['actualprice'];
$sellprice = $prod['sellprice'];
$stock = $prod['Stock'];
$gname = $_POST['gname'];
$saledate = $_POST['saledate'];
$quantity = $_POST['quantity'];
$profit = $_POST['profit'];
$carryO = $_POST['carryO'];
$sells = $_POST['sells'];
$expense = $_POST['expense'];
try{
$stmt = $db_con->prepare("INSERT INTO tblsales(pname,gname,saledate,quantity,actualprice,sellprice,carryO,sells,expense,profit,stock)
VALUES(:upname,:ugname,:usaledate,:uquantity,:uactualprice,:usellprice,:ucarryO,:usells,:uexpense,:uprofit,:ustock)");
$stmt->bindParam(":upname", $pname);
$stmt->bindParam(":ugname", $gname);
$stmt->bindParam(":usaledate", $saledate);
$stmt->bindParam(":uquantity", $quantity);
$stmt->bindParam(":uactualprice", $actualprice);
$stmt->bindParam(":usellprice", $sellprice);
$stmt->bindParam(":ucarryO", $carryO);
$stmt->bindParam(":usells", $sells);
$stmt->bindParam(":uexpense", $expense);
$stmt->bindParam(":uprofit", $profit);
$stmt->bindParam(":ustock", $stock);
if($stmt->execute())
{
echo "Successfully Added";
}
else{
echo "Query Problem";
}
}
catch(PDOException $e){
echo $e->getMessage();
}
}
?>
thanks for your help just new in php and please let me know if I can use your code or its only a example
Change this part:
$prod = mysql_query("SELECT * FROM tblproduct WHERE id = ".$_POST['pid']);
echo $prod;
$pname = [$prod['name']];
Into:
$sql = mysql_query("SELECT * FROM tblproduct WHERE id = '".$_POST['pid']."'");
$prod = mysql_fetch_array($sql);
$pname = $prod['name'];
You may want to try this.
$prod = mysql_query("SELECT * FROM tblproduct WHERE id = ".$_POST['pid'],$db_con); //$db_con must be your database connection
if(!$prod) { die("Database query failed: " . mysql_error()); } //always check if your query is properly done.
$pname = "";
while ($row = mysql_fetch_array($prod)) {
$pname = $row["name"]; }
also if you are fetching only one column which is the name then be specific to your query for fastest result. e.g. "SELECT name FROM tblproduct WHERE id = ".$_POST['pid']
I'm currently trying to echo information from my SQL database which I had to encode in order for it to efficiently write into the table; now when I try to echo the information, WHILE decoding it, the page displays nothing, I'm not entirely sure what I'm doing wrong at this point.
<?php
$type = $_SESSION['SESS_ACC_TYPE'];
$login = $_SESSION['SESS_LOGIN_NAME'];
$log = base64_decode(''.$row['log'].'');
if ($type == '2') {
$qry = "SELECT log FROM logs ";
$result = mysqli_query($GLOBALS["___mysqli_ston"], $qry);
while($row = mysqli_fetch_assoc($result)){
echo ''.$log.'';
}
}
if ($type == '1') {
$qry = "SELECT log FROM logs WHERE login = '.$login.'";
$result = mysqli_query($GLOBALS["___mysqli_ston"], $qry);
while($row = mysqli_fetch_assoc($result)){
echo ''.$log.'';
}
} else {
//do nothing
}
?>
There are many errors with your code:
I fixed them.
$type = $_SESSION['SESS_ACC_TYPE'];
$login = $_SESSION['SESS_LOGIN_NAME'];
if ($type == '2') {
$qry = "SELECT `log` FROM `logs`;";
}
if ($type == '1') {
$qry = "SELECT `log` FROM `logs` WHERE `login` = '" . $login . "';";
}
$result = mysqli_query($GLOBALS["___mysqli_ston"], $qry);
while($row = mysqli_fetch_assoc($result)) {
echo base64_decode($row['log']);
}
since mysql 5.6.1 there are mysql base64 decode/encode functions
select FROM_BASE64('....') ...
select TO_BASE64('....') ...
http://base64decode.net/mysql-from-base64
I would appreciate it if anyone willing to tell how to echoing /print.
Below is the process of entering data into the database, before inserting it how can I echoing it to the table?
<?php
session_start();
if(isset($_POST['submit']))
{
include('class/stock_class.php');
$st = new st_exchange_conv(DEFAULT_SOURCE);
$from = mysql_real_escape_string(stripslashes($_POST['from']));
$value = floatval($_POST['amount']);
$date = date('Y-m-d H:i:s');
$_SESSION['selected'] = $from;
$stocks = $st->stocks();
asort($stocks);
foreach($stocks as $key=>$stock)
{
$st->convert($from,$key,$date);
$stc_price = $st->price($value);
$stock = mysql_real_escape_string(stripslashes($stock));
$count = "SELECT * FROM oc_stock WHERE stock = '$key'";
$result = mysql_query($count) or die(mysql_error());
$sql = '';
if(mysql_num_rows($result) == 1)
{
$sql = "UPDATE oc_stock SET stock_title = '$stock', stc_val = '$stc_price', date_updated = '$date' WHERE stock = '$key'";
}
else
{
$sql = "INSERT INTO oc_stock(stock_id,stock_title,stock,decimal_place,stc_val,date_updated) VALUES ('','$stock','$key','2',$stc_price,'$date')";
}
$result = mysql_query($sql) or die(mysql_error().'<br />'.$sql);
}
header("Location: index.php");
exit();
}
?>
Insert this:
echo "<table><tr><th>".implode(array_keys($stocks), '</th><th>')."</th></tr>";
foreach($stocks as $row) echo "<tr><td>".implode('</td><td>', $row)."</tr>";
echo "</table>";
Edit: If printing the data is the goal and the table-view is not important, I recommend print_r($stocks) instead.