how to store id="getdobtval" into database? - php

Hi i want insert javascript based genarated value into "input value attribute",
my code below like this when i scroll range slider its showing price in id="getdobtval" but when am going buynow its not inserting into database
<form action="" method="post">
<input id="slider-bottom" type="text" name="hrate" data-slider-min="600" data-slider-max="100000" data-slider-step="1" data-slider-value="600" data-slider-tooltip="show"/>
<output id="getdobtcval" name="getdobtval"></output>
<input type="hidden" name="<?php $_SESSION['sess_user']; ?>">
<input type="submit" name="buynow" >
</form>
i changed value into input text now id="getdobtval" not showing generated value in form
<form action="" method="post">
<input id="slider-bottom" type="text" name="hrate" data-slider-min="600" data-slider-max="100000" data-slider-step="1" data-slider-value="600" data-slider-tooltip="show"/>
<input type="text" id="getdobtcval" name="getdobtval">
<input type="hidden" name="<?php $_SESSION['sess_user']; ?>">
<input type="submit" name="buynow" >
</form>
my php form like this
<?php
if(isset($_POST['buynow'])){
$h_rate = $_POST['hrate'];
$hrate_price = $_POST['getdobtval'];
$in_username = $_SESSION['sess_user'];
$conn = mysqli_connect("localhost", "root", "", "buyrate");
$sql = "INSERT INTO buy_rate(hrate,hrate_price,in_username) VALUES('$h_rate','$hrate_price','$in_username')";
if (mysqli_query($conn, $sql)){
echo "Sucessfully Added";
}else{
echo "error";
}
mysqli_close($conn);
}
?>
my javascript like this
<script type="text/javascript">
jQuery(document).ready(function() {
$('#slider-bottom').slider().on('slide', function(ev){
var finalvalue='';
var finalbtvalue='';
var finalbtprice='';
var finalbitvalue='';
finalbtprice= 250;
var newVal = $('#slider-bottom').data('slider').getValue();
var textval = parseInt(newVal);
if( textval >= 600 && textval < 6000){
finalvalue= 0.075;
finalbitvalue = textval * finalvalue;
}else if(textval >=6000 && textval < 30000 ){
finalvalue= 0.070;
finalbitvalue = textval * finalvalue;
}else if(textval >= 30000 ){
finalvalue= 0.065;
finalbitvalue = textval * finalvalue;
}
finalbtvalue = finalbitvalue/finalbtprice;
if(finalbtvalue){
$("#getdobtcval").html("<strong>"+finalbtvalue.toFixed(8)+"</strong>");
}
});
$('#slider-bottom').sliderTextInput();
});
</script>
how to insert javascript based genarated value into "input value attribute", help me

i have update my answer
first you check that when you check amount then this field is empty or not <input type="hidden" id="getdobtval" name="getdobtval"> . type="hidden" change to type="text"
second change insert query
$sql = "INSERT INTO buy_rate(hrate,hrate_price,in_username)
VALUES('".$h_rate."','".$hrate_price."','".$in_username."')";
use concatenation in variables

Related

how can we get autocomplete option during user input from database using sqlite database and php?

I'm trying to get autocomplete option for input form in phpdesktop-chrome which takes data from database and represents near input area while user input. The database I'm using is sqlite3 database.
HTML
<form action="actionpage.php" method="POST" class="register-form" id="register-form" autocomplete="on" >
<label for="itemname"> Item Name</label>
<input type="text" name="itemname" id="itemname" required placeholder="Enter item name">
<input action="insertpage.php" type="submit" name="submit" value="Submit">
</form>
JS
<script>
var items = [ <?php
$result=$db->query("SELECT * FROM register WHERE itemname='$itemname'");
while($row=$result->fetchArray(SQLITE3_ASSOC)) {
$item=$row['itemname'];
} ?>
];
autocomplete(document.getElementById("itemname"), items);
</script>
Use my code it will work
follow this 2 steps you can get your solution
1. first use php function
2. then use JavaScript
PHP function
function pre_json($array,$view=false){
if($view) echo '<pre>';
echo json_encode($array, JSON_NUMERIC_CHECK | JSON_PRETTY_PRINT );
if($view) echo '</pre>';
}
function DBExecute($sql,$type){
global $db;
if($sql !='' && $type !=''){
switch (strtolower($type) ){
case 'select':
$result = $db->query($sql);
if($result){
$resultSet = array();
while($row = $result->fetch(PDO::FETCH_ASSOC)){
$resultSet[] = $row;
}
return $resultSet;
}else{
echo 'Error in Selection Query <br>'.$sql.'<br>';
$error = $db->errorInfo();
echo '<strong>'.$error[2].'</strong>';
exit();
}
break;
default :
return false;
}
}
}
?>
Script
<script>
<?php
$sql = "SELECT * FROM `register` WHERE itemname='$itemname'";
$result = DBExecute($sql,'select');
?>
var json = <?=pre_json($result);?>;
$("#itemname").autocomplete({
source:json,
minLength:0,
select:function(event,ui) {
event.preventDefault();
// console.log(ui.item);
$("#itemname").val(ui.item.itemname);
}
}).focus(function(event) {
$(this).autocomplete("search");
});
</script>
then it will automatically bind in your input field
<form action="actionpage.php" method="POST" class="register-form" id="register-form" autocomplete="on" >
<label for="itemname"> Item Name</label>
<input type="text" name="itemname" id="itemname" required placeholder="Enter item name">
<input action="insertpage.php" type="submit" name="submit" value="Submit">
</form>

Dynamic input and add it into a database

Hello everybody, likle my title tells I'm making a dynamic input but I have errors and I'm going to cry haha. Seriously I have difficulties to make it. I want to add dynamic input and add value in my database. Here is my code :
<?php
// Connect to the DB
$link = mysqli_connect("localhost","root","","testlp") or die("Error " . mysqli_error($link));
// store in the DB
if(!empty($_POST['ok'])) {
// first delete the records marked for deletion. Why? Because we don't want to process them in the code below
if( !empty($_POST['delete_ids']) and is_array($_POST['delete_ids'])) {
// you can optimize below into a single query, but let's keep it simple and clear for now:
foreach($_POST['delete_ids'] as $id) {
$sql = "DELETE FROM recherche WHERE id=$id";
$link->query($sql);
}
}
// adding new recherche
if(!empty($_POST['name'])) {
// ( $i = 0; $i < count($_POST['name']); $i++)
{
$sql = "INSERT INTO recherche (name) VALUES ".$_POST['name'][$i];
$link->query($sql);
}
}
}
// select existing recherche here
$sql="SELECT * FROM recherche ORDER BY id";
$result = $link->query($sql);
?>
<html>
<head>
<title>Simple example of dynamically adding rows with jQuery</title>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.0.3.js"></script>
</head>
<body>
<div style="width:90%;margin:auto;">
<h1>Simple example of dynamically adding rows with jQuery</h1>
<form method="post">
<div id="itemRows">
Item name: <input type="text" name="add_name" /> <input onclick="addRow(this.form);" type="button" value="Add row" /> (This row will not be saved unless you click on "Add row" first)
<?php
// let's assume you have the product data from the DB in variable called $recherche
while($product = mysqli_fetch_array($result)): ?>
<p id="oldRow<?=$product['id']?>"> Item name: <input type="text" name="name<?=$product['id']?>" value="<?=$product['name']?>" /> <input type="checkbox" name="delete_ids[]" value="<?=$product['id']?>"> Mark to delete</p>
<?php endwhile;?>
</div>
<p><input type="submit" name="ok" value="Save Changes"></p>
</form>
</div>
<script type="text/javascript">
var rowNum = 0;
function addRow(frm) {
rowNum ++;
var row = '<p id="rowNum'+rowNum+'">Item name: <input type="text" name="name[]" value="'+frm.add_name.value+'"> <input type="button" value="Remove" onclick="removeRow('+rowNum+');"></p>';
jQuery('#itemRows').append(row);
frm.add_qty.value = '';
frm.add_name.value = '';
}
function removeRow(rnum) {
jQuery('#rowNum'+rnum).remove();
}
</script>
</body>
</html>
I've problem in my loop and I get this error :
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result,
boolean given in C:\wamp\www\testing\dynamic-form-fields.html.php on
line 51 This is the line 51 in the previous code
while($product = mysqli_fetch_array($result)): ?>
<p id="oldRow<?=$product['id']?>"> Item name: <input type="text" name="name<?=$product['id']?>" value="<?=$product['name']?>" /> <input type="checkbox" name="delete_ids[]" value="<?=$product['id']?>"> Mark to delete</p>
<?php endwhile;?>
Thanks for support!
EDIT
Here the new part of the code you guys helped me with : but nothing happens when I submit to the database. I checked in phpmyadmin of my database.
<?php
// Connect to the DB
$link = mysqli_connect("localhost","root","","testlp") or die("Error " . mysqli_error($link));
// store in the DB
if(!empty($_POST['ok'])) {
// first delete the records marked for deletion. Why? Because we don't want to process them in the code below
if( !empty($_POST['delete_ids']) and is_array($_POST['delete_ids'])) {
foreach($_POST['delete_ids'] as $id) {
$sql = "DELETE FROM recherche WHERE id=$id";
$link->query($sql);
}
}
// adding new recherche
if(!empty($_POST['name'])) {
foreach($_POST['name'] as $name)
{
//escape special characters from inputed "name" to prevent SQL injection.
$sql = "INSERT INTO recherche (name) VALUES ".mysqli_real_escape_string($link,$name);
$link->query($sql);
}
}
}
// select existing recherche here
$sql="SELECT * FROM recherche ORDER BY id";
$result = $link->query($sql);
?>
<html>
<head>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.0.3.js"></script>
</head>
<body>
<div style="width:90%;margin:auto;">
<form method="post">
<div id="itemRows">
Item name: <input type="text" name="add_name" /> <input onclick="addRow(this.form);" type="button" value="Add row" /> (This row will not be saved unless you click on "Add row" first)
<?php
if($result!=false && mysqli_num_rows($result)>0){
while($product = mysqli_fetch_array($result)): ?>
<p id="oldRow<?=$product['id']?>"> Item name: <input type="text" name="name<?=$product['id']?>" value="<?=$product['name']?>" /> <input type="checkbox" name="delete_ids[]" value="<?=$product['id']?>"> Mark to delete</p>
<?php endwhile;
}
?>
</div>
<p><input type="submit" name="ok" value="Save Changes"></p>
</form>
</div>
<script type="text/javascript">
var rowNum = 0;
function addRow(frm) {
rowNum ++;
var row = '<p id="rowNum'+rowNum+'">Item name: <input type="text" name="name[]" value="'+frm.add_name.value+'"> <input type="button" value="Remove" onclick="removeRow('+rowNum+');"></p>';
jQuery('#itemRows').append(row);
frm.add_qty.value = '';
frm.add_name.value = '';
}
function removeRow(rnum) {
jQuery('#rowNum'+rnum).remove();
}
</script>
</body>
</html>
Here finaly are the result with great guys in this forum !
Feel free to edit or make whatever you want with this code!
<?php
// Connect to the DB
$link = mysqli_connect("localhost","root","","testlp") or die("Error " . mysqli_error($link));
// store in the DB
if(!empty($_POST['ok'])) {
// first delete the records marked for deletion. Why? Because we don't want to process them in the code below
if( !empty($_POST['delete_ids']) and is_array($_POST['delete_ids'])) {
foreach($_POST['delete_ids'] as $id) {
$sql = "DELETE FROM recherche WHERE id=$id";
$link->query($sql);
}
}
// adding new recherche
if(!empty($_POST['name'])) {
foreach($_POST['name'] as $name)
{
//escape special characters from inputed "name" to prevent SQL injection.
$sql = "INSERT INTO recherche (name) VALUES ('".mysqli_real_escape_string($link,$name)."')";
$link->query($sql);
}
}
}
// select existing recherche here
$sql="SELECT * FROM recherche ORDER BY id";
$result = $link->query($sql);
?>
<html>
<head>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.0.3.js"></script>
</head>
<body>
<div style="width:90%;margin:auto;">
<form method="post">
<div id="itemRows">
Item name: <input type="text" name="add_name" /> <input onclick="addRow(this.form);" type="button" value="Add row" /> (This row will not be saved unless you click on "Add row" first)
<?php
if($result!=false && mysqli_num_rows($result)>0){
while($product = mysqli_fetch_array($result)): ?>
<p id="oldRow<?=$product['id']?>"> Item name: <input type="text" name="name<?=$product['id']?>" value="<?=$product['name']?>" /> <input type="checkbox" name="delete_ids[]" value="<?=$product['id']?>"> Mark to delete</p>
<?php endwhile;
}
?>
</div>
<p><input type="submit" name="ok" value="Save Changes"></p>
</form>
</div>
<script type="text/javascript">
var rowNum = 0;
function addRow(frm) {
rowNum ++;
var row = '<p id="rowNum'+rowNum+'">Item name: <input type="text" name="name[]" value="'+frm.add_name.value+'"> <input type="button" value="Remove" onclick="removeRow('+rowNum+');"></p>';
jQuery('#itemRows').append(row);
frm.add_qty.value = '';
frm.add_name.value = '';
}
function removeRow(rnum) {
jQuery('#rowNum'+rnum).remove();
}
</script>
</body>
</html>
Don't ever assume you have data in $result.test it before processing it.
<?php
if($result!=false && mysqli_num_rows($result)>0){
while($product = mysqli_fetch_array($result)): ?>
<p id="oldRow<?=$product['id']?>"> Item name: <input type="text" name="name<?=$product['id']?>" value="<?=$product['name']?>" /> <input type="checkbox" name="delete_ids[]" value="<?=$product['id']?>"> Mark to delete</p>
<?php endwhile;
}
?>
EDIT
FIX THIS PART IN YOUR CODE, to insert multiple rows of form submit
// adding new recherche
if(!empty($_POST['name'])) {
foreach($_POST['name'] as $name)
{
//escape special characters from inputed "name" to prevent SQL injection.
$sql = "INSERT INTO recherche (name) VALUES ('".mysqli_real_escape_string($link,$name)."')";
$link->query($sql);
}
}

Checkbox filetering not working

I have a couple of checkboxes to filter the results from database but I have two problems, the first is that I am using $_POST variable and when I hit refresh I am getting a confirm form submission dialog, which I don't want as the user may hit refresh many times.
The 2nd part of it is that, if I replace $_POSTwith $_GET I don't see the the confirm message but the checkboxes don't work. Anyone has any idea?
<script type="text/javascript">
$(function(){
$('.checkbox').on('change',function(){
$('#form').submit();
});
});
</script>
<form id="id" method="post" action="">
<input type="checkbox" name="new" class="checkbox" <?php if(isset($_POST['new'])) echo "checked"; ?>/> New<br>
<input type="checkbox" name="used" class="checkbox" <?=(isset($_POST['used'])?' checked':'')?>/> Used<br>
<input type="checkbox" name="ref" class="checkbox" <?=(isset($_POST['ref'])?' checked':'')?>/> Refurbished<br>
</form>
if(isset($_GET['page']))
{
$page = $_GET['page'];
}
else
{
$page = 1;
}
$options = array(
'results_per_page' => 2,
'url' => 'products.php?search=' . urlencode($q) . '&page=*VAR*',
'db_handle' => $dbh
);
if (isset($_POST["ref"])) {
$arguments[] = " condition LIKE '%refur%' ";
}
if (isset($_POST["new"])) {
$arguments[] = " condition LIKE '%new%' ";
}
if (isset($_POST["used"])) {
$arguments[] = " condition LIKE '%use%' ";
}
if(!empty($arguments)) {
$str = implode(' or ',$arguments);
$qry = "SELECT * FROM products where " . $str . " ORDER BY id desc";
$paginate = new pagination($page, $qry, $options);
echo $qry;
}
else {
$paginate = new pagination($page, "SELECT * FROM products order by id desc", $options);
}
This is just an idea, using the classical/modern ajax approach for submitting. Assume that this page is called jqpost.php:
<script>
$(document).ready(function () {
$('.checkbox').on('change',function(){
//$('#form').submit();
var formdata = $("#form").serialize();
$.post("jqpost.php", formdata, function(data) {
$("#result").html("Post OK: " + formdata);
});
});
});
</script>
<form id="form" method="post" action="">
<input type="checkbox" name="new" class="checkbox" <?php if(isset($_POST['new'])) echo "checked"; ?>/> New<br>
<input type="checkbox" name="used" class="checkbox" <?=(isset($_POST['used'])?' checked':'')?>/> Used<br>
<input type="checkbox" name="ref" class="checkbox" <?=(isset($_POST['ref'])?' checked':'')?>/> Refurbished<br>
</form>
<div id="result"></div>
<?php
//...
?>
If a user clicks on a checkbox, jQuery will post data to jqpost.php script. In return, #result div will give a status text.
As a result, if the user presses the refresh button on browser, the form is not submitted again and again.

jQuery Post Form Data to PHP

I am posting data to PHP from jQuery using data from an HTML form.
Here is the jQuery line that sends the POST
$.post("InsertNewQuestion.php", $("Create_Question_Form").serialize());
Here is the PHP code
<?php
$con = mysql_connect("localhost","root","");
mysql_select_db("Quizzes",$con);
$Quiz_Name = $_POST['Question'];
echo $Quiz_Name;
$Option_1 = $_POST['Option1'];
echo $Option_1;
$Option_2 = $_POST['Option2'];
echo $Option_2;
$Option_3 = $_POST['Option3'];
echo $Option_3;
$Option_4 = $_POST['Option4'];
echo $Option_4;
$Option_5 = $_POST['Option5'];
echo $Option_5;
$rowIDList = mysql_query("SELECT rowID FROM TestQuiz");
$ColumnValues = array();
$CurrentGreatestRowID = -1;
$LCV = 1;
while($row1 = mysql_fetch_assoc($rowIDList)) {
if ($CurrentGreatestRowID < $row1['rowID']) {
$CurrentGreatestRowID = $row1['rowID'];
}
$LCV++;
}
$CurrentRowID = $CurrentGreatestRowID+1;
$sql = "INSERT INTO TestQuiz (rowID,Quiz_Name,Option_1,Option_2,Option_3,Option_4,Option_5,Option_1_Votes,Option_2_Votes,Option_3_Votes,Option_4_Votes,Option_5_Votes)
VALUES(".$CurrentRowID.",'".$Question."','".$Option1."','".$Option2."','".$Option3."','".$Option4."','".$Option5."',0,0,0,0,0);";
if (mysql_query($sql,$con)) {
echo "Inserted values";
}
else {
echo ("Could not insert values: ". mysql_error());
}
mysql_close($con);
?>
Here is the HTML form
<form id="Create_Question_Form" action="" method="POST">
Question Name: input id="Question" class="Create_Question_Text_Box" type="text" name="Question_Name"><span id="Invalid_1"></span><br>
Option 1: input id="Option1" class="Create_Question_Text_Box" type="text" name="Option_1"><span id="Invalid_2"></span><br>
Option 2: input id="Option2" class="Create_Question_Text_Box" type="text" name="Option_2"><span id="Invalid_3"></span><br>
Option 3: input id="Option3" class="Create_Question_Text_Box" type="text" name="Option_3"><span id="Invalid_4"></span><br>
Option 4: input id="Option4" class="Create_Question_Text_Box" type="text" name="Option_4"><span id="Invalid_5"></span><br>
Option 5: input id="Option5" class="Create_Question_Text_Box" type="text" name="Option_5"><span id="Invalid_6"></span><br>
input type="Submit" id="Question_Submit" value="Create Question"></input>
</form>
Your form selector should be #Create_Question_Form. Note the # indicating that this is an element ID.
$("#Create_Question_Form").serialize()
Update
You are accessing the $_POST values by ID instead of name. Try this:
$Option_1 = $_POST['Option_1'];
$Option_2 = $_POST['Option_2'];
// etc
input type="Submit" id="Question_Submit" value="Create Question"></input>
<input type="Submit" id="Question_Submit" value="Create Question" />
You seem t be missing a bracket

Editing a form in MySQL and PHP

I am working on a project. What I need to do is basically enter some info into a form, have that form save it into a database, display the data, and then be able to edit the data. So far, I am able to do everything except edit the data. I've tried using $_GET to get the ID of the particular "bug" I need to edit, and I am able to do that, and get all of the information but I am not sure how to edit that particular ID in my database. Here is my handler: http://pastebin.com/mR6QWpJ7 and my form:
<form action="week10handle.php" method="POST">
<fieldset width="300px">
<legend width="300px"><b>Add a bug report</b></legend>
Product Name:<br/><input type="text" name="product_name"><br/>
Product Version: <br/><input type="text" name="product_version"><br/>
Hardware Type: <br/><input type="text" name="hardware"><br/>
Operating System: <br/><input type="text" name="os"><br/>
Frequency: <br/><input type="text" name="frequency"><br/>
Proposed Solutions: <br/><textarea name="solutions"></textarea><br/>
<input type="submit" value="Submit">
</fieldset>
</form>
Here is where I obtain the get data in my edit form page so far, but as of right now, I am not sure how to edit a particular ID in the database.
$getbug = htmlspecialchars($_GET["bugid"]);
if (!empty($getbug)){
$getbuginfo = mysql_query("SELECT * FROM `bugs` WHERE `id`= '$getbug'");
if ($getbuginfo = mysql_fetch_assoc($getbuginfo)){
$edit_product_name = $getbuginfo['product_name'];
$edit_prod_version = $getbuginfo['product_version'];
$edit_hardware = $getbuginfo['hardware_type'];
$edit_os = $getbuginfo['os'];
$edit_frequency = $getbuginfo['frequency'];
$edit_solutions = $getbuginfo['solutions'];
?>
<form action="week10handle.php" method="POST">
<fieldset width="300px">
<legend width="300px"><b>Edit bug <?php echo $getbug;?></b></legend>
Product Name:<br/><input type="edit" name="product_name" value="<?php echo $edit_product_name;?>"><br/>
Product Version: <br/><input type="edit" name="product_version" value="<?php echo $edit_prod_version;?>"><br/>
Hardware Type: <br/><input type="edit" name="hardware" value="<?php echo $edit_hardware;?>"><br/>
Operating System: <br/><input type="edit" name="os"value="<?php echo $edit_os;?>"><br/>
Frequency: <br/><input type="edit" name="frequency"value="<?php echo $edit_frequency;?>"><br/>
Proposed Solutions: <br/><textarea name="solutions"><?php echo $edit_product_name;?></textarea><br/>
<input type="submit" value="Submit">
</fieldset>
</form>
EDIT: Here is my update php code, but it is still not working, when I submit my form, it refreshes the page, but it doesn't update the database:
<?php
if (mysql_connect('localhost','root','') && mysql_select_db('bug_reports')){
$errors = array();
if (isset($_POST['product_name'], $_POST['product_version'],$_POST['hardware'],$_POST['os'],$_POST['frequency'], $_POST['solutions'])){
$product_name = mysql_real_escape_string(htmlentities($_POST['product_name']));
$product_version = mysql_real_escape_string(htmlentities($_POST['product_version']));
$hardware = mysql_real_escape_string(htmlentities($_POST['hardware']));
$os = mysql_real_escape_string(htmlentities($_POST['os']));
$frequency = mysql_real_escape_string(htmlentities($_POST['frequency']));
$solutions = mysql_real_escape_string(htmlentities($_POST['solutions']));
$getbug = mysql_real_escape_string(htmlentities($_POST['bugid']));
if (empty($product_name) || empty($product_version) || empty($hardware) || empty($os) || empty($frequency) || empty($solutions)){
$errors[] = 'All fields are required.';
}
if (!is_numeric($product_version) || !is_numeric($frequency)){
$errors[] = 'Product version and frequency must both be numbers';
}
if (empty($errors)){
$update = "UPDATE `bugs` SET `product_name` = '$product_name', `product_version = '$product_version', `hardware_type = '$hardware', `os` = '$os', `frequency` = '$frequency', `solutions` = '$solutions' WHERE `id` = $getbug";
if ($update = mysql_query($update)){
header('Location: week10handle.php');
} else{
$errors[] = 'Something went wrong, please try again.';
}
} else{
foreach($errors as $error){
echo '<p><strong>'.$error.'</strong></p>';
}
}
}else{
$getbug = htmlspecialchars($_GET["bugid"]);
}
if (!empty($getbug)){
$getbuginfo = mysql_query("SELECT * FROM `bugs` WHERE `id`= '$getbug'");
if ($getbuginfo = mysql_fetch_assoc($getbuginfo)){
$bugid = $getbuginfo['id'];
$edit_product_name = $getbuginfo['product_name'];
$edit_prod_version = $getbuginfo['product_version'];
$edit_hardware = $getbuginfo['hardware_type'];
$edit_os = $getbuginfo['os'];
$edit_frequency = $getbuginfo['frequency'];
$edit_solutions = $getbuginfo['solutions'];
?>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
<fieldset width="300px">
<legend width="300px"><b>Edit bug <?php echo $getbug;?></b></legend>
Product Name:<br/><input type="edit" name="product_name" value="<?php echo $edit_product_name;?>"><br/>
Product Version: <br/><input type="edit" name="product_version" value="<?php echo $edit_prod_version;?>"><br/>
Hardware Type: <br/><input type="edit" name="hardware" value="<?php echo $edit_hardware;?>"><br/>
Operating System: <br/><input type="edit" name="os"value="<?php echo $edit_os;?>"><br/>
Frequency: <br/><input type="edit" name="frequency"value="<?php echo $edit_frequency;?>"><br/>
Proposed Solutions: <br/><textarea name="solutions"><?php echo $edit_product_name;?></textarea><br/>
<input type="hidden" name="bugid" value="<?php echo $bugid;?>" >
<input type="submit" value="Update">
</fieldset>
</form>
<?
}else{
echo "something went wrong";
}
}else{
echo "No bug found.";
}
}else
echo 'Could not connect at this time.';
?>
A typical way to detect an update, as opposed to an insert, would be to check for a value for id. So, in your edit form add a hidden field to pass the id to the handler and then in your handler you can decide whether to process it as insert or update based on the presence of the id field.
if (isset($_GET['id']) {
// do update
$sql = 'UPDATE `bugs` SET ... WHERE id = ' . intval($_GET['id']);
} else {
// do insert
$sql = 'INSERT INTO `bugs` VALUES ....';
}
UPDATE `bugs` SET `product_name` = '...', `product_version` = '...', ... WHERE `id` = $bugid;
Where the "..." will be replaced with newly $_POST-ed values for each column

Categories