Values are not updating in database - php

I have one table , in that i have 4 text fields. So when i enter the values in all text field box. And when i press Update button. The entered values are not showing in my database. Here is my code :
This below code is for textfield box:
<td class="answer">
<input type="text" name="Answer1" value='<?php echo $obj["Answer1"]; ?>' /></td>
<td class="answer">
<input type="text" name="Answer2" value='<?php echo $obj["Answer2"]; ?>' /></td>
<td class="answer">
<input type="text" name="Answer3" value='<?php echo $obj["Answer3"]; ?>' /></td>
<td class="answer">
<input type="text" name="Answer4" value='<?php echo $obj["Answer4"]; ?>' /></td>
My update button code :
if(isset($_POST["update_question"]))
{
$Question_Id=$_POST["update_question"];
$Question_Name=$_POST["Question_Name"];
$Answer1=$_POST["Answer1"];
$Answer2=$_POST["Answer2"];
$Answer3=$_POST["Answer3"];
$Answer3=$_POST["Answer4"];
$update_question="UPDATE `tblquestions` SET `Question_Name`='".$Question_Name."', `Answer1`='".$Answer1."', `Answer2`='".$Answer2."', `Answer3`='".$Answer3."', `Answer4`='".$Answer4."',`ModifiedDate`=NOW() WHERE `Question_Id`='".$Question_Id."'";
$update_result=mysqli_query($con,$update_question);
if($update_result)
{
echo "<script> window.location.href='question.php?msg=sucmsg';</script>";
}
else
{
echo "<script> window.location.href='question.php?msg=errmsg';</script>";
}
}
<button type="submit" name="update_question" class="button" value="<?php echo $obj["update_question"]; ?>">Update</button>
When i enter all the field value , and when i press nothing update in my database.Thanks in advance !

You miss these fields in the form:
<input type="hidden" name="Question_Id" value='<?php echo $obj["Question_Id"]; ?>' /></td>
//just to set any value inside to update_question:
<input type="hidden" name="update_question" value='1' /></td>
Change also the button this way:
<input type="submit" class="button">Update</input>
Then in the script:
if(isset($_POST["update_question"]))
{
$Question_Id=$_POST["Question_Id"];
...
}

There's no update_question column in your table, that's the name of the submit button. The column name is Question_Id, so you should use $obj['Question_Id'] instead of $obj['update_question'].

Related

Update database from inserted table fields

I have made a table with editable fields and i have to add functionality to the update button. I have looked up many posts but cant seem to figure out how it works.
Heres what i have at this moment:
<?php
if (isset($_GET['update'])) {
$query = mysql_query("UPDATE iekartas SET
iernosauk='$Ierices_Nosaukums', tips='$Tips', razotajs='$Razotajs',
izgatdat='$Izgatavosanas_datums', adrese='$Adrese' where id='$Iekartas_ID'", $connection);
}
$query = mysql_query("select * from iekartas", $connection);
while ($row = mysql_fetch_array($query)) {
echo "<b><a href='iekartas.php?update={$row['Iekartas_ID']}'>{$row['Ierices_Nosaukums']}</a></b>";
echo "<br />";
}
?>
<tr>
<form action="ierices.php" method="post">
<td><input class="checkbox" type="checkbox" id="<?php echo $row['Iekartas_ID'] ?>" name="id[]"></td>
<td> <input type="text" name="iernosauk" value=" <?php echo $row["Ierices_Nosaukums"]; ?>"></td>
<td> <input type="text" name="tips" value=" <?php echo $row["Tips"]; ?>"></td>
<td> <input type="text" name="razotajs" value=" <?php echo $row["Razotajs"]; ?>"></td>
<td> <input type="text" name="izgatdat" value=" <?php echo $row["Izgatavosanas_datums"]; ?>"></td>
<td> <input type="text" name="adrese" value=" <?php echo $row["Adrese"]; ?>"></td>
<td> <input type="hidden" name="id" value=" <?php echo $row["Iekartas_ID"]; ?>"></td>
<?php
$i++;
}
?>
<button type="button" action="update.php" name="updatedb" class="btn btn-danger" id="updatedb" value=update>Atjaunot</button>
</tr>
</form>
Button is client side so your "update.php" won't be triggered when you click on button. What you have to do is change your button type to submit so your form will actually send a POST request when you click on the button and it will call the action on the form (ierices.php)
<form action="ierices.php" method="post">
...
<button type="submit" class="btn btn-danger" id="updatedb">Atjaunot</button>
</form

the referrer relay response or receipt link url is invalid

After transaction got successful at authorize.net SIM method it is not redirecting to my website URL. I am getting the error message
the referrer relay response or receipt link url is invalid
Here is my code of my transaction page which is submitting information. Please let me know my mistake in it.
<!-- Create the HTML form containing necessary SIM post values -->
<form method="post" id="finalform" action="<?php echo $url; ?>" >
<!-- Additional fields can be added here as outlined in the SIM integration guide
at: http://developer.authorize.net -->
<input type='hidden' name='x_login' value='<?php echo $loginID; ?>' />
<input type='hidden' name='x_amount' onkeyup="gethash(this.value);" value='<?php echo $amount; ?>' /><br/>
<input type='hidden' name='x_description' value='<?php echo $description; ?>' />
<input type='hidden' name='x_invoice_num' value='<?php echo $invoice; ?>' /><br/>
<input type='hidden' name='x_fp_sequence' value='<?php echo $sequence; ?>' />
<input type='hidden' name='x_fp_timestamp' value='<?php echo $timeStamp; ?>' />
<input type='hidden' name='x_fp_hash' id="fphash" value='<?php echo $fingerprint; ?>' />
<input type='hidden' name='x_test_request' value='<?php echo $testMode; ?>' />
<input type='hidden' name="x_first_name" value="<?php echo $_REQUEST['fne'];?>" />
<input type='hidden' name="x_last_name" value="<?php echo $_REQUEST['lne'];?>" />
<input type='hidden' name="x_company" value="<?php echo $_REQUEST['orgme'];?>" />
<input type='hidden' name="x_address" value="<?php echo $_REQUEST['adds'];?>" />
<input type='hidden' name="x_city" value="<?php echo $_REQUEST['cty'];?>" />
<input type='hidden' name="x_state" value="<?php echo $_REQUEST['ste'];?>" />
<input type='hidden' name="x_zip" value="<?php echo $_REQUEST['zip'];?>" />
<input type='hidden' name="x_cust_id" value="<?php echo $_REQUEST['cusd'];?>" />
<input type="hidden" name="x_receipt_link_method" value="LINK" >
<input type="hidden" name="x_receipt_link_url" value="http://www.uthstuph.com/payment-success/" >
<input type="hidden" name="x_relay_response" value="TRUE" >
<input type="hidden" name="x_relay_url" value="http://www.uthstuph.com/payment-success" >
<input type="hidden" name="x_phone" value="<?php echo $_REQUEST['phone'];?>"/>
<input type="hidden" name="x_email" value="<?php echo $_REQUEST['email'];?>"/>
<input type="hidden" name="x_billing_zip" value="<?php echo $_REQUEST['x_billing_zip'];?>"/>
<input type="hidden" value="<?php echo $_REQUEST['cno'];?>" autocomplete="off" maxlength="16" name="x_card_num" id="x_card_num" class="input_text"><br/>
<input type="hidden" value="<?php echo $_REQUEST['cexp'];?>" autocomplete="off" maxlength="20" name="x_exp_date" id="x_exp_date" class="input_text">
<input type="hidden" name="x_card_code" value="<?php echo $_REQUEST['ccode'];?>"/>
</form>
<script type="text/javascript">
document.getElementById("finalform").submit();
</script>
IN ACCOUNT SETTING I set
Default Receipt URL : http://www.uthstuph.com/payment-success/
Default Relay Response URL : http://www.uthstuph.com/payment-success/
I have tried both http as well as https.
Thanks in advance.
From the Authorize.net support page:
Error 14 may also occur if you try to submit x_receipt_link_url and
x_relay_url simultaneously, instead of choosing a receipt method.
Remove one of them and they should work. Also, from your Authorize.net account try the following:
To add a valid Response/Receipt URL:
Log into the Merchant Interface at https://account.authorize.net.
Click Account from the main toolbar.
Click Response/Receipt URLs under
Transaction Format Settings.
Click Add URL.
Enter your Response URL.
Click Submit

Using content from different sources on a page

I have a page with mixed sources of content. The top half of it is hard coded html with values echo'd from a db like so:
Part Number: <input type="text" name="pn" size="25" id="1" value="<?php
echo "$STH->pn"; ?>"/>
Part Nomenclature: <input type="text" id="partnomen" name="part_nomenclature"
size="35" value="<?php echo "$STH->part_nomenclature"; ?>"/>
Quantity:<input type="text" name="qty" size="3" value="<?php echo "$STH->qty";
?>"/><br />
Serial Number <input type="text" name="sn" size="25" value="<?php echo "$STH->sn";
?>"/>
ATA Code: <input type="text" name="ata" size="12" value="<?php echo "$STH->ata"; ?>"/>
Control Order: xxxxxx
Engine Model: xxxxxxxx<br />
Engine Serial Number: xxxxxxxx
Removed From A/C Serial# <input type="text" name="acsn" value="<?php echo
"$STH->acsn"; ?>"/>
TT / TC: ___________________-->
<input type="hidden" name="db_date" value="<?php echo "$STH->db_date"; ?>"/>
<h3 id="addinfo">Reason For Workorder: </h3>
The middle contains html and values that are both echo'd onto the page:
echo "
<div id='addlinfo'>
<input type='hidden' name='wo_id' value='$wo_id'/>
Sequence<input type='text' name='sel_id[]' size='1' value='$i'/>
Repair ID:<input type='text' name='repair_id[]' size='1'
value='$STH->repair_id'readonly/>
Part Nomenclature: <input type='text' name='' size='35'
value='$STH->part_nomenclature'readonly/>
Repair Name:<input type='text' name='repair_name[]' size='20'
value='$STH->repair_name' readonly/><br />
Location: <input type='text' name='location[]' size='20' value='$STH->location'
readonly/>
Description:<br /> <textarea id='' rows='5' cols='100' name='description[]'
id='text'>$STH->description</textarea>
</div>";
The bottom half is pulled in from a separate php page using a jquery ajax call like so:
$(document).ready(function(){
$('#button1').click(function(){
$.ajax({
url: 'http://localhost/php_site_copy/process.php',
type: 'POST',
data: {part_name: $('#partnomen').val()},
success: function(msg){
$('#result').html(msg);
}
}); //event handler
});
});
<div id="result"></div><br />
<button id="button1">Add Repairs</button>
The goal here is to collect all of the data displayed into a $_POST from the page but I'm finding that I only get part of the array. The bottom part form elements are not picked up in the post at all and only some of the upper form elements.
You would think that this would work but I'm beginning to think I'm traveling down the wrong road when it comes to mixing content from different sources. Is there a standard that I'm missing or should I just put my nose back to the grindstone?
Edit: to answer quids' question, I'm using Firefox and the form arrangement is like so:
<form action='test_page.php' method='post'/>
<top html inputs/>
<middle inputs/>
<bottom inputs/>
<input type='submit' value='submit'/>
</form>

set $_POST value when radio button is selected

I have a page with some radio buttons and form. When I select one radio button I need its id to be set to $_POST['id'] varible so when I submit the form I can check which radio button was selected and act accordingly. I know I can't do it directly so tried using
onclick="document.getElementById("id").value="'.$row['id'].'"
on radio button but it didn't work.
$d="select * from {$_c['dbprefix']}card where active='1' order by s_sent desc, s_order asc limit 0,{$_c['filtr']['step']}";
$r=mysql_query($d);
if (mysql_num_rows($r)>0) {
echo '<div class="cards">';
echo '<form method="POST">';
$i=0;
while ($row=mysql_fetch_array($r)):
echo '<div class="item">';
echo '<input id="'.$row['id'].'" type="radio" name="id" class="detail">'.$_l['detailtitle'].'</input>';
echo '<label for="'.$row['id'].'" class="itemin" style="height:'.$_c['card']['sy'].'px"><img src="pub/cards/'.$row['id'].'s.jpg" /></lable>';
echo '</div>';
$i++;
if ($i%3==0) echo '<div class="cl-left"></div>';
endwhile;
echo '<div class="cl-left"></div>';
echo '</div>';
}
?>
<div class="dvasl">
<div class="sl1">
<fieldset>
<legend>Saatja andmed</legend>
<table class="info">
<colgroup><col width="12%"><col></colgroup>
<tr>
<th>Nimi:</th>
<td><input type="text" name="item[from_name]" value="<?php echo $ap['set']['from_name']; ?>" class="inpedit"></td>
</tr>
<tr>
<th>Email:</th>
<td><input type="text" name="item[from_email]" value="<?php echo $ap['set']['from_email']; ?>" class="inpedit"></td>
</tr>
</table>
</fieldset>
<fieldset>
<legend>Saaja andmed</legend>
<table class="info">
<colgroup><col width="12%"><col></colgroup>
<tr>
<th>Nimi:</th>
<td><input type="text" name="item[to_name]" value="<?php echo $ap['set']['to_name']; ?>" class="inpedit"></td>
</tr>
<tr>
<th>Email:</th>
<td><input type="text" name="item[to_email]" value="<?php echo $ap['set']['to_email']; ?>" class="inpedit"></td>
</tr>
</table>
</fieldset>
</div>
<div class="sl2">
<fieldset>
<legend>E-kaardi tekst</legend>
<table class="info">
<tr>
<td><textarea name="item[text]" cols="20" rows="8" class="inpedit2"></textarea></td>
</tr>
</table>
</fieldset>
</div>
<div class="cl-left"></div>
</div>
<div class="buttons">
<div class="t2"><input type="submit" value="Vaata kaardi eelvaadet" name="button[nahled]" class="unbutt1"></div>
</div>
<input type="hidden" name="id" value="<?php echo $ap['card']['id']; ?>">
<input type="hidden" name="action" value="itemadd">
</form>
<?php
$k=floor(($i-1)/3);
if ($k<2) echo '<div class="spacer-'.(2-$k).'"></div>';
?>
Its better if you can use a hidden field in the form and update its value with the id of the selected radio button and when the form will be posted you can get its value and more over this after once you changed the value of the hidden field you can access it with javascript also with id attibute and can get it in the post by name attribute
add a hidden field named
<input type="hidden" id="checked_radio" name="checked_radio" value="" />
and then change the value with javascript on click of button
<input type="radio" id="foo" name="foo" onclick="document.getElementById('checked_radio').value=this.value;" />
The value of the selected radio button gets posted, and the name is used to group radio buttons together. (Only one radio button with the specified name can be selected.) Instead of trying to post the value of the id attribute you should add a value attribute and set that. You could set it to the same value as the id attribute, or remove the id attribute completely.
When I select one radio button I need its id to be set to $_POST['id'] variable
You are changing the value, not the id, to change the id use:
onclick="document.getElementById("id").id="<?php echo $row['id'] ?>";
Anyway, I think you should use the name attribute for this.
change this line
echo '<input id="'.$row['id'].'" type="radio" name="id" class="detail">'.$_l['detailtitle'].'</input>';
to
echo '<input id="'.$row['id'].'" type="radio" value="'.$row['id'].'" name="id" class="detail">'.$_l['detailtitle'].'</input>';
when your form submit,you will get the selected id as $_POST['id']

checkbox says only "on" all the time

this is how I have 2 checkbox and I do not want that you should only click on them simultaneously. it must only be possible to click on one at a time!. in the present to when I clicked the news, so it must enter a number in there to write "on". I would like to later be sure it is entered into the database.
the problem is that it appears to say "on" no matter what!?
<form action="#" method="post">
<table>
<tr>
<td>Emne</td>
<td>Vigtigt: <input type="checkbox" name="vigtigt" class="new"> Nyhede: <input type="checkbox" name="nyhede" class="new"></td>
</tr>
<tr>
<td>Title</td>
<td><input type="text" name="title" maxlength="50" class="new"></td>
</tr>
<tr>
<td>Tekst</td>
<td><textarea name="tekst" cols="20" rows="15" class="new"></textarea></td>
</tr>
<tr>
<td><input type="submit" name="opret" value="Opret Blog" class="new"></td>
<td></td>
</tr>
</table>
<?php
if(isset($_POST["opret"]))
{
if($_POST["vigtigt"] != "")
{
echo $_POST["vigtigt"];
echo "<br />";
echo $_POST["nyhede"];
}
elseif ($_POST["nyhede"] != "")
{
echo $_POST["vigtigt"];
echo "<br />";
echo $_POST["nyhede"];
}
else
{
echo "Fejl!";
}
}
?>
</form>
You have to define a value attribute for it to:
<input type="checkbox" name="vigtigt" class="new" value="MyValueHere">
This way you will receive its value when its checked.
Edit:
To have only one selected at a time you will have to use type="radio" and give them the same name and different values.
<input type="radio" name="vigtigt" class="new" value="MyValueHere">
<input type="radio" name="vigtigt" class="new" value="MyOtherValueHere">
The purpose of checkboxes if to provide a group of options from which any number can be selected.
If you want a single option to be selected, use radio buttons (or a select element).
The value attribute (of the checked radio / selected option) determines the value that will be submitted. on is the default value for checkboxes which is used if you forget to specify a specific value.
<label><input type="checkbox" name="foo" value="vigtigt" class="new"> Vigtigt</label>
<label><input type="checkbox" name="foo" value="nyhede" class="new"> Nyhede</label>

Categories