가정용 컴퓨터를 떠나지 않으려는 웹 사이트의 두 페이지를 통해 양식을 사용하여 내 컴퓨터에서 호스팅되는 MySQL 데이터베이스에 항목을 입력하고 싶습니다. 나는 거의 동일하게 무언가를하기 전에 이것을 해왔지만, 어떤 이유로이 것은 작동하지 않습니다. 나는 내 컴퓨터를 떠나지 않을 것이기 때문에이 보안 또는 그와 같은 것의 보안에 대해 걱정하지 않는다. 나는 실제로 그것이 실제로 작동하기를 바란다.양식에서 MySQL 데이터베이스에 항목 삽입
형태 :
같은 레이아웃을 유지하기 위해 HTML 쌌다이처럼 보이는, addclothes.php을 통해 전송<form action='addclothes.php' method='post'><table style="font-family:verdana;font-size:14px;color:#004766;"><tr><td>
Type of clothing:</td><td><select name="type">
<option value="0">---</option>
<option value="dresses">Dress</option>
<option value="tops">Top</option>
<option value="bottoms">Bottom</option>
<option value="shoes">Shoes</option>
<option value="accessories">Accessory</option></select></td></tr>
<tr><td>Name:</td><td><input type="text" name="name"></td></tr>
<tr><td>Path to full image:</td><td><input type="text" name="largeimagepath"></td></tr>
<tr><td>Path to thumbnail:</td><td><input type="text" name="smallimagepath"></td></tr>
<tr><td colspan="2"><center><input type="submit" value="Submit" name="submit"></center></td></tr>
</table></form>
:
<?php
$name = $_POST['name'];
$table = $_POST['type'];
$largepath = $_POST['largeimagepath'];
$thumbpath = $_POST['smallimagepath'];
$db = mysql_connect("localhost", "root", "******") or die(mysql_error());
mysql_select_db("Default") or die(mysql_error());
$query = "INSERT INTO clothes."{$table}" (name, imagepath, thumbimagepath)
VALUES("{$name}", "{$largepath}", "{$thumbpath}")";
mysql_query($query) or die(mysql_error()); ?>
<p>Item Added!</p>
그것은 다음 페이지 단지로 온다 무엇이든간에 "항목이 추가되었습니다"라고 말합니다. 쿼리를 에코하려는 경우 바로 나타나지 않는 변수를 만듭니다.
[** ** 구식 ** 데이터베이스 API] (http://stackoverflow.com/q/12859942/19068)를 사용하고 있으며 [최신 대체] (http://php.net/manual/)를 사용해야합니다. en/mysqlinfo.api.choosing.php). 또한 ** [SQL 주입 공격] (http://bobby-tables.com/) **에 현대적인 API를 사용하면 쉽게 방어 할 수 있습니다 ** (http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php)을 사용하십시오. – Quentin
문자열 연결에 PHP에서 구문 분석 오류가 발생할 것으로 예상되는 구문 오류가 있습니다. (이전의 코멘트에 따르면, 쿼리 빌딩에서 문자열 연결을 제거해야하기 때문에 실제로는 사물의 웅장한 계획에서 중요하지 않습니다.) – Quentin