gpt4 book ai didi

javascript - 提交表格并将其发布到主页

转载 作者:行者123 更新时间:2023-11-29 21:00:07 26 4
gpt4 key购买 nike

我有这个表格form image 。提交表单后,个人详细信息将存储到个人表中,书籍详细信息将存储到图书表中。两个表之间通过id建立链接。

$user_query = "INSERT INTO personaldetails(FirstName ,MiddleName,LastName,
Gender,Location,Email,Mobile) VALUES ('$users_firstname',
'$users_middlename', '$users_lastname', '$users_gender','$users_location','$users_email','$users_mobile');";


$result = mysqli_query($mysqli, $user_query);

$user_id = mysqli_insert_id($mysqli);


foreach($_POST['booktitle'] as $key => $bookTitle) {
$bookTitle = mysqli_real_escape_string($mysqli, $bookTitle);
$bookGenre = mysqli_real_escape_string($mysqli, $_POST['bookgenre'][$key]);
$bookWriter = mysqli_real_escape_string($mysqli, $_POST['bookwriter'][$key]);
$bookDescription = mysqli_real_escape_string($mysqli, $_POST['bookdescription'][$key]);

$book_query = "INSERT INTO bookdetails(BookTitle ,BookGenre,BookWriter,
BookDescription, UserId) VALUES('$bookTitle',
'$bookGenre', '$bookWriter', '$bookDescription', '$user_id');";

我的要求是,当我点击发布按钮时,我插入个人详细信息和书籍详细信息的数据应该发布在主页上(相同的Facebook状态更新)

我试图将两个表的数据作为 jason 进行回显,但它正在获取表的整行。

$sql1 = mysql_query("select * from personaldetails");

$sql2 = mysql_query(" select BookTitle,BookGenre,BookWriter,BookDescription from bookdetails INNER JOIN personaldetails ON (bookdetails.UserId = personaldetails.Id)");

echo '{"personaldetails": [';
while($row=mysql_fetch_array($sql1))
{
$id=$row['Id'];
$fname=$row['FirstName'];
$mname=$row['MiddleName'];
$lname=$row['LastName'];
$gender=$row['Gender'];
$location=$row['Location'];
$email=$row['Email'];
$mobile=$row['Mobile'];
echo '
{
"Id":"'.$id.'",
"FirstName":"'.$fname.'"
"MiddleName":"'.$mname.'"
"LastName":"'.$lname.'"
"Gender":"'.$gender.'"
"Location":"'.$location.'"
"Email":"'.$email.'"
"Mobile":"'.$mobile.'"
},';
}
echo ']}';

echo '{"bookdetails": [';
while($row=mysql_fetch_array($sql2))
{

$btitle=$row['BookTitle'];
$bgenre=$row['BookGenre'];
$bwriter=$row['BookWriter'];
$bdescription=$row['BookDescription'];

echo '
{

"BookTitle":"'.$btitle.'"
"BookGenre":"'.$bgenre.'"
"BookWriter":"'.$bwriter.'"
"BookDescription":"'.$bdescription.'"

},';
}
echo ']}';

?>

我有一些想法,我可以通过 jquery 或 ajax 调用 api 来完成,但不知道该怎么做。或者我也可能需要 url 参数。如果您有任何想法,请帮助我。我将不胜感激。

最佳答案

查看您的代码,您需要做很多事情。首先是..停止自己编写 JSON!接下来是您的查询。

$sql1 = mysql_query("select * from personaldetails");

while($row=mysql_fetch_array($sql1)) {
$output['personaldetails'][] = $row;
}

$sql2 = mysql_query(" select BookTitle,BookGenre,BookWriter,BookDescription from bookdetails INNER JOIN personaldetails ON (bookdetails.UserId = personaldetails.Id)");

while($row=mysql_fetch_array($sql2)) {
$output['bookdetails'][] = $row;
}

echo json_encode($output);
?>

关于javascript - 提交表格并将其发布到主页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37308116/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com