sql query wordt niet uitgevoerd
Nu ben ik echt het spoor bijster.
Ik heb nu een stukje code, die de UPDATE niet uitvoerd.
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php
echo "Updating mail info<br>";
$user = $_SESSION['Name'];
$id = $_GET['id'];
echo $user."<br>".$id."<br>";
$sql = 'UPDATE Mail SET By="'.$user.'" WHERE ID="'.$id.'"';
// if(mysqli_query($connect, $sql)) {
// echo "<br>Record Updated Succesfully";
// } else {
// echo "<br>Error Updating record";
// }
echo $sql;
// header('Location: index.php?menu=contact');
?>
echo "Updating mail info<br>";
$user = $_SESSION['Name'];
$id = $_GET['id'];
echo $user."<br>".$id."<br>";
$sql = 'UPDATE Mail SET By="'.$user.'" WHERE ID="'.$id.'"';
// if(mysqli_query($connect, $sql)) {
// echo "<br>Record Updated Succesfully";
// } else {
// echo "<br>Error Updating record";
// }
echo $sql;
// header('Location: index.php?menu=contact');
?>
Haal ik de // voor de onderste code weg, doet hij ook niks en de echo output is wel okay.
Maar hij zet niks in de Dbase weg terwijl de DBase wel de juiste velden heeft
output van de echo
Quote:
Updating mail info
Arno van Zanten
1
UPDATE Mail SET By="Arno van Zanten" WHERE ID="1"
Arno van Zanten
1
UPDATE Mail SET By="Arno van Zanten" WHERE ID="1"
Probeer `By` of verander de veldnaam.
https://mariadb.com/kb/en/reserved-words/
Je kan het testen als je de query direct op de database loslaat.
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php
echo "Updating mail info<br>";
$user = $_SESSION['Name'];
$id = $_GET['id'];
echo $user."<br>".$id."<br>";
// UPDATE `Mail` SET `User`='Arno van Zanten' WHERE id='1'
$sql = 'UPDATE Mail SET User="'.$user.'" WHERE ID="'.$id.'"';
// if(mysqli_query($connect, $sql)) {
// echo "<br>Record Updated Succesfully";
// } else {
// echo "<br>Error Updating record";
// }
echo $sql;
header('Location: index.php?menu=contact');
?>
echo "Updating mail info<br>";
$user = $_SESSION['Name'];
$id = $_GET['id'];
echo $user."<br>".$id."<br>";
// UPDATE `Mail` SET `User`='Arno van Zanten' WHERE id='1'
$sql = 'UPDATE Mail SET User="'.$user.'" WHERE ID="'.$id.'"';
// if(mysqli_query($connect, $sql)) {
// echo "<br>Record Updated Succesfully";
// } else {
// echo "<br>Error Updating record";
// }
echo $sql;
header('Location: index.php?menu=contact');
?>
// UPDATE `Mail` SET `User`='Arno van Zanten' WHERE id='1' heb ik uit de Dbase gepakt, deze werkt, maar waarom die in de code staat niet?
En id='1' kan gewoon id=1 zijn.
Gewijzigd op 04/06/2022 20:24:41 door - SanThe -
Ja die bestaat, deze page wort in include gebruikt
Echo mysqli_error($connect) eens.
- SanThe - op 04/06/2022 20:30:52:
Echo mysqli_error($connect) eens.
geen error
Toevoeging op 04/06/2022 20:36:48:
- SanThe - op 04/06/2022 20:30:52:
Echo mysqli_error($connect) eens.
geen error
maar doe ik dit :
echo mysqli_error($sql);
Dan stopt de code en krijg ik geen output.
En var_dump($connect);
- SanThe - op 04/06/2022 20:42:53:
En var_dump($connect);
Dan krijg ik dit :
object(mysqli)#1 (18) { ["affected_rows"]=> int(-1) ["client_info"]=> string(13) "mysqlnd 8.1.6" ["client_version"]=> int(80106) ["connect_errno"]=> int(0) ["connect_error"]=> NULL ["errno"]=> int(0) ["error"]=> string(0) "" ["error_list"]=> array(0) { } ["field_count"]=> int(0) ["host_info"]=> string(25) "Localhost via UNIX socket" ["info"]=> NULL ["insert_id"]=> int(0) ["server_info"]=> string(25) "10.1.48-MariaDB-1~stretch" ["server_version"]=> int(100148) ["sqlstate"]=> string(5) "00000" ["protocol_version"]=> int(10) ["thread_id"]=> int(52987081) ["warning_count"]=> int(0) } UPDATE Mail SET User="Arno van Zanten" WHERE ID="1"
Ik weet ook dat de sql naar kleine en hoofdletters kijkt, daar ben ik me van bewust
En als je het script uitvoert dan geeft ie "Error Updating record"?
Nope, daar hang ie op vast
Code (php)
1
2
3
4
5
6
2
3
4
5
6
if(mysqli_query($connect, $sql)) {
echo "<br>Record Updated Succesfully";
} else {
echo "<br>Error Updating record";
}
echo $sql;
echo "<br>Record Updated Succesfully";
} else {
echo "<br>Error Updating record";
}
echo $sql;
Doet ie geen van die twee echo's in de if maar wel de echo $sql?
maar nu een ander klein probleem, dat daar mee te maken heeft
Ik wil weten of er in een veld van de dbase iets ingevuld is.
Maar ik snap niet hoe dit moet
En is ID of id?
ID
Wat zit daar in? Naam of leeg?
Toevoeging op 04/06/2022 20:59:19:
contac.php
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
$sql = 'SELECT * FROM Mail';
$result = mysqli_query($connect, $sql);
$mails = mysqli_fetch_all($result, MYSQLI_ASSOC);
mysqli_free_result($result);
mysqli_close($connect);
echo "</td>
</tr>
<tr>
<td>From</td><td>Email address</td><td>Phone Number</td><td colspan='2'>Website</td><td>Recieved</td><td>Read by</td>
</tr>";
foreach($mails as $mail) {
echo "
<tr>
<td><a href='index.php?menu=read&id=".$mail['ID']."'>".$mail['Name']."</a></td>
<td>".$mail['Email']."</td><td>".$mail['Phone']."</td>
<td colspan='2'>".$mail['URL']."</td>
<td>".date('m-d-Y',$mail['Time'])."</td>";
if(isset($mail['User'])){
echo "Nobody";
} else {
echo "<td>".$mail['User']."</td>";
}
"
</tr>";
}
?>
$sql = 'SELECT * FROM Mail';
$result = mysqli_query($connect, $sql);
$mails = mysqli_fetch_all($result, MYSQLI_ASSOC);
mysqli_free_result($result);
mysqli_close($connect);
echo "</td>
</tr>
<tr>
<td>From</td><td>Email address</td><td>Phone Number</td><td colspan='2'>Website</td><td>Recieved</td><td>Read by</td>
</tr>";
foreach($mails as $mail) {
echo "
<tr>
<td><a href='index.php?menu=read&id=".$mail['ID']."'>".$mail['Name']."</a></td>
<td>".$mail['Email']."</td><td>".$mail['Phone']."</td>
<td colspan='2'>".$mail['URL']."</td>
<td>".date('m-d-Y',$mail['Time'])."</td>";
if(isset($mail['User'])){
echo "Nobody";
} else {
echo "<td>".$mail['User']."</td>";
}
"
</tr>";
}
?>
readmail.php
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
$sql = 'SELECT * FROM Mail WHERE ID="'.$_GET['id'].'"';
$result = mysqli_query($connect, $sql);
$mails = mysqli_fetch_all($result, MYSQLI_ASSOC);
mysqli_free_result($result);
mysqli_close($connect);
foreach($mails as $mail) {
echo "
<tr>
<td colspan='3'>From :".$mail['Name']."</td>
<td colspan='4'>Email address: ".$mail['Email']."</td>
</tr>
<tr>
<td colspan='3'>Phone Number :".$mail['Phone']."</td>
<td colspan='4'>Website :".$mail['URL']."</td>
</tr>
<tr>
<td colspan='7'>Recieved :".date('m-d-Y',$mail['Time'])."</td>
</tr>
<tr>
<td colspan='7'>Message :<br>"
.nl2br($mail['Message'],false)."</td>
</tr>
<tr>
<td colspan='7' align='right'><a href='index.php?menu=back&id=".$_GET['id']."'>Go back</a></td>
</tr>";
}
?>
$sql = 'SELECT * FROM Mail WHERE ID="'.$_GET['id'].'"';
$result = mysqli_query($connect, $sql);
$mails = mysqli_fetch_all($result, MYSQLI_ASSOC);
mysqli_free_result($result);
mysqli_close($connect);
foreach($mails as $mail) {
echo "
<tr>
<td colspan='3'>From :".$mail['Name']."</td>
<td colspan='4'>Email address: ".$mail['Email']."</td>
</tr>
<tr>
<td colspan='3'>Phone Number :".$mail['Phone']."</td>
<td colspan='4'>Website :".$mail['URL']."</td>
</tr>
<tr>
<td colspan='7'>Recieved :".date('m-d-Y',$mail['Time'])."</td>
</tr>
<tr>
<td colspan='7'>Message :<br>"
.nl2br($mail['Message'],false)."</td>
</tr>
<tr>
<td colspan='7' align='right'><a href='index.php?menu=back&id=".$_GET['id']."'>Go back</a></td>
</tr>";
}
?>
mailsaw.php
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php
echo "Updating mail info<br>";
$user = $_SESSION['Name'];
$id = $_GET['id'];
echo $user."<br>".$id."<br>";
// UPDATE `Mail` SET `User`='Arno van Zanten' WHERE id='1'
$sql = 'UPDATE Mail SET User="'.$user.'" WHERE ID="'.$id.'"';
// var_dump($connect);
// echo mysqli_error($connect);
// echo mysqli_error($sql);
if(mysqli_query($connect, $sql)) {
echo "<br>Record Updated Succesfully";
} else {
echo "<br>Error Updating record";
}
echo $sql;
header('Location: index.php?menu=contact');
?>
echo "Updating mail info<br>";
$user = $_SESSION['Name'];
$id = $_GET['id'];
echo $user."<br>".$id."<br>";
// UPDATE `Mail` SET `User`='Arno van Zanten' WHERE id='1'
$sql = 'UPDATE Mail SET User="'.$user.'" WHERE ID="'.$id.'"';
// var_dump($connect);
// echo mysqli_error($connect);
// echo mysqli_error($sql);
if(mysqli_query($connect, $sql)) {
echo "<br>Record Updated Succesfully";
} else {
echo "<br>Error Updating record";
}
echo $sql;
header('Location: index.php?menu=contact');
?>
Dit hoort bij elkaar
Gedaan maar blijft het zelfe doen