저는 여기서 정말 간단하게하려고합니다. 내가 원하는 것은 MySQL에 정보를 삽입하는 것입니다. 다음은이 양식의 코드입니다.INSERT INTO mysql 데이터베이스가 작동하지 않습니다.
<?php
$host=""; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name
$tbl_name=""; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// get value of id that sent from address bar
$dj=$_GET['dj'];
// Retrieve data from database
$sql="SELECT * FROM $tbl_name WHERE dj='$dj'";
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);
?>
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<form name="form1" method="post" action="insert_ac.php">
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
<td> </td>
<td colspan="3"><strong>Insert The information for the Now PlayingProgram.</strong>
</td>
</tr>
<tr>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
</tr>
<tr>
<td align="center"> </td>
<td align="center"><strong>Name</strong></td>
<td align="center"><strong>Email</strong></td>
<td align="center"><strong>Email2</strong></td>
</tr>
<tr>
<td> </td>
<td align="center">
<input name="name" type="text" id="name" value="">
</td>
<td align="center">
<input name="email" type="text" id="email" value="" size="15">
</td>
<td>
<input name="email2" type="text" id="email2" value="" size="15">
</td>
</tr>
<tr>
<td align="center"> </td>
<td align="center"><strong>Twitter</strong></td>
<td align="center"><strong>Twitter2</strong></td>
<td align="center"><strong>Avatar</strong></td>
</tr>
<tr>
<td> </td>
<td align="center">
<input name="twitter" type="text" id="twitter" value="">
</td>
<td align="center">
<input name="twitter2" type="text" id="twitter2" value="" size="15">
</td>
<td>
<input name="avatar" type="text" id="avatar" value="" size="15">
</td>
</tr>
<tr>
<td align="center"> </td>
<td align="center"><strong>Facebook</strong></td>
<td align="center"><strong>Facebook2</strong></td>
<td align="center"><strong>Type</strong></td>
</tr>
<tr>
<td> </td>
<td align="center">
<input name="facebook" type="text" id="facebook" value="">
</td>
<td align="center">
<input name="facebook2" type="text" id="facebook2" value="" size="15">
</td>
<td>
<input name="type" type="text" id="type" value="" size="15">
</td>
</tr>
<tr>
<td align="center"> </td>
<td align="center"><strong>Alias1</strong></td>
<td align="center"><strong>Alias2</strong></td>
<td align="center"><strong>Alias3</strong></td>
</tr>
<tr>
<td> </td>
<td align="center">
<input name="alias1" type="text" id="alias1" value="">
</td>
<td align="center">
<input name="alias2" type="text" id="alias2" value="" size="15">
</td>
<td>
<input name="alias3" type="text" id="alias3" value="" size="15">
</td>
</tr>
<tr>
<td align="center"> </td>
<td colspan="3" align="center"><strong>Request Line</strong></td>
</tr>
<tr>
<td> </td>
<td colspan="3" align="center">
<input name="address" type="text" id="address" value="" size="65">
</td>
</tr>
<tr>
<td> </td>
<td>
<input name="dj" type="hidden" id="dj" value="">
</td>
<td align="center">
<input type="submit" name="Submit" value="Submit">
</td>
<td> </td>
</tr>
</table>
</td>
</form>
</tr>
</table>
<?php
// close connection
mysql_close();
?>
이제 내가 할 수 있기를 원하는 것은이 양식에 입력 한 정보를 데이터베이스에 삽입하는 것입니다. 글쎄 내 문제는 일부 데이터를 입력하고 제출을 클릭하면, 내가 얻을 수있는 모든 오류입니다.
<?php
$host=""; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name
$tbl_name=""; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// insert data in mysql database
$sql="INSERT INTO $tbl_name (name, email, email2, twitter, twitter2, avatar, facebook, facebook2, type, alias1, alias2, alias3, address, dj)
VALUES('{$_POST[name]}', '{$_POST[email]}', '{$_POST[email2]}', '{$_POST[twitter]}', '{$_POST[twitter2]}', '{$_POST[avatar]}', '{$_POST[facebook]}', '{$_POST[facebook2]}', '{$_POST[type]}', '{$_POST[alias1]}', '{$_POST[alias2]}', '{$_POST[alias3]}', '{$_POST[address]}', '{$_POST[dj]}')";
$result=mysql_query($sql);
// if successfully inserted
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='list_records.php'>View result</a>";
echo "1 record added";
}
else {
echo "ERROR";
}
?>
난 그냥 구문 또는 여기에 심지어 맞춤법 문제가 발생하고 있는지 알고 싶습니다
그래서 아래 코드는 내 incert_ac.php에서 살펴 수 있습니다! 도움이 될 것입니다.
어쩌면 일부 SQL 입력 위생을 추가하여 변수'$의 tbl_name' 항상 –
비어 있기 때문에 내가 secuity에 대한 그 정보]를 제거 이유 – Feek
'$ tbl_name'테이블에'name, email, email2, twitter, twitter2, avatar, facebook, facebook2, type, alias1, alias2, alias3, address, dj '필드가 모두 존재하는지 다시 확인하십시오 –