i am poorly trapped and also not getting any proper support from the Godaddy customer care. I have a comment section which is working perfectly on localhost and some other hosting but it is not working on Godaddy hosting. I don't understand, why this only occurs on godaddy.
Here is my html :
<div class="comment-form-container">
<form id="frm-comment">
<div class="input-row">
<input type="hidden" name="comment_id" id="commentId" placeholder="Name" /> <input class="input-field" type="text" name="name" id="name" placeholder="Name" />
</div>
<div class="input-row">
<textarea class="input-field" type="text" name="comment" id="comment" placeholder="Add a Comment"> </textarea>
</div>
<div>
<input type="button" class="btn-submit" id="submitButton" value="Publish" /><div id="comment-message">Comments Added Successfully!</div>
</div>
</form>
</div>
<div id="output"></div>
Here is my script :
function postReply(commentId) {
$('#commentId').val(commentId);
$("#name").focus();
}
$("#submitButton").click(function () {
$("#comment-message").css('display', 'none');
var str = $("#frm-comment").serialize();
$.ajax({
url: "comment-add.php",
data: str,
type: 'post',
success: function (response) {
//var result = eval('(' + response + ')');
//var result = eval('(' + JSON.stringify(response) + ')');
if (response) {
$("#comment-message").css('display', 'inline-block');
$("#name").val("");
$("#comment").val("");
$("#commentId").val("");
listComment();
} else {
alert("Failed to add comments !");
return false;
}
}
});
});
$(document).ready(function () {
listComment();
});
function listComment() {
$.post("comment-list.php",
function (data) {
var data = JSON.parse(data);
var comments = "";
var replies = "";
var item = "";
var parent = -1;
var results = new Array();
var list = $("<ul class='outer-comment'>");
var item = $("<li>").html(comments);
for (var i = 0; (i < data.length); i++)
{
var commentId = data[i]['comment_id'];
parent = data[i]['parent_comment_id'];
if (parent == "0")
{
comments = "<div class='comment-row'>"+
"<div class='comment-info'><span class='commet-row-label'>from</span> <span class='posted-by'>" + data[i]['comment_sender_name'] + " </span> <span class='commet-row-label'>at</span> <span class='posted-at'>" + data[i]['date'] + "</span></div>" +
"<div class='comment-text'>" + data[i]['comment'] + "</div>"+
"<div><a class='btn-reply' onClick='postReply(" + commentId + ")'>Reply</a></div>"+
"</div>";
var item = $("<li>").html(comments);
list.append(item);
var reply_list = $('<ul>');
item.append(reply_list);
listReplies(commentId, data, reply_list);
}
}
$("#output").html(list);
});
}
function listReplies(commentId, data, list) {
for (var i = 0; (i < data.length); i++)
{
if (commentId == data[i].parent_comment_id)
{
var comments = "<div class='comment-row'>"+
" <div class='comment-info'><span class='commet-row-label'>from</span> <span class='posted-by'>" + data[i]['comment_sender_name'] + " </span> <span class='commet-row-label'>at</span> <span class='posted-at'>" + data[i]['date'] + "</span></div>" +
"<div class='comment-text'>" + data[i]['comment'] + "</div>"+
"<div><a class='btn-reply' onClick='postReply(" + data[i]['comment_id'] + ")'>Reply</a></div>"+
"</div>";
var item = $("<li>").html(comments);
var reply_list = $('<ul>');
list.append(item);
item.append(reply_list);
listReplies(data[i].comment_id, data, reply_list);
}
}
}
And I am 100% sure that there is no connectivity problem with database. Please help me out.
here is comment-add.php
<?php
require_once ("db.php");
date_default_timezone_set('Asia/Kolkata');
$commentId = isset($_POST['comment_id']) ? $_POST['comment_id'] : "";
$comment = isset($_POST['comment']) ? $_POST['comment'] : "";
$commentSenderName = isset($_POST['name']) ? $_POST['name'] : "";
$date = date("Y-m-d H:i:s", time());
$sql = "INSERT INTO tbl_comment(parent_comment_id,comment,comment_sender_name,date) VALUES ('" . $commentId . "','" . $comment . "','" . $commentSenderName . "','" . $date . "')";
$result = mysqli_query($conn, $sql);
if (! $result) {
$result = mysqli_error($conn);
}
echo $result;
?>
here is comment-list.php
<?php
require_once ("db.php");
$sql = "SELECT * FROM tbl_comment ORDER BY parent_comment_id asc, comment_id asc";
$result = mysqli_query($conn, $sql);
$record_set = array();
while ($row = mysqli_fetch_assoc($result)) {
array_push($record_set, $row);
}
mysqli_free_result($result);
mysqli_close($conn);
echo json_encode($record_set);
?>
here is db.php
<?php
$conn = mysqli_connect("localhost","xxxxxxxxx","xxxxxxxx","xxxxxxxxxx");
?>
Related
This question already has answers here:
Syntax error due to using a reserved word as a table or column name in MySQL
(1 answer)
Why does this PDO statement silently fail?
(2 answers)
Reference - What does this error mean in PHP?
(38 answers)
Closed 4 years ago.
<?php
//index.php
$connect = new PDO("mysql:host=localhost;dbname=sales", "root", "");
function e_type($connect) {
$output1 = '';
$query = "SELECT * FROM elimo_type ORDER BY type ASC";
$statement = $connect->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
foreach ($result as $row) {
$output1 .= '<option value="' . $row["type"] . '">' . $row["type"] . '</option>';
}
return $output1;
}
function hw_type($connect) {
$output2 = '';
$query = "SELECT * FROM hw_version ORDER BY type ASC";
$statement = $connect->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
foreach ($result as $row) {
$output2 .= '<option value="' . $row["type"] . '">' . $row["type"] . '</option>';
}
return $output2;
}
function sw_type($connect) {
$output3 = '';
$query = "SELECT * FROM sw_version ORDER BY type ASC";
$statement = $connect->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
foreach ($result as $row) {
$output3 .= '<option value="' . $row["type"] . '">' . $row["type"] . '</option>';
}
return $output3;
}
?>
<?php
include 'header.php';
?>
<div class="container">
<h3 align="center">Purchase</h3>
<br />
<h4 align="center">Enter Purchase Details</h4>
<br />
<form method="post" id="insert_form">
<div class="table-repsonsive">
<span id="error"></span>
<table class="table table-bordered" id="item_table">
<tr>
<th>Serial No</th>
<th>Type</th>
<th>Hardware Version</th>
<th>Software Version</th>
<th>Key</th>
<th><button type="button" name="add" class="btn btn-success btn-sm add"><span class="glyphicon glyphicon-plus"></span></button></th>
</tr>
</table>
<div align="center">
<input type="submit" name="submit" class="btn btn-info" value="Insert" />
</div>
</div>
</form>
</div>
</body>
</html>
<script>
$(document).ready(function () {
$(document).on('click', '.add', function () {
var html = '';
html += '<tr>';
html += '<td><input type="text" name="serial_no[]" class="form-control serial_no" /></td>';
html += '<td><select name="e_type[]" class="form-control e_type"><option value="">Select Type</option><?php echo e_type($connect); ?></select></td>';
html += '<td><select name="hw_type[]" class="form-control hw_type"><option value="">Select Hardware Version</option><?php echo hw_type($connect); ?></select></td>';
html += '<td><select name="sw_type[]" class="form-control sw_type"><option value="">Select Software Version</option><?php echo sw_type($connect); ?></select></td>';
html += '<td><input type="text" name="key[]" class="form-control key" /></td>';
html += '<td><button type="button" name="remove" class="btn btn-danger btn-sm remove"><span class="glyphicon glyphicon-minus"></span></button></td></tr>';
$('#item_table').append(html);
});
$(document).on('click', '.remove', function () {
$(this).closest('tr').remove();
});
$('#insert_form').on('submit', function (event) {
event.preventDefault();
var error = '';
$('.serial_no').each(function () {
var count = 1;
if ($(this).val() == '')
{
error += "<p>Enter Serial no at " + count + " Row</p>";
return false;
}
count = count + 1;
});
$('.e_type').each(function () {
var count = 1;
if ($(this).val() == '')
{
error += "<p>Select Type at " + count + " Row</p>";
return false;
}
count = count + 1;
});
$('.hw_type').each(function () {
var count = 1;
if ($(this).val() == '')
{
error += "<p>Select Hardware Version at " + count + " Row</p>";
return false;
}
count = count + 1;
});
$('.sw_type').each(function () {
var count = 1;
if ($(this).val() == '')
{
error += "<p>Select Software Version at " + count + " Row</p>";
return false;
}
count = count + 1;
});
$('.key').each(function () {
var count = 1;
if ($(this).val() == '')
{
error += "<p>Enter Key at " + count + " Row</p>";
return false;
}
count = count + 1;
});
var form_data = $(this).serialize();
if (error == '')
{
$.ajax({
url: "insert.php",
method: "POST",
data: form_data,
success: function (data)
{
if (data == 'ok')
{
$('#item_table').find("tr:gt(0)").remove();
$('#error').html('<div class="alert alert-success">Purchase Details Saved</div>');
}
}
});
} else
{
$('#error').html('<div class="alert alert-danger">' + error + '</div>');
}
});
});
</script>
<?php
//insert.php;
if (isset($_POST["serial_no"])) {
$connect = new PDO("mysql:host=localhost;dbname=sales", "root", "");
$id = uniqid();
for ($count = 0; $count < count($_POST["serial_no"]); $count++) {
$query = "INSERT INTO elimo_purchase
(id,serial_no, e_type, hw_type, sw_type,key)
VALUES (:id,:serial_no, :e_type, :hw_type, :sw_type,:key)";
$statement = $connect->prepare($query);
$statement->execute(
array(
':id' => $id,
':serial_no' => $_POST["serial_no"][$count],
':e_type' => $_POST["e_type"][$count],
':hw_type' => $_POST["hw_type"][$count],
':sw_type' => $_POST["sw_type"][$count],
':key' => $_POST["key"][$count]
)
);
}
$result = $statement->fetchAll();
if (isset($result)) {
echo 'ok';
}
}
?>
I'm getting output as purchase details saved but result is not stored into database.
You need to debug as per below,
Check all the values which you pass in insert query print all and check values.
Then print the query and fire the same query manually and check it was inserted or not
When you're doing an INSERT query, you can't use a fetch function, because it doesn't return any data. That can only be used with SELECT. You need to check the result of $statement->execute().
if(isset($_POST["serial_no"]))
{
$connect = new PDO("mysql:host=localhost;dbname=sales", "root", "");
$id = uniqid();
$query = "INSERT INTO elimo_purchase (id,serial_no, e_type, hw_type, sw_type,key)
VALUES (:id,:serial_no, :e_type, :hw_type, :sw_type,:key)";
$statement = $connect->prepare($query);
for($count = 0; $count < count($_POST["serial_no"]); $count++)
{
if (!$statement->execute(
array(
':id' => $id,
':serial_no' => $_POST["serial_no"][$count],
':e_type' => $_POST["e_type"][$count],
':hw_type' => $_POST["hw_type"][$count],
':sw_type' => $_POST["sw_type"][$count],
':key' => $_POST["key"][$count]
)
)) {
die('not ok');
}
}
echo 'ok';
}
I am new to this so an early sorry if my question useless... :) I want to be able to click on a result of a search output (the same as a dropdown menu except it's with a search bar) I have looked on internet but nothing could interest me. Thank you. PS: the connection of my database is in an other code but that shouldn't be useful.
Here is my code so far :
<body>
<h1>LIVE SEARCH WITH AJAX TEST</h1>
<div class="search">
<input type="search" name="search" id="recherche" class="search" onkeypress="showdiv()">
</div>
<div class="resultat" id="resultat" id="resultat" style="display: none;">
<a>Please continue typing...</a>
<br>
<br>
<br>
<br>
</div>
<script type="text/javascript">
function showdiv() {
document.getElementById("resultat").style.display = "block";
}
</script>
PHP:
<?php
include 'connect.php';
if ($connect->connect_error) {
die("Connection failed: " . $connect->connect_error);
}
if (isset($_GET['motclef'])) {
$motclef = $_GET['motclef'];
$sql = "SELECT name FROM smartphone WHERE name LIKE '%" . $motclef . "%' LIMIT 5";
$result = $connect->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo $row["name"] . "<br>";
}
} else {
echo "Aucun resultat trouvé pour: " . $motclef;
}
}
?>
jQuery:
$(document).ready(function(){
var delay = (function(){
var timer = 0;
return function(callback, ms){
clearTimeout (timer);
timer = setTimeout(callback, ms);
};
})();
$('#recherche').keyup(function() {
delay(function(){
var recherche = $('#recherche').val();
if (recherche.length > 1) {
$("#resultat").html("");
$.get( "fetch.php", { motclef: recherche} )
.done(function( data ) {
$("#resultat").html(data);
});
}
}, 1000 );
});
});
First-page.php
<?php
global $wpdb;
$supplier_prod_table=$wpdb->prefix.'supplier_product_post';
$sup_query=$wpdb->get_results("SELECT * FROM $supplier_prod_table");
$supp_name_chek=$user_info->user_login;
?>
<div class="form-group">
<input name="keysearch" value="<?php if($supp_name_chek!='') { echo $supp_name_chek; }?>" placeholder="name" id="keysearch" type="text" class="form-control">
<input type="hidden" value="" id="supplier_id">
<span id="loading">Loading...</span> </div>
db page
if(isset($_POST['keysearch']))
{
include('../../../../wp-load.php');
global $wpdb;
$search = $_POST['search'];
$table_name= $wpdb->prefix.'users';
$data = $wpdb->get_results("SELECT * FROM `$table_name` WHERE `user_nicename` like '%$search%' OR `display_name` like '%$search%'");
foreach($data as $key)
{
$user_id=$key->ID;
$user = new WP_User( $user_id );
$role=$user->roles[0];
if($role=='supplier'){
$username = $key->user_login;
?>
<div class="search_show" align="left" id="<?php echo $user_id ?>"><?php echo $username; ?></div>
<?php
// echo "<div class='show' onclick='select_supp()'>".$username."</div>";
}
}
}
JS Code
jQuery(document).ready(function(){
jQuery('#keysearch').on('keyup', function(){
var ajax_search_url=search_url;
var key = jQuery('#keysearch').val();
if (key && key.length > 2)
{
jQuery('#loading').css('display', 'block');
jQuery.ajax({
url : ajax_search_url,
type : 'POST',
cache : false,
data : {
keysearch : key,
},
success : function(data)
{
console.log(data)
if (data)
{
jQuery('#loading').css('display', 'none');
jQuery("#search_result").html(data).show();
}
jQuery('#search_result .search_show').click(function() {
var text = jQuery(this).text();
var sid = jQuery(this).attr('id');
jQuery('#keysearch').val(text)
jQuery('#supplier_id').val(sid);
jQuery('#search_result').fadeOut(1000);
});
}
});
}
else
{
jQuery('#loading').css('display', 'none');
jQuery('#search_result').css('display', 'none');
}
});
});
I have written same code at one machine and it is working fine but on other machine same code is giving error unexpected end of input. This is driving me crazy as why it is happening. Anybody who can help, please. These are my files with which I am working.
edit: I am making a small online test application for learning purpose. As the test start, the first question appears, on clicking next button the url changes to what it should be but next question does not appear and the error in the console says unexpected end of input. Since all my brackets are ok, I am not able to find error. Please help!!
TestStart.php
<?php
session_start();
if(isset($_SESSION['TestId']))
{
$TestId = $_SESSION['TestId'];
}
include('Config.php');
include('Reference.php');
$query = "select * from testquestions where testid='".$TestId."'";
$res = mysql_query($query);
if(mysql_num_rows($res) > 0)
{
$z = array();
while($fetch = mysql_fetch_array($res))
{
$z[]=$fetch['QId'];
}
$y = implode(",", $z);
$_SESSION['QIds']=$z;
}
else{
echo mysql_error();
}
?>
<body>
<div class="container">
<div class="row">
<div class="col-md-12" id="resultDiv">
<div class="col-md-12" id="qtext"></div>
<div class="col-md-12">
<div class="col-md-3">
<div class="col-md-12">
<input type="radio" id="optionA"name="options" value="A"><span id="optA"></span>
</div>
<div class="col-md-12">
<input type="radio" id="optionB" name="options" Value="B"><span id="optB"></span>
</div>
</div>
<div class="col-md-3">
<div class="col-md-12">
<input type="radio" id="optionC" name="options" value="C"><span id="optC"></span>
</div>
<div class="col-md-12">
<input type="radio" id="optionD" name="options" value="D"><span id="optD"></span>
</div>
</div>
</div>
<div id="nextbuttondiv"></div>
</div>
</div>
</div>
<script>
$(document).ready(function(){
<?php
if(isset($_GET['qno'])&&isset($_GET['qindex']))
{
$qno = $_GET['qno'];
$qindex = $_GET['qindex'];
}
else{
$qno = '1';
$qindex = '0';
}
?>
var qno = <?php echo $qno;?>;
var qindex = <?php echo $qindex;?>;
var qidsarrCm = '<?php echo $y;?>';
var arrQid = qidsarrCm.split(",");
var totalQuestions = arrQid.length;
$.ajax({
type : "post",
url : "GetQuestionForTest.php",
data : {
"quId" : arrQid[qindex]
},
dataType : "json",
success : function(data){
alert('xy');
console.log(data);
$.each(data, function(){
var qText = this.questiontext;
var optionA = this.OptionA;
var optionB = this.OptionB;
var optionC = this.OptionC;
var optionD = this.OptionD;
var nxtBtn = this.NextButton;
$('#qtext').text(qText);
$('#optA').text(optionA);
$('#optB').text(optionB);
$('#optC').text(optionC);
$('#optD').text(optionD);
$('#nextbuttondiv').html(nxtBtn);
});
},
error: function(data, statusCode, xhr){
alert(statusCode);
console.log(data);
console.log(xhr);
}
});
$('input[type=radio]').on('click',function(){
$('.nxtbtn').removeAttr('disabled');
});
$('body').on('click','.nxtbtn', function(){
$.ajax({
type : "post",
url : "SaveTestAnswers.php",
data : {
"qid" : arrQid[qindex],
"ansId" : $('input[name=options]:checked').val(),
"stuId" : <?php echo $_SESSION['CurrentUser'];?>,
"testId" : <?php echo $TestId;?>
},
dataType : "json",
success : function(data){
if(data.toString() == "true"){
qindex = qindex + 1;
qno = qno + 1;
if(qno > totalQuestions){
window.location.href="TestFinish.php";
}
else{
window.location.href="TestStart.php?qno="+qno+"&qindex="+qindex;
}
}
else{
alert(data + "Please resubmit the answer");
}
},
error : function(data, statusCode, xhr){
alert(statusCode);
console.log(data);
console.log(xhr);
}
});
});
});
</script>
</body>
GetQuestionForTest.php
<?php
$questionid = $_POST['quId'];
include('Config.php');
$query = "select * from questionstable where questionid = '".$questionid."'";
$result = mysql_query($query);
if(mysql_num_rows($result) > 0)
{
$someArray = [];
while($fetch = mysql_fetch_array($result))
{
array_push($someArray,[
'questiontext' => $fetch['questiontext'],
'OptionA' => $fetch['optionA'],
'OptionB' => $fetch['optionB'],
'OptionC' => $fetch['optionC'],
'OptionD' => $fetch['optionD'],
'NextButton' => '<button class="btn btn-success nxtbtn" disabled >Next</button>'
]);
}
$someJSON = json_encode($someArray);
echo $someJSON;
}
else{
echo mysql_error();
}
?>
SaveTestAnswers.php
<?php
$qid = $_POST['qid'];
$ansId = $_POST['ansId'];
$stuId = $_POST['stuId'];
$testId = $_POST['testId'];
include('Config.php');
$query = "insert into testattemptedanswers(StudentId,TestId,QuestionId,AnswerGiven) values('".$stuId."','".$testId."','".$qid."','".$ansId."')";
$res = mysql_query($query);
if($res){
echo 'true';
}
else{
echo 'false'.mysql_error();
}
?>
Missing quotes -
var qno = <?php echo $qno;?>;
var qindex = <?php echo $qindex;?>;
Change them to -
var qno = '<?php echo $qno;?>';
var qindex = '<?php echo $qindex;?>';
And here also -
data : {
"qid" : arrQid[qindex],
"ansId" : $('input[name=options]:checked').val(),
"stuId" : '<?php echo $_SESSION['CurrentUser'];?>',
"testId" : '<?php echo $TestId;?>'
},
I am a newbie on ajax. I spend hours with "try and error", but unfortunately without success.
I have a form:
<form id="upload" method="post" name="form">
<input class="datepicker" type="text" name="date" value="<?php echo $date_bes; ?>"/>
<input class="chk" name="chk" type="checkbox" value="<?php echo $id_submit; ?>"
<?php if($check == 1){ echo "checked"; }else{ echo "";} ?>/>
<textarea class="remark" name="remark" cols="30" rows="1"><?php echo $remark; ?> </textarea>
<input class="submit" type="image" src="save.jpg"></td>
</form>
Then I my ajax_script.js:
$(document).ready(function() {
$( "#upload" ).on("submit", function() {
var id = $('.chk').val();
var date = $('.datepicker').val();
var chk = $('.chk').prop('checked');
var remark = $('.remark').val();
$.ajax({
type: "POST",
url: "update.php",
data : "{'id':'" + id + "', 'date':'" + date + "', 'chk':'" + chk + "', 'remark':'" + remark + "'}",
success: function (data) {
if(data.success == true)
{
console.log('everything fine');
}
},
error: function(){
console.log('something bad happened');
}
});
});
});
and my update.php
<?php
$id = $_POST['id'];
$date = $_POST['date'];
$chk = $_POST['chk'];
if($chk == true){
$check = 1;
}else{
$check = 0;
}
$remark = $_POST['remark'];
$jahr = substr($date,6,4);
$mon = substr($date,3,2);
$tag = substr($date,0,2);
$date = $jahr.'-'.$mon.'-'.$tag;
echo $id ."<br>".$date."<br>".$chk."<br>".$remark;
require_once('config.php');
$link = mysqli_connect (
MYSQL_HOST,
MYSQL_BENUTZER,
MYSQL_KENNWORT,
MYSQL_DATENBANK
);
if(!$link){
die('Keine Verbindung möglich: ' .mysql_error());
}
$sql = "UPDATE mytable
SET date = '$date', chka ='$chk', remark = '$remark' WHERE id_submits = $id";
$result = mysqli_query( $link, $sql );
echo $sql."<br>";
?>
After push on the bottom, firebug deliver me following:
Can anybody help me - please!
Regards,
Yab86
I think that you do not really need the quotes around the variable in the data section of ajax.
data: {id: id, date: date, chk: chk, remark: remark},
To let AJAX pass data through JQuery you should simply put in the "data" part of the AJAX request your data in this format {'name':name_on_php,'name2':name_on_php2}
I've written "name_on_php" to remind you that the part after the " : " is the one that you GET or POST on your php page.
Hope it helped :)
I have a table with content comming from a database. Now i tryed to realize a way to (a) delete rows from the table (b) edit the content of the row "on the fly". (a) is working perfectly (b) makes my head smoking!
Here is the complete Mootools Code:
<script type="text/javascript">
window.addEvent('domready', function() {
var eDit = $('edit_hide');
eDit.slide('hide');
var del = new Request.HTML(
{
url: 'fuss_response.php',
encoding: 'utf-8',
update: eDit,
onComplete: function(response)
{
eDit.slide('in');
}
});
$$('input.delete').addEvent( 'click', function(e){
e.stop();
var aID = 'delete_', bID = '';
var deleteID = this.getProperty('id').replace(aID,bID);
new MooDialog.Confirm('Soll der Termin gelöscht werden?', function(){
del.send({data : "id=" + deleteID});
}, function(){
new MooDialog.Alert('Schon Konfuzius hat gesagt: Erst denken dann handeln!');
});
});
var edit = new Request.HTML(
{
url: 'fuss_response_edit.php',
update: eDit,
encoding: 'utf-8',
onComplete: function(response)
{
$('sst').addEvent( 'click', function(e){
e.stop();
safe.send();
});
}
});
var safe = new Request.HTML(
{
url: 'termin_safe.php',
encoding: 'utf-8',
update: eDit,
onComplete: function(response)
{
}
});
$$('input.edit').addEvent( 'click', function(e){
e.stop();
var aID = 'edit_', bID = '';
var editID = this.getProperty('id').replace(aID,bID);
edit.send({data : "id=" + editID});
$('edit_hide').slide('toggle');
});
});
</script>
Here the PHP Part that makes the Edit Form:
<?php
$cKey = mysql_real_escape_string($_POST['id']);
$request = mysql_query("SELECT * FROM fusspflege WHERE ID = '".$cKey."'");
while ($row = mysql_fetch_object($request))
{
$id = $row->ID;
$name = $row->name;
$vor = $row->vorname;
$ort = $row->ort;
$tel = $row->telefon;
$mail = $row->email;
}
echo '<form id="termin_edit" method="post" action="">';
echo '<div><label>Name:</label><input type="text" id="nns" name="name" value="'.$name.'"></div>';
echo '<div><label>Vorname:</label><input type="text" id="nvs" name="vorname" value="'.$vor.'"></div>';
echo '<div><label>Ort:</label><input type="text" id="nos" name="ort" value="'.$ort.'"></div>';
echo '<div><label>Telefon:</label><input type="text" id="nts" name="telefon" value="'.$tel.'"></div>';
echo '<div><label>eMail:</label><input type="text" id="nms" name="email" value="'.$mail.'"></div>';
echo '<input name="id" type="hidden" id="ids" value="'.$id.'"/>';
echo '<input type="button" id="sst" value="Speichern">';
echo '</form>';
?>
And last the Code of the termin_safe.php
$id = mysql_real_escape_string($_POST['id']);
$na = mysql_real_escape_string($_POST['name']);
$vn = mysql_real_escape_string($_POST['vorname']);
$ort = mysql_real_escape_string($_POST['ort']);
$tel = mysql_real_escape_string($_POST['telefon']);
$em = mysql_real_escape_string($_POST['email']);
$score = mysql_query("UPDATE fuspflege SET name = '".$na."', vorname = '".$vn."', ort = '".$ort."', telefon = '".$tel."', email = '".$em."' WHERE ID = '".$id."'");
As far as i can see the request does work but the data is not updated! i guess somethings wrong with the things posted
For any suggestions i will be gladly happy!
PS after some comments: I see the problem in this part:
var edit = new Request.HTML(
{
url: 'fuss_response_edit.php',
update: eDit,
encoding: 'utf-8',
onComplete: function(response)
{
$('sst').addEvent( 'click', function(e){
e.stop();
safe.send();
});
}
});
The "Edit" request opens the form with the prefilled input fields and then attaches a click event to the submit button which should call a new request when clicked.
This third request i fail to pass the data of the input fields. i tried to get the value of each field like this:
var name = $('nns').getProperty('value');
and pass it this way
.send({data : "name=" + name});
did not work so far
PPS:
as requested the code that makes the html from main site
<?php $request = mysql_query("SELECT * FROM fusspflege");
echo '<form id="fusspflege" method="post" action="">';
echo '<table class="fuss_admin">';
echo '<tr><th>Name</th><th>Vorname</th><th>Ort</th><th>Telefon</th><th>eMail</th><th>Uhrzeit</th><th>Datum</th><th></th><th></th></tr>';
echo '<tr><td colspan=8 id="upd"></td></tr>';
while ($row = mysql_fetch_object($request))
{
$id = $row->ID;
$name = $row->name;
$vor = $row->vorname;
$ort = $row->ort;
$tel = $row->telefon;
$mail = $row->email;
$dat = $row->datum;
$uhr = $row->uhrzeit;
echo '<tr><td>'.$name.'</td><td>'.$vor.'</td><td>'.$ort.'</td><td>'.$tel.'</td><td>'.$mail.'</td><td>'.$uhr.'</td><td>'.$dat.'</td>';
echo '<td><input id="delete_'.$id.'" class="delete" type="button" value="X"></td>';
echo '<td><input id="edit_'.$id.'" class="edit" type="button" value="?"></td>';
echo '</tr>';
}
echo '</table>';
echo '</form>';
echo '<div id="edit_hide"></div>';
?>
UPDATE:
<form action="" method="post" id="termin_edit">
<div>
<label>
Name:
</label>
<input type="text" value="NAME" name="name" id="nns">
</div>
<div>
<label>
Vorname:
</label>
<input type="text" value="Marianne" name="vorname" id="nvs">
</div>
<div>
<label>
Ort:
</label>
<input type="text" value="MArkt Wald" name="ort" id="nos">
</div>
<div>
<label>
Telefon:
</label>
<input type="text" value="" name="telefon" id="nts">
</div>
<div>
<label>
eMail:
</label>
<input type="text" value="info#rudolfapotheke.de" name="email" id="nms">
</div>
<input type="hidden" value="115" id="ids" name="id">
<input type="button" value="Speichern" id="sst">
</form>
Update:
This is the mootools script based on the form you gave me that should work with your html:
$('sst').addEvent('click', function(event) {
var data;
event.stop();
var myInputEl = $$('#termin_edit input');
for(var i=0; i<myInputEl.length; i++){
if(i == 0)
data = myInputEl[i].name + "=" + myInputEl[i].value;
else
data += "&" + myInputEl[i].name + "=" + myInputEl[i].value;
}
myRequest.send(data);
});
Also add alert to your Request call back for the edit just to test if the ajax worked:
onSuccess: function(responseText) {
alert("done! " + responseText);
},
onFailure: function() {
alert("failed");
}
On the php side create a new PHP file and put the following in it and have ajax target it:
<?php
print_r($_POST);
?>
The Ajax should return the $_POST array in the alert box.