2017-12-13 21 views
0

これは私のコードです。私の場合のidは、varchar(数字、記号、charからなる)です。数字のIDを入力すると、情報を編集できます。入力されたIDが完全に数値ではない場合でも、システムが言う "不明な列 '618XRWCGは' 中 'where句'"IDは数字ではありません。編集できません。

これはこれはviewforecastある

<?php 

} 


// connect to the database 

include('connect.php'); 



// check if the form has been submitted. If it has, process the form and save it to the database 

if (isset($_POST['submit'])) 

{ 

// confirm that the 'id' value is a valid integer before getting the form data 

if (is_numeric($_POST['id'])) 

{ 

// get form data, making sure it is valid 

$id = $_POST['id']; 

$min = mysql_real_escape_string(htmlspecialchars($_POST['min'])); 

$max = mysql_real_escape_string(htmlspecialchars($_POST['max'])); 

$sapuk = mysql_real_escape_string(htmlspecialchars($_POST['sapuk'])); 

$sapus = mysql_real_escape_string(htmlspecialchars($_POST['sapus'])); 

$sapasia = mysql_real_escape_string(htmlspecialchars($_POST['sapasia'])); 

$sapmex = mysql_real_escape_string(htmlspecialchars($_POST['sapmex'])); 

$penuk = mysql_real_escape_string(htmlspecialchars($_POST['penuk'])); 

$penus = mysql_real_escape_string(htmlspecialchars($_POST['penus'])); 

$penasia = mysql_real_escape_string(htmlspecialchars($_POST['penasia'])); 

$penmex = mysql_real_escape_string(htmlspecialchars($_POST['penmex'])); 



// check that firstname/lastname fields are both filled in 

if ($min == '' || $max == '') 

{ 

// generate error message 

$error = 'ERROR: Please fill in all required fields!'; 



//error, display form 

renderForm($id, $min, $max, $sapuk, $sapus, $sapasia, $sapmex, $penuk, $penus, $penasia, $penmex, $error); 

} 

else 

{ 

// save the data to the database 

mysql_query("UPDATE forecast SET Min='$min', Max='$max', sapUK='$sapuk', sapUS='$sapus', sapAsia='$sapasia', sapMex='$sapmex', penUK='$penuk', penUS='$penus', penAsia='$penasia', penMex='$penmex' WHERE Partnumber='$id'") 

or die(mysql_error()); 



// once saved, redirect back to the view page 

header("Location: viewforecast.php"); 

} 

} 

else 

{ 

// if the 'id' isn't valid, display an error 

echo 'Error!'; 

} 

} 

else 

// if the form hasn't been submitted, get the data from the db and display the form 

{ 



// get the 'id' value from the URL (if it exists), making sure that it is valid (checing that it is numeric/larger than 0) 

if (isset($_GET['id'])&& $_GET['id'] > 0) 

{ 

// query db 

$id = $_GET['id']; 

$result = mysql_query("SELECT * FROM forecast WHERE Partnumber=$id") 

or die(mysql_error()); 

$row = mysql_fetch_array($result); 



// check that the 'id' matches up with a row in the databse 

if($row) 

{ 



// get data from db 

$min = $row['Min']; 

$max = $row['Max']; 

$sapuk = $row['sapUk']; 

$sapus = $row['sapUS']; 

$sapasia = $row['sapAsia']; 

$sapmex = $row['sapMex']; 

$penuk = $row['pendingUK']; 

$penus = $row['pendingUS']; 

$penasia = $row['pendingAsia']; 

$penmex = $row['pendingMex']; 



// show form 

renderForm($id, $min, $max, $sapuk, $sapus, $sapasia, $sapmex, $penuk, $penus, $penasia, $penmex, ''); 

} 

else 

// if no match, display result 

{ 

echo "No results!"; 

} 

} 

else 

// if the 'id' in the URL isn't valid, or if there is no 'id' value, display an error 

{ 

echo 'Error!'; 

} 

} 

?> 

updateforecast.phpです私が入ったとき

<?php 
include('connect.php'); 

$result = mysql_query("SELECT * FROM forecast") 

or die(mysql_error()); 

echo "<table border='1' id = 'frmnew' cellpadding='10'>"; 

echo "<tr> 
    <th rowspan='2'><center><b>Part Number</b></center></th> 
    <th rowspan='2'><center><b>Minimum Quantity</b></center></th> 
    <th rowspan='2'><center><b>Maximum Quantity</b></center></th> 

    <th colspan='4' scope='colgroup'><center>SHIP AGAINST PO</center></th> 
    <th colspan='4' scope='colgroup'><center>FORECAST FROM VARIOUS REGIONS PENDING FOR INTERCO PO</center></th> 
    </tr> 
    <tr> 
    <th scope='col'><center>UK</center></th> 
    <th scope='col'><center>US</center></th> 
    <th scope='col'><center>ASIA</center></th> 
    <th scope='col'><center>MEXICO</center></th> 
    <th scope='col'><center>UK</center></th> 
    <th scope='col'><center>US</center></th> 
    <th scope='col'><center>ASIA</center></th> 
    <th scope='col'><center>MEXICO</center></th> 
    </tr>"; 



// loop through results of database query, displaying them in the table 

while($row = mysql_fetch_array($result)) { 



// echo out the contents of each row into a table 

echo "<tr>"; 

echo '<td>' . $row['Partnumber'] . '</td>'; 

echo '<td>' . $row['Min'] . '</td>'; 

echo '<td>' . $row['Max'] . '</td>'; 

echo '<td>' . $row['sapUK'] . '</td>'; 

echo '<td>' . $row['sapUS'] . '</td>'; 

echo '<td>' . $row['sapAsia'] . '</td>'; 

echo '<td>' . $row['sapMex'] . '</td>'; 

echo '<td>' . $row['pendingUK'] . '</td>'; 

echo '<td>' . $row['pendingUS'] . '</td>'; 

echo '<td>' . $row['pendingAsia'] . '</td>'; 

echo '<td>' . $row['pendingMex'] . '</td>'; 

echo '<td><a href="updateforecast.php?id=' . $row['Partnumber'] . '">Edit</a></td>'; 

echo '<td><a href="deleteforecast.php?id=' . $row['Partnumber'] . '">Delete</a></td>'; 

echo "</tr>"; 

} 



// close table> 

echo "</table>"; 

?> 

<p><a href="forecast.php">Add a new record</a></p> 

</body> 
</html> 

.PHP私が述べた前のエラーでしたシンボルのないID。私はシンボルを持つidを入力すると、シンボルとその後ろのキャラクターは隠されたものになります。

+0

このコードは、実際に問題があることを示す[mcve]に減らす必要があります。ほとんどの場合、これを実行すると、問題を完全に見つけ出すことができます。 – IncredibleHat

+1

サイドノート:すべての 'mysql_ *'関数は償却され、後のPHPで完全に削除されています。 mysqli_ *またはPDO関数に移行します。また、その間に、コードを攻撃から守るために準備されたステートメントを調べます。 – IncredibleHat

+0

@IncredibleHat私はあなたに感謝します –

答えて

-1

編集あなたは、文字列を変更せずにこれをIDを渡され、あなたのupdateforecast.phpコード選択クエリを助けてください。

 $result = mysql_query("SELECT * FROM forecast WHERE Partnumber='$id'") 
+0

ありがとうございます私はとてもうれしい –

0

コードにはSQL Injectionの脆弱性が存在します。 @IncredibleHatのようにPDOを使うべきです

+0

私はあなたに感謝します –

関連する問題