gpt4 book ai didi

php - 使用 php 将我的 sql 数据库上传到我的 html 表单中

转载 作者:行者123 更新时间:2023-11-30 00:19:07 25 4
gpt4 key购买 nike

我需要一些关于这个项目的帮助。我已尽我所能,没有结果,查询表单可以工作,但我需要用我的 sql 表填充它。我只能截屏我的sql,我不知道如何将它放在这里。场景如下:直接上传信息到查询表

在此场景中,我将使用在一个项目中创建的查询表单,以及在另一个项目中使用 SQL 创建的名为查询的表。用户响应必须使用 MySQL 语句上传到查询表中。在 email.php 文件(用于从查询表单发送电子邮件的文件)上添加用于将信息上传到查询表的代码。要测试结果是否已上传到表中,请使用 if...else 语句在屏幕上显示结果是否已上传。添加至少 3 个查询回复。

注意:确保查询表单的字段名称与创建的值变量名称匹配,以确保结果上传到表中。如果上传结果时出现问题,请首先查看字段名称和列出的顺序。

这是我的询问.php:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<?php
$name = $_POST ['name'];
$address = $_POST ['address'];
$city = $_POST ['city'];
$state = $_POST ['state'];
$zip = $_POST ['zip'];
$phone = $_POST ['phone'];
$email = $_POST ['email'];
$major = $_POST ['major'];
$year = $_POST ['year'];
$semester = $_POST ['semester'];
$to="bgoog@mail.nira.edu, ther691@gmail.com"; //an email is sent to your email account and to
$message="To Whom It May Concern, <br>";
$message.="My information is listed below: <br><br>";
$message.="Name: $name<br>";
$message.="Address: $address<br>";
$message.="City: $city<br>";
$message.="State: $state<br>";
$message.="Zip: $zip<br>";
$message.="Phone: $phone<br>";
$message.="Email: $email<br>";
$message.="Major: $major<br><br>";
$message.="I plan to enter in the $semester of $year. <br>";
$message.="Please assist me in this matter.<br><br>";
$message.="Respectfully,<br>";
$message.="B Good<br>";
$subject="University - Inquiry Form";//The subject of the email is �University - Inquiry Form�
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= "From: <therock691@gmail.com>" . "\r\n";//the email should like it was sent from the person contacting University
$response=mail($to,$subject,$message,$headers);
if($response)
{
Echo "Email sent successfully";
}
else //
{
Echo "Error Occured while sending email";
}
$hostname = "localhost";
$username = "vde_bgood";
$password = "s0123456";
$database = "vde_bgood";
$table = "inquiry";
mysql_connect($hostname, $username, $password) or die("Unable to connect to database");
mysql_select_db($database) or die ("Unable to select db");
$fields = "id, name, address, city, state, zip, phone, email, major, semester year";
$values = "'$id', '$name', '$address', '$city', 'state', 'zip', 'phone', 'email', 'major'. 'semester', 'year'";
$query = "INSERT INTO $table ($fields) VALUES ($values)";
$result = mysql_query($query);
if($result)
echo "Thank you for completing the Inquiry Form";
else
echo "Sorry, this is not currently working";
?>
<br>
<br>
<a href='inquiry.html'>Go back to contact form</a></body>
</html>

.HTML 文档:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<script type="text/javascript">
function MM_validateForm()
{ //v4.0
if (document.getElementById)
{
var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
for (i=0; i<(args.length-2); i+=3)
{
test=args[i+2];
val=document.getElementById(args[i]);
if (val)
{
nm=val.name;
if ((val=val.value)!="")
{
if (test.indexOf('isEmail')!=-1)
{
p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
}
else if (test!='R')
{
num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf('inRange') != -1)
{
p=test.indexOf(':');
min=test.substring(8,p);
max=test.substring(p+1);
if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
}
}
}
else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n';
}
}
if (errors) alert('The following error(s) occurred:\n'+errors);
document.MM_returnValue = (errors == '');
}
}
</script>
</head>

<body>
<form action="inquiry.php" method="post" name="form1" id="form1">
<h2>Nira University Enrollment Form</h2>
<table width="500" border="1">
<tr>
<td width="171"><label for="name">Name:</label></td>
<td width="313"><input name="name" type="text" id="name" form="form1" title="name"></td>
</tr>
<tr>
<td width="171"><label for="name">Street Address:</label></td>
<td width="313"><input type="text" name="address" id="address"></td>
</tr>
<tr>
<td width="171"><label for="name">City:</label></td>
<td width="313"><input type="text" name="city" id="city"></td>
</tr>
<tr>
<td width="171"><label for="name">State:</label></td>
<td width="313"><input type="text" name="state" id="state"></td>
</tr>
<tr>
<td width="171"><label for="name">Zip Code:</label></td>
<td width="313"><input type="text" name="zip" id="zip"></td>
</tr>
<tr>
<td width="171"><label for="name">Telephone:</label></td>
<td width="313"><input name="phone" type="text" id="phone" onBlur="MM_validateForm('name','','R','address','','R','city','','R','state','','R','zipcode','','RisNum','phone','','R','email','','RisEmail','major','','R');return document.MM_returnValue"></td>
</tr>
<tr>
<td width="171"><label for="name">Email Address:</label></td>
<td width="313"><input type="text" name="email" id="email"></td>
</tr>
<tr>
<td width="171"><label for="name">Intended Major:</label></td>
<td width="313"><input type="text" name="major" id="major"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td><label for="select">Year:</label></td>
<td><select name="year" id="year" >
<option value="">Select Year</option>
<option value="2014">2014</option>
<option value="2015">2015</option>
<option value="2016">2016</option>
<option value="2017">2017</option>
</select></td>
<label for="select3"></label>
<tr>
<td><label for="select">Semester:</label></td>
<td width="313"><select name="semester" id="semester" title="semester">
<option value="">Select Semester</option>
<option value="Spring">Spring</option>
<option value="Summer">Summer</option>
<option value="Fall">Fall</option>
</select></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td width="171"><input name="submit" type="submit" id="submit" onClick="MM_validateForm('name','','R','address','','R','city','','R','state','','R','zip','','RisNum','phone','','R','email','','NisEmail','major','','R');return document.MM_returnValue" value="Submit"></td>
</tr>
</table>
</form>
</body>
</html>

最佳答案

我什至不知道你应该问我们什么?但是,如果问题出在您的 mysql 查询上,请尝试以下操作:

  $result = mysql_query("INSERT INTO inquiry($fields) VALUES('$values')");

关于php - 使用 php 将我的 sql 数据库上传到我的 html 表单中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23392189/

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