문제는 잠시 해결되었으며 이제 데이터베이스 추가에 정보에 대한 새 줄이 추가되었습니다. 유일한 문제는 데이터베이스가 양식에서 정보를 가져 오지 않는다는 것입니다.
<?php
$con = mysql_connect("localhost","username","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("databasename", $con);
$sql="INSERT INTO breakdowns (username, breakdowndate, policyinception, customername, customersurname, covertype, vehiclemake, vehiclemodel, vehiclereg, vehicleage, excess, mileage, paid, HSRS, fault, garage, telephone)
VALUES
('$_POST[username]','$_POST[breakdowndate]','$_POST[policyinception]','$_POST[customername]','$_POST[customersurname]','$_POST[covertype]','$_POST[vehiclemake]','$_POST[vehiclemodel]','$_POST[vehiclereg]','$_POST[vehicleage]','$_POST[excess]','$_POST[mileage]','$_POST[paid]','$_POST[HSRS]','$_POST[fault]','$_POST[garage]','$_POST[telephone]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 breakdown added";
mysql_close($con)
?>
스크립트가 서버에서 실행되면 에코 메시지가 표시되고 데이터베이스에 빈 줄이 나타나지만 양식의 정보가 없습니다.
이것은 이제 작동합니다.
<?php
// This sends the breakdown form to the database //
$con = mysql_connect("localhost","dgtlss20_orca1","qG!P}ubT.tuw");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("dgtlss20_orca", $con);
$sql="INSERT INTO breakdowns (username, breakdowndate, policyinception, customername, customersurname, covertype, vehiclemake, vehiclemodel, vehiclereg, vehicleage, excess, mileage, paid, HSRS, fault, garage, telephone)
VALUES ('$_POST[username]','$_POST[breakdowndate]','$_POST[policyinception]','$_POST[customername]','$_POST[customersurname]','$_POST[covertype]','$_POST[vehiclemake]','$_POST[vehiclemodel]','$_POST[vehiclereg]','$_POST[vehicleage]','$_POST[excess]','$_POST[mileage]','$_POST[paid]','$_POST[HSRS]','$_POST[fault]','$_POST[garage]','$_POST[telephone]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
header('Location: ../breakdown-added.php');
mysql_close($con)
?>
코드가 SQL 주입에 취약합니다.
$_POST['post_breakdowndate']
대신 매개 변수를 전달해야합니다.$_POST[post_breakdowndate]
쿼리를 다음과 같이 업데이트해야합니다.
mysqli_query($connect,"INSERT INTO posts (user, breakdowndate, policyinception, customername, customersurname, covertype, vehiclemake, vehiclemodel, vehiclereg, vehicleage, excess, mileage, paid, HSRS, fault, garage, telephone) VALUES ('".$_POST['post_user']."', '".$_POST['post_breakdowndate']."', '".$_POST['post_policyinception']."', '".$_POST['post_customername']."', '".$_POST['post_customersurname']."', '".$_POST['post_covertype']."', '".$_POST['post_vehiclemake']."', '".$_POST['post_vehiclemodel']."', '".$_POST['post_vehiclereg']."', '".$_POST['post_vehicleage']."', '".$_POST['post_excess']."', '".$_POST['post_mileage']."', '".$_POST['post_paid']."', '".$_POST['post_HSRS']."', '".$_POST['post_fault']."', '".$_POST['post_garage']."', '".$_POST['post_telephone']."')");
함수 외부의 값 부분을 종료합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다