2016-06-17 3 views
-2

기본적으로 업데이트 또는 추가를 누르면 오류가 표시되지 않습니다. 누구든지 나를 도울 수 있습니까? 나는 그것을 추가 할 때 데이터베이스에 데이터를 추가하고, update를 누르면 해당 값으로 데이터베이스를 업데이트하기를 원합니다.PHP 코드가 업데이트 중이거나 데이터베이스에 추가되지 않았습니다.

<html> 
<head> 
<title>Subcontractors Data</title> 
</head> 

<body> 
<a href="index.html">Logout</a> 
<a href="homepage.html">Homepage</a> 
<?php 
//make connection 
$con = mysqli_connect("localhost","root",""); 

if(!$con){ 
    die("Can not connect " . mysqli_error()); 
} 

//select db 
mysqli_select_db($con , 'subcontractor'); 


$sql="SELECT * FROM subcontractors"; 



if(isset($_POST['update'])){ 
    $UpdateQuery = "UPDATE subcontractors SET ID='$_POST[ID]', Name='$_POST[Name]', Surname='$_POST[Surname]', FPA='$_POST[FPA]', Performance='$_POST[Performance]' WHERE ID='$_POST[hidden]'"; 
    mysqli_query($con, $UpdateQuery); 


}; 

if(isset($_POST['add'])){ 
    $AddQuery = "INSERT INTO subcontractors (ID, Name, Surname, FPA, Performance) VALUES ('$_POST[aID]','$_POST[aName]','$_POST[aSurname]','$_POST[aFPA]','$_POST[aPerformance]')"; 
    mysqli_query($con, $AddQuery); 

}; 

$my_Data=mysqli_query($con,$sql); 

echo "<table border=1>"; 
    echo"<tr>"; 
    echo"<th>ID</th>"; 
    echo"<th>Name</th>"; 
    echo"<th>Surname</th>"; 
    echo"<th>FPA</th>"; 
    echo "<th>Performance</th>"; 
    echo "</tr>"; 

while($record=mysqli_fetch_assoc($my_Data)){ 
echo "<form action=editsub.php method=post>"; 
echo "<tr>"; 
echo "<td>" . "<input type=text name='ID' value=".$record['ID'] ." </td>"; 
echo "<td>" . "<input type=text name='Name' value=".$record['Name'] . " </td>"; 
echo "<td>" . "<input type=text name='Surname' value=".$record['Surname'] . " </td>"; 
echo "<td>" . "<input type=text name='FPA' value=".$record['FPA'] . "% </td>"; 
echo "<td>" . "<input type=text name='Performance' value=".$record['Performance'] . "% </td>"; 
echo "<input type=hidden name='hidden' value=" . $record['ID'] . ">"; 
echo "<input type=submit name='update' value='update'>"; 
echo "</tr>"; 
echo "</form>"; 
} 
echo "<form action=editsub.php mehtod=post>"; 
echo "<tr>"; 
echo "<td><input type=text name='aID'></td>"; 
echo "<td><input type=text name='aName'></td>"; 
echo "<td><input type=text name='aSurname'></td>"; 
echo "<td><input type=text name='aFPA'></td>"; 
echo "<td><input type=text name='aPerformance'></td>"; 
echo "<td>" . "<input type=submit name='add' value='add'" . " </td>"; 
echo "</form>"; 

echo "</table>"; 
mysqli_close($con); 
?> 



</body> 




</html> 
+1

처음으로,'mehtod'! ='method'. 둘째, 준비된 문장을 사용하십시오. 주입 공격에 개방적입니다. 셋째,이 'editsub.php'입니까? 넷째, 질의가 실제로 실행되고 있는지 확인하고, 마지막으로 [오류]를 확인하십시오 (http://php.net/manual/en/mysqli.error.php). –

답변

0

이렇게하면 오류를 확인할 수 있습니다.

ini_set('display_errors', 1); 
ini_set('display_startup_errors', 1); 
error_reporting(E_ALL); 
+0

또한 사용할 수 있습니다

관련 문제