Bir php komut dosyası var Temelde sadece bir öğretici tarafından çektiğim ve gereksinimlerime uygun şekilde değiştirdiğim bir çalışma yapmaya çalışıyorum. Bu benim php'deki ilk denememdir, lütfen benim için kolay ol. php güncelleme sql formdan
BenList_records MySQL tablodan veri okuma update_ac.php
- list_records.php
- var. list_records'daki tablonun, verileri db tablosunda görüntülediği update.php dosyasına götüren bir düzenleme işlevi vardır.
Update.php, update_ac.php kullanarak mysql değerini $ _GET ['id] kullanarak url'deki id alanını kullanarak değiştirdiğiniz bilgilerle güncellemeyi amaçlayan bir gönderme düğmesine sahiptir.
Bu betiğin slq enjeksiyonlarına çok açık olduğunu biliyorum, ancak bunu yalnızca yerel bir ortamda kullanmayı planlıyorum, internete maruz kalmayacağım ve sadece kendim ve bir başkası bu sayfayı kullanmayacak gerçekten bir sorun.
Neyse, bir kaç şey teyit ettik: -
- id $ _GET kullanılarak yakalandı olsun demek, ben bir yankı koymak ve onu update.php sayfasında yazdırılır. $ _GET [id] kullanırken
- i php ve değişim değerlerinin içinde güncelleme komutunu çalıştırabilirsiniz ama alışkanlık çalışmak
kimse doğru yönde işaret edebilir? Burada
<title>Ports</title> </head> <?php // Connect to server and select database. mysql_connect("localhost", "username", "passsword")or die("cannot connect"); mysql_select_db("porting")or die("cannot select DB"); $sql="SELECT * FROM ports"; $result=mysql_query($sql); ?> <body> <table width="1200" border="1" cellspacing="1" cellpadding="0"> <tr> <td> <table width="1200" border="1" cellspacing="1" cellpadding="3"> <tr> <td colspan="50"><strong>Pending Port Requests 2</strong> </td> </tr> <tr> <td align="center"><strong>Customer</strong></td> <td align="center"><strong>Number</strong></td> <td align="center"><strong>Type</strong></td> <td align="center"><strong>Completed</strong></td> <td align="center"><strong>Update</strong></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td><?php echo $rows['Customer']; ?></td> <td><?php echo $rows['Number']; ?></td> <td><?php echo $rows['Type']; ?></td> <td><?php echo $rows['Completed']; ?></td> <td align="center"><a href="update.php?id=<?php echo $rows['id']; ?>">update</a></td> </tr> <?php } ?> </table> </td> </tr> </table> </body> </html>
update.php
update_ac.php<title>update</title> </head> <?php // Connect to server and select database. mysql_connect("localhost", "username", "password")or die("cannot connect"); mysql_select_db("porting") or die("cannot select DB"); // get value of id that sent from address bar $id=$_GET['id']; // Retrieve data from database $sql="SELECT * FROM porting.ports WHERE id = '$id'"; $result=mysql_query($sql); $rows=mysql_fetch_array($result); ?> <body> <table width="1200" border="0" cellspacing="1" cellpadding="0"> <tr> <form name="form1" method="post" action="update_ac.php"> <td> <table width="100%" border="0" cellspacing="1" cellpadding="0"> <tr> <td> </td> <td colspan="6"><strong>Update Porting Details</strong> </td> </tr> <tr> <td align="center"> </td> <td align="center"> </td> <td align="center"> </td> <td align="center"> </td> </tr> <tr> <td align="center"> </td> <td align="center"><strong>Customer</strong></td> <td align="center"><strong>Number</strong></td> <td align="center"><strong>Type</strong></td> <td align="center"><strong>Completed</strong></td> </tr> <tr> <td> </td> <td align="center"> <input name="Customer" type="text" id="Customer" value="<?php echo $rows['Customer']; ?>"size= "15"/> </td> <td align="center"> <input name="Number" type="text" id="Number" value="<?php echo $rows['Number']; ?>" size="15"/> </td> <td align="center"> <input name="Type" type="text" id="Type" value="<?php echo $rows['Type']; ?>" size="15"/> </td> <td align="center"> <input name="Comments" type="text" id="Completed" value="<?php echo $rows['Comments']; ?>" size="15"/> </td> <tr> </table> <input name="id" type="hidden" id="id" value="<?php echo $rows['id']; ?>"/> <input type="submit" name="Submit" value="Submit" /></td> <td align="center"> </td> </td> </form> </tr> </table> </body> </html>
<?php // Connect to server and select database. mysql_connect("localhost", "username", "password")or die("cannot connect"); mysql_select_db("porting")or die("cannot select DB"); // update data in mysql database $sql="UPDATE ports SET Customer='Customer', Number='Number' WHERE id='id'" or die ("this stuffed up"); $result=mysql_query($sql) or die ("this stuffedup"); // if successfully updated. if($result){ echo "Successful"; echo "<BR>"; echo "<a href='list_records.php'>View result</a>"; } else { echo "ERROR"; } ?>
gerekli alıyorsanız değeri koymalıyız satırlar [ 'Müşteri']; ? –
Kodunuz SQL enjeksiyon saldırılarına açık bırakıyor. Örnekler için [bobi tabloları] (http://bobby-tables.com/) örneğine bakın. Ayrıca, 'mysql_ *' fonksiyonları kullanımdan kaldırıldıkça, lütfen MySQLi veya [PDO] 'ya bakın (http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers) – jcbwlkr