my php page use ajax to send a request to the other page, but somehow the request seems cannot be sent, I have test update_ok.php and should be ok with those code, I think the problem is from sending the request by the ajax. the code as following, please help me out bro.
update.php
<?php
<table>
<tr class="item">
<form action="" method="POST" name="form" id="form">
<input name="id" type="hidden" class="normalinput" id="id" value="<?php echo $row_result2["id"];?>">
<input name="gp_name" type="hidden" class="normalinput" id="gp_name" value="<?php echo $row_result2["gp_name"];?>">
<input name="city" type="text" class="normalinput" id="city" size="6" value="<?php echo $row_result2["city"];?>"></td>
<td align="center"><input name="arrange" type="text" class="normalinput" id="arrange" size="10" value="<?php echo $row_result2["arrange"];?>"></td>
<td align="center"><input name="qua" type="text" class="normalinput" id="qua" size="1" value="<?php echo $row_result2["qua"];?>"></td>
<td align="center">
<input name="id" type="hidden" class="normalinput" id="id" value="<?php echo $row_result2["id"];?>">
<input name="action" type="hidden" id="action" value="update">
<input type="button" name="button" value="Update" onClick="update(form);"></td>
<td align="center">
<input name="id" type="hidden" class="normalinput" id="id" value="<?php echo $row_result2["id"];?>">
<input type="button" name="Submit" value="Delete" onClick="window.location.href='delete.php?id=<?php echo $row_result2['id'];?>'" />
</td>
</form>
</tr><?php }?>
</table>
index.js
function update(form){
var xml;
if(window.ActiveXObject){
xml=new ActiveXObject('Microsoft.XMLHTTP');
}else if(window.XMLHttpRequest){
xml=new XMLHttpRequest();
}
var id=form.id.value;
var city=form.city.value;
var gp_name=form.gp_name.value;
var arrange=form.arrange.value;
var qua=form.qua.value;
xml.open("GET","update_ok.php?id="+id+"&city="+city+"&gp_name="+gp_game+"&arrange="+arrange+"&qua="+qua,true);
xml.onreadystatechange=function(){
if(xml.readyState==4&&xml.status==200){
var msg=xml.responseText;
if(msg==1){
alert("Update succeed!!");
location.href='index.php';
}else{
alert("Update False");
return false;
}
}
}
xml.send(null);
}
update_ok.php
<?php
header("Content-Type: text/html; charset=utf-8");
include_once("conn/connMysql.php");
$id=$_GET['id'];
$gp_name=$_GET['gp_game'];
$arrange=$_GET['arrange'];
$city=$_GET['city'];
$qua=$_GET['qua'];
$sql=mysql_query("update gp_info set gp_name = '$gp_name', city = '$city', qua = '$qua', arrange = '$arrange' where id=".$id);
if($sql){
$reback=1;
}else{
$reback=0;
}
echo $reback;
?>
Related
Basically, i got a form/submit form, but it doesn't post to my site since it's a paypal payment gateway but i need a value from one of the text input fields how can i accomplish this without post/get? I heard you can do it with JS, i tried some JS code but it didn't really work
PAYPAL_URL is a defined variable in config_payment.php that's just a PayPal URL.
My code:
<form action="<?php echo PAYPAL_URL; ?>" method="post">
<div class="inform">
<fieldset>
<div class="fakeform">
<table class="aligntop">
<tbody>
<tr>
<th scope="row">Username</th>
<td><input class="payment-field" id="username" type="text" name="username" value="" maxlength="80"></td>
</tr>
<tr>
<th scope="row">User ID</th>
<td><input class="payment-field" id="userid" type="text" name="userid" value="<?php echo $pun_user['id'] ?>" maxlength="80"></td>
</tr>
<tr>
<th scope="row">Email</th>
<td><input class="payment-field" id="email" type="email" name="email" value="" maxlength="80"></td>
</tr>
<tr>
<th scope="row">Plan</th>
<td>
<select name="validity" onchange="getSubsPrice(this);" class="payment-field">
<option value="1" selected="selected">1 Month - $20</option>
</select>
</td>
</tr>
<script type="text/javascript">
var getuserid=document.getElementById('userid').value;
</script>
<?php
$phpVar = "<script>document.writeln(getuserid);</script>";
?>
<!-- Identify your business so that you can collect the payments -->
<input type="hidden" name="business" value="<?php echo PAYPAL_ID; ?>">
<!-- Specify a subscriptions button. -->
<input type="hidden" name="cmd" value="_xclick-subscriptions">
<!-- Specify details about the subscription that buyers will purchase -->
<input type="hidden" name="item_name" value="<?php echo $itemName; ?>">
<input type="hidden" name="item_number" value="<?php echo $itemNumber; ?>">
<input type="hidden" name="currency_code" value="<?php echo PAYPAL_CURRENCY; ?>">
<input type="hidden" name="a3" id="paypalAmt" value="<?php echo $itemPrice; ?>">
<input type="hidden" name="p3" id="paypalValid" value="1">
<input type="hidden" name="t3" value="M">
<!-- Custom variable user ID -->
<input type="hidden" name="custom" value="<?php echo $phpVar; ?>">
<!-- Specify urls -->
<input type="hidden" name="cancel_return" value="<?php echo PAYPAL_CANCEL_URL; ?>">
<input type="hidden" name="return" value="<?php echo PAYPAL_RETURN_URL; ?>">
<input type="hidden" name="notify_url" value="<?php echo PAYPAL_NOTIFY_URL; ?>">
</div>
</tbody>
</table>
<div class="centered">
<input class="buy-btn" type="submit" value="Buy Subscription">
</div>
</div>
</fieldset>
</div>
</div>
</div>
</form>
As you can see i tried some JS and PHP merging, but it's still 0 when i retrieve it and post it
<script type="text/javascript">
var getuserid=document.getElementById('userid').value;
</script>
<?php
$phpVar = "<script>document.writeln(getuserid);</script>";
?>
Please if anyone can point out what im doing wrong, im eternally greatful thanks.
PHP runs before any JavaScript executes so what you want to do ins not possible.
Seems like you want the value to update another field if it changes.
<input type="hidden" name="custom" value="<?php echo $pun_user['id'] ?>">
and add a simple script
document.querySelector("#userid").addEventListener("change", function(){
document.querySelector('[name="custom"]').value = this.value;
});
Simpler solution, get rid of the hidden element and rename the userid field.
<td><input class="payment-field" id="userid" type="text" name="custom" value="<?php echo $pun_user['id'] ?>" maxlength="80"></td>
A better approach in my opinion would be to use your server as the middle man between the 'User' and 'PayPal'.
That is, instead of the User submitting directly to PayPal, you could have the User submit to your server instead. With that, you have access to that input field you really wanted and you're able to also validate that form.
Finally, your server would resubmit the same request to PayPal, receive the response, perform other necessary operations, and send it back to the User.
i.e
User -- PayPal request ---> Server
Server -- validate form, get that input field you want, resubmit request ---> PayPal
PayPal -- PayPal response---> Server
Server -- perform some operations i.e. saving to database, send PayPal response---> User
This is my controller:
function update_agenda() {
$id = $this->input->post['did'];
$this->load->model('agenda_model');
$data = array(
'nama' => $this->input->post('did'),
'keterangan' => $this->input->post('dketer')
);
($this->agenda_model->update($id, $data))
}
When I click button Save, it won't change anything. How can I fix this problem?
<td>
<input type ="checkbox" id="haha" class=checkbox1 name="checklist" value=<?php echo $agenda->id; ?>> <?php echo $agenda->id; ?>
</td>
<td>
<input type="text" id="hide" name="did" value="<?php echo $agenda->id; ?>">
</td>
<td>
<input type="text" name="dnama" id="nama_" value="<?php echo $agenda->nama; ?>" disabled />
</td>
<td>
<input type="text" name="dketer" id="ket_" value="<?php echo $agenda->keterangan; ?>" disabled>
</td>
<?php }?>
</td>
</tr>
</table>
<button onclick="saveUpdate()"> Save </button>
This is my model:
function update ($id,$data){
$this->db->where('id', $id);
$this->db->update('agenda', $data);
}
Here is my saveUpdate function
i hope this helpyou
view.php
<td>
<input type ="checkbox" id="haha" class=checkbox1 name="checklist" value=<?php echo $agenda->id; ?>> <?php echo $agenda->id; ?>
</td>
<td>
<input type="text" id="hide" name="did" value="<?php echo $agenda->id; ?>">
</td>
<td>
<input type="text" name="dnama" id="nama_" value="<?php echo $agenda->nama; ?>" disabled />
</td>
<td>
<input type="text" name="dketer" id="ket_" value="<?php echo $agenda->keterangan; ?>" disabled>
</td>
<?php }?>
</td>
</tr>
</table>
<button onclick="saveUpdate()"> Save </button>
controller.php
function update_agenda() {
$this->load->model('agenda_model');
$this->form_validation->set_rules('did', 'Did', 'trim|required|xss_clean');
$this->form_validation->set_rules('dketer', 'Dketer', 'trim|required|xss_clean');
if ($this->form_validation->run() === FALSE){
echo 'ERROR';
}
else{
$id = $this->input->post['did'];
$data = array(
'nama' => $this->input->post('did'),
'keterangan' => $this->input->post('dketer')
);
$this->agenda_model->update($id, $data);
$data['agenda'] = $this->agenda_model->get_data($id);
$this->load->view('formsuccess', $data);
}
}
model.php
function update($id, $data){
$this->db->where('id', $id);
$this->db->update('table', $data);
}
function get_data($id){
$this->db->where('id', $id);
return $this->db->get('table')->row();
}
I have radio buttons with name as 2d array in a while loop.I want to show the number of radio buttons checked when its clicked.
my radio buttons
$n=0;
while($row= mysqli_fetch_row($rs)){?>
<form name="myfm" id="myfm" method="post" action="Quizn.php">
<table width=100%> <tr> <td width=30><td></td></td></tr> <table border=0>
<?php $n=$n+1; ?>
<tr><td>Question <?php echo $n.") "; echo $row[2]; ?></td></tr>
<tr><td class=style8>A. <input type="radio" name="ques['<?php echo $n; ?>'][]" value=1><?php echo $row[3]; ?></td></tr>
<tr><td class=style8>B. <input type="radio" name="ques['<?php echo $n; ?>'][]" value=2><?php echo $row[4];?></td></tr>
<tr><td class=style8>C. <input type="radio" name="ques['<?php echo $n; ?>'][]" value=3><?php echo $row[5];?></td></tr>
<tr><td class=style8>D. <input type="radio" name="ques['<?php echo $n; ?>'][]" value=4><?php echo $row[6];?></td></tr>
<input type="hidden" name="ques['<?php echo $n; ?>'][]" value="0" />
<input type="hidden" value="<?php echo $row[0]; ?>" name="qid[]" />
<?php }
echo "<tr><td><input type=submit name=submit id='result' value='Get Result'></form>";
?>
</table></table>
</form>
<p>Clicked:</p> <p id="clicked">0</p>
javascript
$("input:radio").click(function () {
var totalRd = $('table').find(':not(.pend) > input:radio:checked').length;
$("#totalRd .rd-count").html(totalRd);
});
Please help me if you know the solution.
Thankyou
With some assumption, try like this
<?php
if(isset($_POST['submit'])){
echo "<pre>";
print_r($_POST);
echo "</pre>";
}
?>
<form method="post" action="">
<?php for ($i=0; $i < 3 ; $i++) { ?>
<br>
A<input type="radio" name="ques[<?php echo $i;?>][]" value=1>
B<input type="radio" name="ques[<?php echo $i;?>][]" value=2>
C<input type="radio" name="ques[<?php echo $i;?>][]" value=3>
D<input type="radio" name="ques[<?php echo $i;?>][]" value=4>
<?php } ?>
<br>
<input type="submit" name="submit" value="submit">
</form>
http://screencast.com/t/HEVSPR7yVR
http://screencast.com/t/rQSpXiJAMg
I suggest don't use array here name="ques[<?php echo $i;?>][]" just use name="ques[<?php echo $i;?>]" for clean and clear
Try this
$(":radio").on( 'click', function() {
count = $(':radio:checked').length;
alert(count);
});
My Ckeditor post variable returns as having the input I need. When I insert it into the column everything inserts, BUT the ckeditor data.
This is my function to insert:
public function SubmitReply() {
$query = <<<SQL
INSERT INTO {$this->tprefix}posts(guid,poster,content,postdate)
VALUES(:guid,:poster,:content,:postdate)
SQL;
$resource = $this->db->db->prepare( $query );
$resource->execute( array (
':guid' => $_POST['guid'],
':poster' => $_POST['poster'],
':content' => htmlspecialchars($_POST['editor1']),
':postdate' => $_POST['postdate'],
));
return $resource->rowCount();
}
And my form has:
<form id="reply" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="hidden" name="process" id="process" value="DEF_FORUM_SUBMIT_REPLY">
<input type="hidden" name="guid" id="guid" value="<?php DEF_TOPIC_NAME($_GET['topic']); ?>">
<input type="hidden" name="poster" id="poster" value="<?php echo $_SESSION['key']['userid']; ?>">
<input type="hidden" name="postdate" id="postdate" value="<?php echo gmdate('Y-m-d H:i:s'); ?>">
<textarea name="editor1" id="editor1" rows="10" cols="80"></textarea>
</form>
<p style="text-align:center; margin-top:10px;">
<input type="submit" class="btn btn-success" value="Post Reply" id="submit_reply">
</p>
It seems that the post for editor1 actually isn't passing now. I have no clue as to why at this point.
I have a lot of these forms that I post with PHP. They are under every article in my page, but when I submit the form with these ajax functions it only sends to the first form of the page. Why? I want send these form separately what am I doing wrong?
<script type="text/javascript" >
$(function() {
$(".submit").click(function()
{
var name = $("#name").val();
var comment = $("#comment").val();
var post_id = $("#post").val();
var dataString = 'name='+ name + '&comment=' + comment+ '&post_id=' + post_id;
if(name=='' || comment=='')
{
alert('Please Give Valid Details');
}
else
{
$("#flash").show();
$("#flash").fadeIn(400).html('<img src="images/loading.gif" />Loading Comment...');
$.ajax({
type: "POST",
url: "commenti.php",
data: dataString,
cache: false,
success: function(html){
$("ol#update").append(html);
$("ol#update li:last").fadeIn("slow");
$("#flash").hide();
}
});
}return false;
});
});
<script>
<ol id="update" class="timeline">
</ol>
<div id="flash"></div>
<div >
<form action="#" method="post">
<input type="hidden" id="post" value="<?php echo $post_id; ?>"/>
<input type="hidden" id="name" value="<?php echo $username; ?>"/>
<textarea id="comment"></textarea><br />
<input type="submit" class="submit" value=" Submit Comment " />
</form>
</div>
<ol id="update" class="timeline">
</ol>
<div id="flash"></div>
<div >
<form action="#" method="post">
<input type="hidden" id="post" value="<?php echo $post_id; ?>"/>
<input type="hidden" id="name" value="<?php echo $username; ?>"/>
<textarea id="comment"></textarea><br />
<input type="submit" class="submit" value=" Submit Comment " />
</form>
</div>
<ol id="update" class="timeline">
</ol>
<div id="flash"></div>
<div >
<form action="#" method="post">
<input type="hidden" id="post" value="<?php echo $post_id; ?>"/>
<input type="hidden" id="name" value="<?php echo $username; ?>"/>
<textarea id="comment"></textarea><br />
<input type="submit" class="submit" value=" Submit Comment " />
</form>
</div>
First of all, as has been said in the comments, don't use repetead IDs. If you don't intend to use Ids as a unique identifier, use classes.
<ol class="timeline update">
<div id="flash"></div>
<div >
<form action="#" id="form" method="post">
<input type="hidden" class="post" value="<?php echo $post_id; ?>"/>
<input type="hidden" class="name" value="<?php echo $username; ?>"/>
<textarea class="comment"></textarea><br />
<input type="submit" class="submit" value=" Submit Comment " />
</form>
</div>
</ol>
In your javascript code, you are trying to get the id name with var name = $('#name'), right? What name?
Also, try to send your requeste with an array rather than a string.
Something like this:
$(".submit").click(function()
{
var name = $(this).parents('form:input.name').val();
var comment = $(this).parents('form:input.comment').val();
var post_id = $(this).parents('form:input.post').val();
var data = {'name': name,
'comment': comment,
'post_id':post_id},
$.ajax({
type: "POST",
url: "commenti.php",
data: data,
success: function(html){
//do stuff
}
}
Access your variable in PHP with $_POST['varName'];
Hope it helps.