gpt4 book ai didi

php - 我的 SQL 查询有什么问题?

转载 作者:行者123 更新时间:2023-11-29 05:00:16 24 4
gpt4 key购买 nike

我需要快速查看我的 SQL 查询。已经让我很头疼了。比较我得到的一些建议,我无法找出适合我的 SQL 的格式。

这是我的代码:

$query = "INSERT INTO `[my_db_name]`.`members` (`id` ,`first` ,`last` ,`add1` ,`add2` ,`phone_home` ,`phone_cell` ,`phone_dad` ,`phone_mom` ,`email1` ,`email2`)
VALUES ('NULL' , '".$first."', '".$last."', '".$add1."', '".$add2."', '".$phone_home."', '".$phone_cell."', '".$phone_dad."', '".$phone_mom."', '".$email1."', '".$email2."')";

`mysql_query($query) or die ('Error updating database, Error:' . mysql_error());

提前致谢!

编辑:

目前我有这样的形式:

<table border="0" cellpadding="0" cellspacing="0">

<form enctype="multipart/form-data" method="POST" action="add-member.php">

<tr class="labels">

<td class="f">Add a Member</td>
<td class="l"></td>

</tr>

<tr>

<td class="f"><label for="first">First Name:</label></td>
<td class="l"><input id="first" type="text"/></td>

</tr>


<tr>

<td class="f"><label for="last">Last Name:</label></td>
<td class="l"><input id="last" type="text"/></td>

</tr>

<tr>

<td class="f"><label for="add1">Address 1:</label></td>
<td class="l"><input id="add1" type="text"/></td>

</tr>

<tr>

<td class="f"><label for="add2">Address 2:</label></td>
<td class="l"><input id="add2" type="text"/></td>

</tr>

<tr>

<td class="f"><label for="phone_home">Home Phone:</label></td>
<td class="l"><input id="phone_home" type="text"/></td>

</tr>

<tr>

<td class="f"><label for="phone_cell">Cell Phone:</label></td>
<td class="l"><input id="phone_cell" type="text"/></td>

</tr>

<tr>

<td class="f"><label for="phone_dad">Dad Cell:</label></td>
<td class="l"><input id="phone_dad" type="text"/></td>

</tr>

<tr>

<td class="f"><label for="phone_mom">Mom Cell:</label></td>
<td class="l"><input id="phone_mom" type="text"/></td>

</tr>

<tr>

<td class="f"><label for="email1">Email 1:</label></td>
<td class="l"><input id="email1" type="text"/></td>

</tr>

<tr>

<td class="f"><label for="email2">Email 2:</label></td>
<td class="l"><input id="email2" type="text"/></td>

</tr>

</table>

这是插入查询:

<?php

$first = $_POST['first'];
$last = $_POST['last'];
$add1 = $_POST['add1'];
$add2 = $_POST['add2'];
$phone_home = $_POST['phone_home'];
$phone_cell = $_POST['phone_cell'];
$phone_dad = $_POST['phone_dad'];
$phone_mom = $_POST['phone_mom'];
$email1 = $_POST['email1'];
$email2 = $_POST['email2'];

include ("../lib/login.php");

mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");

mysql_select_db ([dbname]);

$query = "INSERT INTO `[dbname]`.`mem_dir` (`id` ,`first` ,`last` ,`add1` ,`add2` ,`phone_home` ,`phone_cell` ,`phone_dad` ,`phone_mom` ,`email1` ,`email2`)
VALUES (NULL , '$first', '$last', '$add1', '$add2', '$phone_home', '$phone_cell', '$phone_dad', '$phone_mom', '$email1', '$email2')";

mysql_query($query) or die ('Error updating database, Error:' . mysql_error());

echo "Database successfully uploaded with:<br/><ul>
<li>" . $first . "</li>
...
</ul>";

?>

好像提交的是条目,不是提交的值...看腻了看不看。我感谢所有的帮助。谢谢!

编辑(再次):

正如 Salman A 指出的那样,问题实际上是表单,以及每个输入都用“id”而不是“name”标识的事实。

谢谢大家,非常感谢大家的帮助!我想我不正确的 SQL 格式是另一个话题,嗯?

最佳答案

它的形式有气味!全部更改:

<input id="yadayada">

收件人:

<input name="yadayada">
<!-- ^^^^---- you must use the name attribute -->

可选:

  • 表单标签错位;我建议你把 <table><form>里面,而不是相反。
  • 我没有看到 </form><input type="submit"> .
  • 你不需要 multipart/form-data编码,除非您要上传文件。

关于php - 我的 SQL 查询有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1844922/

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