mysql 데이터베이스에 연결하는 PHP 페이지가 있습니다. 웹 페이지에 데이터베이스의 정보를 표시하는 PHP 코드가 있기 때문에 데이터베이스 연결이 좋다는 것을 알고 있습니다. 데이터 베 이스에 새 데이터를 삽입하려고하면 페이지가 새로 고침되고 데이터가 삽입되지 않습니다. 삽입 명령에 올바른 값이 있는지 확인했습니다.PHP가 mysql에 데이터를 전달하지 않음
<?php
if (isset($_POST['User_Name']))
{
include "connect_to_mysql.php";
$name = mysql_real_escape_string($_POST["Name"]);
$sql = mysql_query("SELECT TestID FROM test WHERE Name='$name' LIMIT 1")or die (mysql_error());
$productMatch = mysql_num_rows($sql);
if ($productMatch > 0)
{
echo 'Sorry you tried to place a duplicate "User Account" into the system, <a href="index.php">click here</a>';
exit();
}
else
{
$sql = mysql_query("INSERT INTO test (TestID,Name)
VALUES('', '$name')") or die (mysql_error());
$uid = mysql_insert_id();
header("location: index.php");
exit();
}
}
?>
<?php
include "connect_to_mysql.php";
$User_list = "";
$sql = mysql_query("SELECT * FROM test");
$UserCount = mysql_num_rows($sql);
if ($UserCount > 0)
{
while($row = mysql_fetch_array($sql))
{
$id = $row["TestID"];
$name = $row["Name"];
$User_list .= "Users ID: $id - <strong>$name</strong> <br />";
}
}
else
{
$User_list = "You have no users listed in the database.";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<div align="center" id="mainWrapper">
<div id="pageContent"><br />
<div align="right" style="margin-right:32px;"><a href="index.php#UserForm">+ Add New User</a></div>
<div align="left" style="margin-left:24px;">
<h2>User list</h2>
<?php echo $User_list; ?>
</div>
<hr />
<a name="UserForm" id="UserForm"></a>
<h3>
↓ Add New User Form ↓
</h3>
<form action="index.php" enctype="multipart/form-data" name="myForm" id="myform" method="post">
<table width="90%" border="0" cellspacing="0" cellpadding="6">
<tr>
<td width="20%" align="right">Name</td>
<td width="80%"><label>
<input name="name" type="text" id="name" size="50" />
</label></td>
</tr>
<tr>
<td> </td>
<td><label>
<input type="submit" name="button" id="button" value="Add This Name Now" />
</label></td>
</tr>
</table>
</form>
<br />
<br />
</div>
</div>
</body>
</html>
어쩌면 당신은 MySQL의 인스턴스를 열어 거기에서 바로 데이터를 삽입 해 볼 수 있을까요? PHP를 사용하여 DB에 물건을 삽입하려고하면 실제로 무엇이 잘못되었는지는 알려주지 않지만 MySQL을 직접 사용하면 잘못 된 것 (아마도 이스케이프 처리되지 않은 따옴표 또는 마이너 등)을 알려줍니다 그러나 붙잡기 단단한). – Raymond
이전의'mysql _ *()'함수를 더 이상 사용하지 않는 것이 좋습니다. 지원 중단 예정입니다. 대신 PDO 또는 MySQLi와 같은 준비된 문을 지원하는 최신 API 사용을 고려하십시오. –