如何更新超链接?

时间:2015-12-06 18:56:37

标签: php updates

我决定使用活动的超链接建立我的数据库,所以当我找到记录时,我点击一个电子邮件地址,然后打开电子邮件。但我有更新问题,当我想对条目进行更正时,当我按更新时,电子邮件消失,我得到: 注意:未定义索引:第36行/Applications/XAMPP/xamppfiles/htdocs/robocze/mydata_dodaj_test_1.php中的邮件

我可以添加记录,但我无法更新...

你能帮助我吗,谢谢你

代码:

<?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 个答案:

答案 0 :(得分:-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],而不是您表单中的位置。