제 SQL 쿼리를 간략하게 살펴볼 필요가 있습니다. 벌써 나에게 두통이 닥쳤다. 내가 얻은 조언을 비교해 볼 때, 필자는 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());
감사 :
이 내 코드입니다!
편집 :
<?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>";
?>
이 항목을 제출하는 것 같은데,하지만 값 :이 삽입 쿼리입니다
<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>
:
현재 나는 형태로 이것을 가지고 ... 나는 그것을보고 지켜 보지 못한다. 모든 도움에 감사드립니다. 감사!
EDIT (다시) :
있듯이 Salman A 지적한 문제 대신 "이름"에, 실제로 형성하고, 각 입력에 "ID"로 확인 된 사실이었다 .
모두에게 감사드립니다. 정말 감사드립니다! 내 잘못된 SQL 서식을 다른 주제가 같아요, 응?
동의; 테이블 이름에 '['와 ']'가 없으면 MySQL에서는 작동하지 않습니다. –
당신이 [my_db_name]을 언급하고 있다면, 실제로 SQL에있는 것은 아니며 여기에 표시하는 것입니다. –
테이블 이름과 열 이름은 따옴표로 묶어서는 안되며 특히 역 따옴표는 사용하지 않아야합니다. 키워드 NULL도 마찬가지입니다. – UncleO