Update mySql based specific onChange - javascript

I have a page that present a big table in my SQL DB, and every cell is an HTML input.
The goal is to make a editable sql table that update my SQL DB based on changed in specific cell in big table form.
I tought about making a script that trigger a JS function when a cell-change occurs, that update the specific change.
Is it possible?
Any other idea?
This is a draft of my idea. The issue is the While loop that present the table
<script>
$(document).ready(function(){
$('#testnum').on('change', 'input', function(){
$.post("getter.php",{###Don't know what to put here###);
});
});
</script>
<?php
while($res=mysqli_fetch_array($result))
{
echo "<tr>
<td onchange='changeit(fin)'>
<div name='fin' style='display:none;'> ".$res['first'] ."</div>
<input type='int' value=".$res['first'].">
</td>
<td onchange='changeit(sta)'>
<div name='sta' style='display:none;'>".$res['second']."</div>
<input type='int' value=".$res['second'].">
</td>
<td>";
?>
EDIT
For example - how can I pass David's ID if I change his city?
(This table printed with WHILE statement)
ID name city
-------------------
1 David NY
--------------------
2 John LA
-------------------
3 Adam NJ
if I change David's city to "London" for example I want to send 3 things:
1) The ID - so I know which specific row. (in this case - "1")
2) The column name - so I can know which column has changed. (in this case - "city")
3) The data after change - so I know what to update. (in this case - "London")

Hi you can use something similar to this, you'll need to adapt it to your code and needs.
HTML FILE:
<!DOCTYPE html>
<html lang="">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Table Check</title>
</head>
<body>
<table>
<tbody>
<tr class="row">
<td class="col id"><input class="txtdata" name="id" value="1"></td>
<td class="col name"><input class="txtdata" name="name" value="Jhon"></td>
<td class="col city"><input class="txtdata" name="city" value="NY"></td>
</tr>
<tr class="row">
<td class="col id"><input class="txtdata" name="id" value="2"></td>
<td class="col name"><input class="txtdata" name="name" value="Jane"></td>
<td class="col city"><input class="txtdata" name="city" value="LA"></td>
</tr>
</tbody>
</table>
</body>
<script type='text/javascript' src='https://code.jquery.com/jquery-3.1.0.min.js'></script>
</html>
<script>
$(document).ready(function($) {
$('.txtdata').on('change', function(){
var parent = $(this).parent('.col').parent('.row');
var id = $(parent).find('.id').find('input').val();
var name = $(parent).find('.name').find('input').val();
var city = $(parent).find('.city').find('input').val();
var attribChanged = $(this).attr('name');
data = {id: id, name: name, city: city, attribChanged: attribChanged};
$.post('getter.php', data, function(data){
$(parent).html(data);
});
});
});
</script>
PHP FILE:
<?php
$name = $_REQUEST['name'] . '(mod)';
$id = $_REQUEST['id'] . '(mod)';
$city = $_REQUEST['city'] . '(mod)';
echo '<td class="id"><input class="txtdata" name="id" value="'.$id.'"></td>
<td class="name"><input class="txtdata" name="name" value="'.$name.'"></td>
<td class="city"><input class="txtdata" name="city" value="'.$city.'"></td>';
?>

PHP file:
<?php
echo '<table>';
while($res=mysqli_fetch_array($result)){
echo '<tr>';
echo '<td>$res['id']</td>';
echo '<td onchange="changeit($res['id'], \'name\', this)"><input type="text" value="$res['name']"/></td>';
echo '<td onchange="changeit($res['id'], \'city\', this)"><input type="text" value="$res['city']"/></td>';
echo '</tr>';
}
echo '</table>';
Jquery:
function changeit(id, field, element){
var newVal = element.find('input').val();
$.post("getter.php",{
"id": id,
"field": field,
"newVal": newVal
}, function(result){
if(result == 'success'){
alert('id: '+ id);
alert('column: '+ field);
alert('what change: '+ newVal);
}
});
}
PHP file getter.php:
$id = $_POST['id'];
$field = $_POST['field'];
$newVal = $_POST['newVal'];
$sql = mysql_query("UPDATE table_name SET $field = $newVal WHERE id = $id");
if($sql) echo 'success'; else echo '0';
Hope helpful for you.

Related

Onchange event is not detecting copy paste in input fields

I have so many Input fields in html table and I am using the code below to copy paste columns from excel directly to these input fields. and the code below is working great for copy paste columns from excel to this html input table fields. My problem is that I want onchange event for each input to detect when I copy paste and alert these values. cause then I can take each value was changed and change it in the database. The Onchange event does not detect change in value when I copy paste!
<table>
<thead>
<tr>
<th>Name</th>
<th>Unit</th>
<th >ID</th>
<th >Margin </th>
</tr>
<tbody>
<?php
$query = " select name,unit,Margin, id FROM Table1";
$stmt = $conn->query( $query );
$count=0;
while ( $row = $stmt->fetch( PDO::FETCH_ASSOC ) )
{ ?>
<tr>
<td> <input onchange="send(this)" type="text" value="<?php echo $row['Name']; ?>"> </td>
<td><input onchange="send(this)" type="number" value="<?php echo $row['unit]; ?>" ></td>
<td><input type="number" value="<?php echo $row['ID']; ?>" ></td>
<td><input onchange="send(this)" type="number" value="<?php echo $row['Margin']; ?>" ></td>
</tr>
<?php } ?>
</tbody>
</thead>
</table>
<!-- Copy Paste in input fields -->
<script type="text/javascript">
$('input').on('paste', function(e){
var $this = $(this);
$.each(e.originalEvent.clipboardData.items, function(i, v){
if (v.type === 'text/plain'){
v.getAsString(function(text){
var x = $this.closest('td').index(),
y = $this.closest('tr').index()+1,
obj = {};
text = text.trim('\r\n');
$.each(text.split('\r\n'), function(i2, v2){
$.each(v2.split('\t'), function(i3, v3){
var row = y+i2, col = x+i3;
obj['cell-'+row+'-'+col] = v3;
$this.closest('table').find('tr:eq('+row+') td:eq('+col+') input').val(v3);
});
});
});
}
});
return false;
});
</script>
<script>
function send(value){
alert(value.value);
}
</script
I use this for my input for cut ,copy & paste
function send(value){
alert(value.value);
}
input here : <input onchange="send(this)" type="text" oncopy="send(this)" onpaste="send(this)" oncut="send(this)" type="text" value=""/>

passing value to hidden input value before submit

I am trying to run a form that stores an Id in a hidden input tag so that I can retrieve it in the next page using php. For some reason I can't retrieve the value using the php file. Echoing orderId.value and order number are working fine.
main_page.php
<script>
function EditValues(orderNumber) {
var orderId = document.getElementById("orderId");
orderId.value = orderNumber;
document.forms["form1"].submit();
}
</script>
<body>
<form action="edit-form.php" id="form1">
<div class="container">
<!--use the hidden input variable to save the order number clicked -->
<input id="orderId" type="hidden" name="orderId"/>
<?php
require("config.php");
$con = new mysqli(DB_Host, DB_User, DB_Password, DB_Name);
if ($con->connect_error) {
die("Connection failed");
}
echo '<table id="tblOrders" name ="OrderTable" style="width: 100%">
<tr>
<th>Sno</th>
<th>Order Number</th>
</tr>';
$displayTableDataQuery = "SELECT id, orderNumber, customerName, deliveryDate FROM orderTable";
if ($tableData = $con-> query($displayTableDataQuery)) {
while($row = $tableData-> fetch_assoc()) {
$id = $row['id'];
$orderNumber = $row["orderNumber"];
echo '<tr >
<td>'.$id.'</td>
<td id = "orderNumber">'.$orderNumber.'</td>
<td><input type = "button" id ="editButton'.$id.'" value = "Edit" onclick = "EditValues('.$orderNumber.');"/> </td>
<td><input type = "button" id = "printInvoice'.$id.'" value="Print" onclick = "PrintInvoice('.$orderNumber.');" /> </td>
</tr>';
}
} else {
echo $con->error;
}
$tableData->free();
?>
</div>
</form>
</body>
In edit-form.php
<?php
$xyzabc = $_POST['orderId'];
echo $xyzabc;
?>
There is nothing echoed for $xyzabc
I would prefer if there was some way to do this without jQuery as I'm kind of new to this and haven't really gotten a hang of how everything works together as of now.
You can store value directly to the hidden input field.
<!--use the hidden input variable to save the order number clicked -->
<input id="orderId" type="hidden" name="orderId" value="<?=$variable_name;?> />
So that when you submit the form
<?php
$xyzabc = $_POST['orderId'];
echo $xyzabc;
?>
will fetch the data.
Or you can pass the hidden value in url. For example
<a href="localhost:8000/edit-form.php?orderId="<?=$variable_name;?>
Then in you form-edit.php
<?php
$xyzabc = $_GET['orderId'];
echo $xyzabc;
?>

How can i get one value from different select options with the same name in the same form

I have assigned three select options with the same name which will be stored in the my database table. My code was working well at first right now i don't why it's working well. right now it only saves the value assigned to the last select option panel. Please i need help
<?php
if(isset($_POST['submit'])){
$vic_title = $_POST['vic_title'];
$vic_name = $_POST['vic_name'];
echo $vic_name;
if($vic_name=='')
echo "<font color='Green'><b>Please fill in the discription the accused name THANKS!!</b></font>";
else
$insert = "INSERT INTO discips(vic_title, vic_name)
values('$vic_title','$vic_name')";
$run = mysql_query($insert);
if ($run) {
echo "<font color='Green'><b>the incident was added</b></font>";
# code...
}
else{
echo "<font color='red'><b>the incident was not added</b></font>";
}
}
?>
Here is my form that i used.
<form name="harvets" id="form" action="?pg=<?php echo $_GET[pg]."&lodge_inc"."&hv=$token"; ?>" method="post" enctype="multipart/form-data">
<input type="hidden" name="id" value="<?php echo $edit_ca;?>">
<center style="padding-top: 2%; margin-top: 3%;"><h3>Enter Incident Informtion</h3></center>
<table width="100%" class="m_aligned">
<tr>
<td align="right" style="width: 100%;">Victim *</td>
<td align="left" style="width: 100%;">
<select style="width: 100%;" id="victim" name="vic_title" class="sect" placeholder="Select a Role">
<option></option>
<option value="staff">Staff</option>
<option value="student">Student</option>
<option value="visitor">Vistor</option>
</select>
</td>
</tr>
<tr id="staff_name" style="display: none;">
<td align="right" style="width: 100%;">Staff Name : </td>
<td align="left" style="width: 100%;">
<select style="width: 100%;" name="vic_name" class="sect" placeholder="Staff's Name">
<?php
$get_staf = "select * from useraccounts";
$run_staf = mysql_query($get_staf);
while ($row = mysql_fetch_array($run_staf)) {
$staf_id = $row['username'];
$staf_name = $row['name'];
echo "<option value='$staf_id'>". $staf_name ."</option>";
# code...
}
?>
</select>
</td>
</tr>
<tr id="vis_name" style="display: none;">
<td align="right" style="width: 100%;">Visitor Name : </td>
<td align="left" style="width: 100%;"><input type="text" name="vic_name" placeholder="Visitor's Name"></td>
</tr>
<tr id="stud_name" style="display: none;">
<td align="right" style="width: 100%;">Student Name: </td>
<td align="left" style="width: 100%;">
<select style="width: 100%;" class="sect" name="vic_name" placeholder="Student's Name" cols="9">
<option></option>
<?php
$get_stud= "SELECT * FROM studentdetails";
$run_stud = mysql_query($get_stud);
while ($row = mysql_fetch_array($run_stud)) {
$stud_id = $row['id'];
$stud_fname = $row['fname'];
$stud_lname = $row['lname'];
echo "<option value='$stud_id'>". $stud_fname ." ". $stud_lname ."</option>";
# code...
} ?>
</select>
</td>
</tr>
SAVE
Here is My JavaScript
<script type="text/javascript">
$("#victim").change(function (ev){
if($(this).val()=='visitor') $("#vis_name").css("display", "table-row")
else $("#vis_name").css("display", "none")
if($(this).val()=='student') $("#stud_name").css("display", "table-row")
else $("#stud_name").css("display", "none")
if($(this).val()=='staff') $("#staff_name").css("display", "table-row")
else $("#staff_name").css("display", "none")
});
</script>
<script type="text/javascript">
$(document).ready(function() {
$(".sect").select2({
allowClear: true
});
</script>
Getting the value of the last field (select or anything) using a given name is the correct behaviour. If you wish to send multiple values when submiting the form, you must give different names to their fields.
Ask yourself why you want to name them the same way. How are you supposed to get them ? If I create three different inputs, name the three of them 'title' and submit the form after type different things in each input, what do you guess I'll get if I access $_POST['title'] ? More problematic, what should I type to get the value of the first of my three inputs ? How the hell would I know, these are identical elements with different purposes !
If you design different elements, give them different features or they won't be different. They will just overwrite each other and you'll only have the last of the lot.
If you truly need to have them named the same, add hooks at the end of the name like this :
name="vic_name[].
It will append the value of that field to $_POST['vic_name'], which will now be an array, and therefore may contain multiple values. That's the only way.
I have solved the problem. I created two files by using AJAX to call another file to replace one a certain line of code. Sometimes we may want something and we fail in someway or another, but when we focus deeply we can solve the code.
i replaced my Javasrcipt file with
<script type="text/javascript">
$("#victim").change(function () {
var cat = $(this).val();
$.ajax({
type: "GET"
, url: "student/fetch_victim.php"
, data: "n=" + Math.random() + "&vr=" + cat
, beforeSend: function () {
$("#ctg").html("<img src='imgs/loader.gif' />...loading")
}
, success: function (response) {
$("#tryme").html(response)
}
});
});
</script>
and i moved the sections i wanted to another file
<?php
require "../ht.php"; $hom = new ht;
if($_GET['vr']){
$q = $_GET['vr'];
if($q =='staff'){
echo "
<td align='right' style='width: 100%;'>Staff Name : </td>
<td align='left' style='width: 100%;'>
<select name='vic_name' class='sect' style='width: 100%;' value='<?php echo $edit[2] ?>' placeholder='Staff's Name'>";
$staf = mysql_query("SELECT * FROM useraccounts"); $w=mysql_error();
while ($row = mysql_fetch_array($staf)) {
echo "<option value='$row[0]'>". $row[1] ."</option>";
# code...
}
echo "</select>
</td>
";
}elseif ($q == 'student') {
echo "
<td align='right' style='width: 100%;'>Student Name: </td>
<td align='left' style='width: 100%;'>
<select style='width: 100%;' class='sect' name='vic_name' value='".$edit[2] ."' placeholder='Student's Name' cols='9'>
<option></option>";
$stud= mysql_query("SELECT * FROM studentdetails");
while ($row = mysql_fetch_array($stud)) {
echo "<option value='$row[31]'>". $row[0] .' '. $row[1] ."</option>";
# code...
}
echo "</select>
</td>
";
}else{
echo "
<td align='right' style='width: 100%;'>Visitor Name : </td>
<td align='left' style='width: 100%;'><input style='width: 100%;' type='text' name='vic_name' value='".$edit[2] ."'placeholder='Visitor's Name'></td>
";
}
}
?>
<script type="text/javascript">(function($){
var code = $('.html-container').html();
$('.html-viewer').text(code);
})(jQuery);</script>

How to execute sql delete query on button click using javascript function in PHP

I have three files, index.html, database.php, and function.js. In my database.php, I have created a form with a delete button to execute the delete sql query on click. My main purpose is to display a table with records displayed and a delete button on each so that whenever I click the delete button, it executes the SQL query and removes that particular row from the database.
It works fine before I added in ajax into the javascript. Now when delete button is clicked, the whole page just refreshes.
How do I execute the delete query on the delete button click using a javascript function that I want to call in my php file without creating/using new files?
I am using vi editor to code so I do not have any means of debugging except IE's developer tools. My javascript file doesn't seem to be working because in the HTML file the form returns a null at
onsubmit="return checkFields()";
as stated from the error I received, but it's probably just because there are errors in my javascript file.
P.S. I am new to PHP, javascript, and ajax so do pardon me if I make any careless or obvious mistakes. I also do not know any jQuery or JSON. Any form of help in the simplest explanation would be greatly appreciated.
Here is the index.html file:
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css"/>
<script src="function.js" type="text/javascript"></script>
</head>
<body>
<form name="infoForm" method="post" onsubmit="return checkFields()" action="">
<table>
<tr>
<td>Name:</td>
<td><input type="text" name="name" id="name" maxlength="40"></td>
</tr>
<tr>
<td>Address:</td>
<td><textarea maxlength="45" name="address"id="address" ></textarea></td>
</tr>
<tr>
<td>Phone:</td>
<td><input type="text" name="phone" id="phone" maxlength="20"><br></td>
</tr>
<tr>
<td>Gender:</td>
<td><input checked type="radio" name="gender" id="male" value="Male">Male
<input type="radio" name="gender" id="female" value="Female">Female</td>
</tr>
<tr>
<td>
Nationality:
</td>
<td>
<select name="nation">
<option value="Singapore">Singapore</option>
<option value="Malaysia">Malaysia</option>
<option value="Thailand">Thailand</option>
<option value="Indoensia">Indonesia</option>
<option value="Philippines">Philippines</option>
</select>
</td>
</tr>
<tr>
<td></td>
<td>
<br><input type="reset" value="Cancel">
<input type="submit" name="result" value="Submit"/>
</td>
</tr>
</table>
</form>
<div id="divTable"></div>
</body>
</html>
Here is the database.php file:
<?php
// Define database parameters //
DEFINE ('DB_USER' ,'iqwe');
DEFINE ('DB_PASSWORD', 'inqwe123');
DEFINE ('DB_HOST', 'localhost');
DEFINE ('DB_NAME', 'hqwdqq');
$table_info = "info";
// Connect to database
$conn = #mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect to Database:'. mysql_error());
#mysql_select_db (DB_NAME) OR die ('Could not select the Database: '.mysql_error());
// Delete Row
if(isset($_POST['delete'])){//java script function somewhere
echo "<script>";
echo "deleteRow()";
echo "</script>";
}
//Check if phone no. is duplicate and if not, insert data
if(isset($_POST['result'])){
$phone = $_POST['phone'];
$query_string = "select phone from $table_info where phone='$phone'";
$result = #mysql_query($query_string);
$num_row = mysql_num_rows($result);
if($num_row){
echo "A same phone number has been found. Please enter a different phone number.";
}else{
$query_string = "insert into $table_info(name, address, phone, gender, nation) values('".$_POST['name']."','".$_POST['address']."','".$_POST['phone']."','".$_POST['gender']."','".$_POST['nation']."')";
$result = #mysql_query($query_string);
}
}
// Display table
$query_string = "select * from $table_info";
$result = #mysql_query($query_string);
$num_row = mysql_num_rows($result);
if($num_row){
echo "<table border=1>";
echo "<tr><th>Name</th><th>Address</th><th>Phone no.</th><th>Gender</th><th>Nationality</th><th>Created</th><th>Modified</th><th>Action</th></tr>";
while($row = mysql_fetch_array($result)){
echo "<tr><td>", $row['name'], "</td>";
echo "<td>", $row['address'], "</td>";
echo "<td>", $row['phone'], "</td>";
echo "<td>", $row['gender'], "</td>";
echo "<td>", $row['nation'], "</td>";
echo "<td>", $row['createdTime'], "</td>";
echo "<td>", $row['modifiedTime'], "</td>";
?>
<!--Delete button-->
<td><form id="delete" method="post" action="">
<input type="hidden" name="deleteRow" value="<?php echo $row['user_id']; ?>"/>
<input type="button" name="delete" value="Delete" onclick="return deleteRow(<?php echo $row['user_id']; ?>);"/></td></form></tr>
<?php
}
echo "</table>";
}
else{
echo "0 results";
}
?>
<form method="post" action="index.html">
<input type="submit" name="goBack" value="Back"/>
</form>
And here is the function.js file:
function checkFields(){
var name = document.getElementById("name");
var address = document.getElementById("address");
var phone = document.getElementById("Phone");
if(confirm('Do you want to submit')){
if(name == null, name == ""||address == null, address == ""||phone == null, phone == ""){
alert("Please fill in all your details.");
return false;
}
else{
var page = "database.php";
var xmlhttp = new XMLHttpRequest();
if(xmlhttp==null){
alert("Your browser does not support AJAX!");
return false;
}
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyState==4 && xmlhttp.status==200){
document.getElementById("divTable").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET", page, true);
xmlhttp.send(null);
return false;
}
}
else{
return false;
}
}
function deleteRow(id){
if(confirm("Are you sure you want to delete this contact?")){
//$id = $_POST['user_id'];
$query_string = "delete from $table_info where user_id='id';
$result = mysql_query($result) or die ('Could not execute.'. mysql_error());
return false;
}
}
It looks like you're missing a closing double-quote at the end of this line:
$query_string = "delete from $table_info where user_id='id';
It should read:
$query_string = "delete from $table_info where user_id='id'";
There may be other errors as well. You should learn to use your browser's built-in script debugging features (and/or download one if your browser doesn't have one). For example, try Firebug and the Web Developer Toolbar for Firefox.

Limited success with AJAX. Sometimes nothing is returned or an error

So far I'm having limited success with AJAX. I have a couple of textboxes I want to fill with values from the database, only nothing is being inserted. Something is happening though which I guess is a good sign, but they're specific to 2 values and they're errors. Nothing seems to be out of the ordinary about these values either. The error report says: Parse error: syntax error, unexpected '}' in getemp.php, but everything lines up correctly and it never happens anywhere else in the database but these values that are back to back. Also since I'm using a table with listboxes no matter which box I choose from it only affects one entry into the table, however I thought the loop would take care of that.
So here's the code I'm trying to use AJAX on:
<? require_once("connect_to_DB.php"); // inserts contents of this file here ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>New Order Form/Edit Order Form</title>
<link rel="stylesheet" href="hw2.css"/>
<?
connectDB();
session_start();?>
<script src="validation.js"></script>
<script src="jquery.js"></script>
<script type="text/javascript">
function showUser(str){
if(str==""){
$("#txtHint").html("");
return;
}else{
$("#txtHint").load("getemp.php?q="+str);
};
}
</script>
</head>
<body>
<?
include ('navbar_func.php');
echo navbar();
// Establish a connection with the data source, and define the SQL
$strSQL = "SELECT product_name FROM product";
$rs = mysqli_query($db, $strSQL) or die("Error in SQL statement: " . mysqli_error());
$row = mysqli_fetch_array($rs);
// Establish a connection with the data source, and define the SQL for the orders
$newID = 101;
$rndSQL = "Select order_id FROM salesorder WHERE order_id = ".$newID;
while(mysqli_num_rows(mysqli_query($db, $rndSQL)) > 0){
echo "<script>console.log($newID)</script>";
$newID++;
$rndSQL = "Select order_id FROM salesorder WHERE order_id =". $newID;
}
?>
<?$today = date("F j, Y");?>
<form name="orderform" method="post" action="new_order_result.php" onsubmit="return validate_order()">
<table>
<tr>
<td>Order Number:</td>
<td><label id="order" type="text" name="ordernumber" value="<?=$newID?>"><?=$newID?></label>
</td>
<td>Order Date:</td>
<td><label type="text" name="orderdate" value="<?=$today?>"/><?=$today?></label></td>
</tr>
<tr>
<td> Customer:</td>
<td><input id="customer"type="text" name="customer" value=""/></td>
</tr>
<tr>
<td>Sale Agent:</td>
<td><input id="salesagent" type="text" name="salesagent" value=""/></td>
<td>Order Status:</td>
<td><input id="orderstatus" type="text" name="orderstatus" value=""/></td>
</tr>
</table>
<table border = "1">
<tr>
<th>Product</th>
<th>Price</th>
<th>Quantity</th>
</tr>
<?$rs = mysqli_query($db, $strSQL) or die("Error in SQL statement: " . mysqli_error());?>
<?for($x=0; $x <= 19; $x++)
//just needs to post quantity not which
{?>
<tr>
<td>
<select name="P<?=$x?>" onchange="showUser(this.value)">
<option value="">Choose the product you'd like to purchase:</option>
<?while($row = mysqli_fetch_array($rs)){?>
<?print '<option value="'.$row[0].'">' . $row[0] . '</option>' . "\n";}//This is uses the datebase values?>
</select>
</td>
<td>
<div id="txtHint"><input type="text" name="M<?=$x?>" value="0"></input></div>
</td>
<td><select name="Q<?=$x?>" value="$row[1]">
<?for($i = 0; $i < 10; $i++){
print "<option value=$i>$i</option>";}//This uses the datebase values?>
</select></td>
</tr>
<? $rs = mysqli_query($db, $strSQL); //resets pointer in database.?>
<?}?>
</table>
<center>
<input type="submit" value="Submit"/>
<input type="reset" value="Reset"/>
</center>
</form>
</body>
</html>
Here's getemp.php which is being used in the script.
<? require_once("connect_to_DB.php"); // connect to furniture database
// ###################### retrieve data from database #################
connectDB();
$sql = "SELECT * FROM product WHERE product_name = " . $_GET["q"];
$result = mysqli_query($db, $sql) or die("SQL error: " . mysqli_error());
// ###############################################################
while($row = mysqli_fetch_array($result))
{
print $row['product_cost']
}
mysqli_close($db);
?>
As of right now the only way I can test for a reaction is by having "div" tags surrounding the textbox.
Thank you so much for the help or tips. I've spent so many hours on just this small thing and I can't make much more progress more than this. I've tried everything and looked everywhere for possible solutions, but none seemed to work. Thanks again!
In getemp.php:
print $row['product_cost'] is missing a semicolon.
Should be:
print $row['product_cost'];
Which is why you're seeing the error Parse error: syntax error, unexpected '}' in getemp.php

Categories

Resources