-6ren">
gpt4 book ai didi

php - 添加记录到表 PHP/MySQL

转载 作者:行者123 更新时间:2023-11-30 01:17:05 26 4
gpt4 key购买 nike

所以这应该是一个非常简单的添加到表 PHP/MySQL - 但是由于某种原因我无法开始工作。我尝试过使用引号放置、连接等。但是我认为我需要一些帮助。谢谢

<?php 
//Variables from Form
$Fs = "$_POST[Fs]";
$Ls = "$_POST[Ls]";
$T = "$_POST[T]";
$A = "$_POST[A]";
$Sn = "$_POST[Sn]";
?>

<h2>Add</h2>
<form id="form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

<input name="Fs" type="text" value="First Name" size="20" maxlength="60" onfocus="if (this.value=='First Name') this.value='';"onblur="if (this.value=='') this.value='First Name';"/>
<input name="Ls" type="text" value="Last Name" size="20" maxlength="60"onfocus="if (this.value=='Last Name') this.value='';"onblur="if (this.value=='') this.value='Last Name';" />
<input name="T" type="text" value="Telephone" size="20" maxlength="60" onfocus="if (this.value=='Telephone') this.value='';"onblur="if (this.value=='') this.value='Telephone';"/>
<input name="A" type="text" value="Address" size="20" maxlength="60"onfocus="if (this.value=='Address') this.value='';" onblur="if (this.value=='') this.value='Address';"/>
<input name="Sn" type="text" value="Student Number" size="40" maxlength="40" onfocus="if (this.value=='Student Number') this.value='';" onblur="if (this.value=='') this.value='Student Number';"/>

 <?php 
if(isset($_POST['Submit']))
{

//Conections

$con = mysql_connect("localhost", "root", "root") or die("Error connecting to database: ".mysql_error());
mysql_select_db("assign2") or die(mysql_error());

//Insert Statements

if($Fs != null && $Ls != null && $T != null && $T != null && $A != null && $Sn != null) {
echo "<br><br><br>" . $Fs . " " . $Ls . " " . $T . " " . $A . " " . $Sn ;
mysqli_query($con, "INSERT INTO 'assign2table' (First_Name , Last_Name , Telephone , Address ,Student_Number) VALUES ('$Fs' , '$Ls' . '$T' . '$A' . '$Sn')");
}
else {
echo "Missing Info";

}
}
?>

最佳答案

您在插入查询中使用了 (DOT) (.) 而不是逗号 (,)。

mysqli_query($con, "INSERT INTO 'assign2table' (名字、姓氏、电话、地址、学生编号) 值 ('$Fs'、'$Ls'、'$T'、'$A'、'$Sn ')");

关于php - 添加记录到表 PHP/MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18946892/

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