Win7에서 WAMP 2.5를 실행하고 웹 페이지를 만들어 mySQL 데이터베이스에 레코드를 삽입했습니다. 이것은 완벽하게 작동했습니다. 그렇다면 SQL 대신 2014 (LAN상의 원격 서버) (WAMP의 로컬)를 사용해야했고, 모든 것이 정상적으로 보이지만 테이블에서 생성 된 레코드를 얻지는 못했지만 오류도 발생하지 않았습니다. 로그인에 사용 된 계정은 db owner입니다. 도움이 될 것입니다. 감사합니다 렌mySQL에서 SQL로 변경하고 이제는 레코드 생성을 얻을 수 없습니다.
코드는 다음과 같습니다 (db 연결의 경우 sqlconnect.php를 호출 함). 연결이 성공했음을 확인합니다. 파일을 insert-data.php라고 부르므로 양식이 비어 있고 제출이 선택되면 파일 자체를 호출합니다. mcpbarcode 열이 문자열 형식 (VARCHAR, 문자 등)입니다
경우 : 그런 식으로 작동하고있는 경우
<?php
if(!empty($_POST['mcpbarcode'])) {
header("Location insert-data.php");
include('sqlconnect.php');
$mcpbarcode = $_POST['mcpbarcode'];
$sqlinsert = "INSERT INTO mcpbarcode (mcpbarcode)
VALUES ('$mcpbarcode')";
sqlsrv_query($conn,$sqlinsert);
if (!$sqlinsert) {
die('error inserting new record');
}
$newrecord = "New record added";
}
?>
<html>
<head>
<title> Insert Barcode into Database</title>
</head>
<h3><font color = red>This window must be open and active</font></h3>
<img src="header.jpg" alt="anyname" style="width:800px;height:165px;">
<body>
<h1> Insert barcode into Database</h1>
<form method="post" action="insert-data.php">
<input type="hidden" name="submitted" value="true"/>
<label>Barcode:<input type="text" name="mcpbarcode" autofocus /></label>
<br /><br />
<input type="submit" value="Add new record" />
</form>
<?php
$newrecord="";
echo $newrecord
?>
</body>
</html>
짧은 답변. mysqli 또는 pdo를 사용하고 준비된 문장을 구현한다. – Akintunde007
또한 왜이 줄을'header ("Location insert-data.php");'?? 이 스크립트를 종료해야합니다. 또한 당신은'header()'위치 구문을 놓쳤습니다. – Akintunde007
무엇이 오류입니까? mcpbarcode는 데이터를 제공하는 열 이름입니까? 테이블의 다른 열은 무엇입니까? – Radu