weixin_33688840 2017-10-04 09:26 采纳率: 0%
浏览 3

用于PHP脚本的AJAX

I am pretty new to Web Development and especially AJAX (jquery) and i am facing a problem

I have 3 php scripts

input.php:

<form id="input" action='data.php' method='post'>
<select name="id">
<?php 

require_once('function.php');
$conn = connect();

$sql = "SELECT id,item FROM t1";
$results = mysqli_query($conn, $sql) or die($mysqli->error);
//echo "<form action='data.php' method='post'>";
while($row = $results->fetch_assoc()){
echo "<option value='" . $row['id'] . "'>" . $row['item'] . "</option>";
}
?>

<input type='Submit' value='Auswahl bestätigen'/>

</select>  

data.php

<form action= 'change.php' method='post'>

<?php

$id = $_POST ["id"];
$id = $mysqli->real_escape_string($id);


require_once('function.php');
$conn = connect();


$sql = "SELECT * FROM t1 WHERE id='".$id."'";
//echo $sql;
$results = mysqli_query($conn, $sql);
$row = mysqli_fetch_array($results);

echo "ID: <input type='number' name='id' value='" .$row['id']. "' readonly 
size='5'><br><br>";

echo "Beschreibung: <input type='text' name='beschreibung' 
value='".$row['description']."'><br><br>"; 

echo "Finder: <input type='text' name='finder' required 
value='".$row['contact']."' /><br><br>";

echo "Datum: <input type='date' name='datum' required 
value='".$row['date']."'> <br><br>";

echo "Ort: <input type='text' name='ort' required value='".$row['place']."'> 
<br><br>";

echo "Abgeholt?: <input type='radio' name='abgeholt' value='1' />Ja";
echo            "<input type='radio' name='abgeholt' value='0' 
checked>Nein<br><br>";

echo "Abholdatum: <input type='date'  name='abholdatum' 
value='".$row['retrieve date']."'> <br><br>";

?> 
<input type='Submit' value='Eintrag ändern!' /><br><br>
</form>  

and change.php:

<?php
$id = $_POST ["id"];
$item = $_POST ["gegenstand"];
$description = $_POST ["beschreibung"];
$contact = $_POST ["finder"];
$date = $_POST ["datum"];
$place = $_POST ["ort"];
$retrieved = $_POST ["abgeholt"];
$retrieve_date = $_POST ["abholdatum"];


require_once('function.php');
$conn = connect();




$item = $conn->real_escape_string($item);
$description = $conn->real_escape_string($description);
$contact = $conn->real_escape_string($contact);
$date = $conn->real_escape_string($date);
$place = $conn->real_escape_string($place);
$retrieved = $conn->real_escape_string($retrieved);
$retrieve_date = $conn->real_escape_string($retrieve_date);



$sql ="UPDATE t1

SET description = '$description', contact = '$contact', date = '$date', 
place = '$place', retrieved = '$retrieved' , retrieve_date = 
'$retrieve_date'
WHERE id = '$id'";

//echo $sql;        

if ($conn->query($sql) === TRUE) {
echo "New record created successfully" . "<br>" . "<br>";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();

?>

so my problem:
These scripts are working and I am able to change entries in my db (mariadb) But I want to let them be loaded via AJAX to improve the feel of my site (nobody likes 3 redirects to change something)

I tried it with the jquery $.load function but no joy

<script type="text/javascript">                                                                                     

$(document).ready(function(){
$('#f1').load('input.php');
});
}); 
</script>

so my question is:
Is it possible to join these scripts to cut them down to max. 1 redirect or even better to integrate them via AJAX into the main html page?

ps: sorry for grammar mistakes , english isn't my mother tongue

  • 写回答

1条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 Android URL如何转成视频/音频,可行吗?
      • ¥20 SQL数据查询,子查询
      • ¥15 c++字符串分割问题
      • ¥15 关于#sql#的问题:没有用命令关闭cdc,手动把系统表开启的cdc右键删除了
      • ¥15 vue+uniapp
      • ¥15 android freedom
      • ¥15 使用自定义的类型代替内置类型可行吗
      • ¥15 关于STM32的SPI和ENDAT接口编码器通信的问题
      • ¥15 关于#pdfbox#生成的PDF文件正常,转图片中文乱码的问题,如何解决?
      • ¥15 ADS中有关DAC控件的使用问题