2015-12-06 179 views
1

我決定讓我的數據庫有一個活動的超鏈接,所以當我找到一條記錄時,我點擊一個電子郵件地址並打開電子郵件。但我有一個更新的問題,當我想進行更正,當我按更新電子郵件消失,我得到: 注意:未定義的索引:Mail中/ Applications/XAMPP/xamppfiles/htdocs/robocze/mydata_dodaj_test_1 .PHP上線36如何更新超鏈接?

我可以添加記錄,但我不能更新...

可以請你幫幫我,謝謝你

代碼:

<?php 
session_start(); 
if(!isset($_SESSION["sess_user"])){ 
header("location:login.php"); 
} else { 
?> 

<!DOCTYPE html> 
<html> 
<head> 
<meta charset="UTF-8"> 
<title>Baza Klientów</title> 
</head> 
<body> 
<h3>Welcome, <?=$_SESSION['sess_user'];?>! <a href="logout.php">Logout</a> </h3> 

<input type="button" onclick="location.href='mydata_dodaj_test_1.php';" value="Powrót do wyszukiwania" /> 
<input type="button" onclick="location.href='index.php';" value="MENU powrót" /> 

<h2><b><center>Wyszukiwanie Klientów ITalents</center></b></h2> 

<?php 
} 
?>  

<?php 

$con = mysql_connect("","","",""); 
if (!$con){ 
die("Błąd połączenia: " . mysql_error()); 
} 
mysql_select_db("baza",$con); 


if(isset($_POST['update'])) { 
$UpdateQuery = "UPDATE Klienci SET id='$_POST[id]', Firma='$_POST[Firma]', Mail='$_POST[Mail]', Data='$_POST[Data]', Konsultant='$_POST[Konsultant]' WHERE id='$_POST[hidden]'"; 
mysql_query($UpdateQuery,$con); 
}; 

if(isset($_POST['add'])) { 
$AddQuery = "INSERT INTO Klienci (id, Firma, Mail, Data, Konsultant) VALUES ('$_POST[uid]','$_POST[uFirma]','$_POST[uMail]','$_POST[uData]','$_POST[uKonsultant]')"; // this is the 36 line 
mysql_query($AddQuery,$con); 
};  

if(isset($_POST['search'])) 
{ 
$valueToSearch = $_POST['valueToSearch']; 
$query = "SELECT * FROM Klienci WHERE CONCAT(Firma, Mail, Konsultant) LIKE '%".$valueToSearch."%'"; 
$search_result = filterTable($query); 

} 
else { 
$query = "SELECT * FROM Klienci ORDER BY id ASC"; 
$search_result = filterTable($query); 
} 

function filterTable($query) 
{ 
$con = mysql_connect("","","",""); 
if (!$con){ 
die("Błąd połączenia: " . mysql_error()); 
} 
mysql_select_db("baza",$con); 

$filter_Result = mysql_query($query, $con); 
return $filter_Result; 
}; 


echo "<form action=mydata_dodaj_test_1.php method=post>"; 
echo "<input type=text name=valueToSearch placeholder=wpisz>"; 
echo "<input type=submit name=search value=Szukaj>"; 

echo "<table align=center style=text-align:center border=5> 
<tr> 
<th>ID</th> 
<th>Firma</th> 
<th>Mail</th> 
<th>Data</th> 
<th>Konsultant</th> 
</tr>"; 

while($row = mysql_fetch_array($search_result)) { 
echo "<form action=mydata_dodaj_test_1.php method=post>"; 
echo "<tr>"; 
echo "<td>" . "<input type=int name=id value=" . $row['id'] . " </td>"; 
echo "<td>" . "<input type=varchar name=Firma value=" . $row['Firma'] . " </td>"; 

echo "<td>" . "<a href='mailto:{$row['Mail']}'>" . $row['Mail'] . " </td>"; 

echo "<td>" . "<input type=date name=Data value=" . $row['Data'] . " </td>"; 
echo "<td>" . "<input type=varchar name=Konsultant value=" . $row['Konsultant'] . " </td>"; 
echo "<td>" . "<input type=hidden name=hidden value=" . $row['id'] . " </td>"; 
echo "<td>" . "<input type=submit name=update value=update" . " </td>"; 
echo "</form>";  
} 
echo "<form action=mydata_dodaj_test_1.php method=post>"; 
echo "<tr>"; 
echo "<td><input type=text name=uid></td>"; 
echo "<td><input type=varchar name=uFirma></td>"; 
echo "<td><input type=text name=uMail></td>"; 
echo "<td><input type=text name=uData></td>"; 
echo "<td><input type=text name=uKonsultant></td>"; 
echo "<td>" . "<input type=submit name=add value=dodaj" . " </td>"; 
echo "</form>"; 
echo "</table>"; 
?> 

<input type="button" onclick="location.href='mydata_dodaj_test_1.php';" value="Powrót do wyszukiwania" /> 
<input type="button" onclick="location.href='index.php';" value="MENU powrót" /> 
</body> 
</html> 
+1

你有很多表單。看起來你實際上沒有在你的更新表單中輸入[name = Mail]。您應該添加一個帶有該值的隱藏輸入。 – Terminus

回答

-1

由於錯誤在你的說明undefined index日期聲明

$UpdateQuery = "UPDATE Klienci SET id='$_POST[id]', Firma='$_POST[Firma]', Mail='$_POST[Mail]', Data='$_POST[Data]', Konsultant='$_POST[Konsultant]' WHERE id='$_POST[hidden]'"; 

您正在訪問$_POST[Mail]哪裏沒有你的形式。

+0

千萬不要將這樣的變量插入到SQL查詢中,而不要使其安全或使用'prepared'語句。 – Enijar

+0

告訴OP不是我..我只是告訴OP關於未定義的索引 –

+0

事實上,DB的行工作正常,但沒有超鏈接看起來像這樣 - 回聲「​​」。 「」;然後我的版本的$ UpdateQuery ....是好的但沒有超鏈接...我不知道如何使超鏈接可以編輯和更新。上面在我的消息中顯示超鏈接,但我無法更新它.... –