Database update niet:
Wat doet het niet?
Nou, het select gaat goed, en de options ook, maar wanneer ik mijn database will updaten met de aangepaste text in de input box, gaat het mis, de database word niet geupdate en de comment blijf dus gewoon het zelfde, hier is mijn script:
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link href="../style.css" rel="stylesheet" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="JavaScript">
<!--
function formCheck(formobj){
// Enter name of mandatory fields
var fieldRequired = Array("questionPopulate");
// Enter field description to appear in the dialog box
var fieldDescription = Array("Comment");
// dialog message
var alertMsg = "Please complete the following fields:\n";
var l_Msg = alertMsg.length;
for (var i = 0; i < fieldRequired.length; i++){
var obj = formobj.elements[fieldRequired[i]];
if (obj){
switch(obj.type){
case "select-one":
if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
case "select-multiple":
if (obj.selectedIndex == -1){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
case "text":
case "textarea":
if (obj.value == "" || obj.value == null){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
default:
}
if (obj.type == undefined){
var blnchecked = false;
for (var j = 0; j < obj.length; j++){
if (obj[j].checked){
blnchecked = true;
}
}
if (!blnchecked){
alertMsg += " - " + fieldDescription[i] + "\n";
}
}
}
}
if (alertMsg.length == l_Msg){
return true;
}else{
alert(alertMsg);
return false;
}
}
// -->
</script>
<script language="javascript">
function populateTextField()
{
var selectedQuestion=document.getElementById("selectionPanel").value;
if(selectedQuestion!="select")
{
document.getElementById("questionPopulate").value=selectedQuestion;
}
}
</script>
</head>
<body>
<center>
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("a", $con);
$query = " SELECT * FROM a " .
"ORDER BY id DESC";
$result = mysql_query($query) or die('Error, query failed');
echo("<form method='post' onsubmit='return formCheck(this);'>
<select name='selectionPanel' id='selectionPanel' onChange='populateTextField()')>
<option name='a' value='Select'>Select</option>
");
while($row = mysql_fetch_array($result))
{
echo "<option name='a' value='".$row['comment']."'>".$row['question']."</option>";
}
echo("</select><br />");
echo("<br /><input type='text' name='questionPopulate' id='questionPopulate'></input>
<button type='submit' value='submit'>Submit</button>
</form>");
if(isset($_POST['submit']))
{
$uComment = $_POST['questionPopulate'];
$quest = $_POST['selectionPanel'];
$query = "UPDATE `a` SET `comment`='$uComment' WHERE (`comment`='$quest')";
mysql_query($query);
}
mysql_close($con);
?>
</center>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link href="../style.css" rel="stylesheet" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="JavaScript">
<!--
function formCheck(formobj){
// Enter name of mandatory fields
var fieldRequired = Array("questionPopulate");
// Enter field description to appear in the dialog box
var fieldDescription = Array("Comment");
// dialog message
var alertMsg = "Please complete the following fields:\n";
var l_Msg = alertMsg.length;
for (var i = 0; i < fieldRequired.length; i++){
var obj = formobj.elements[fieldRequired[i]];
if (obj){
switch(obj.type){
case "select-one":
if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
case "select-multiple":
if (obj.selectedIndex == -1){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
case "text":
case "textarea":
if (obj.value == "" || obj.value == null){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
default:
}
if (obj.type == undefined){
var blnchecked = false;
for (var j = 0; j < obj.length; j++){
if (obj[j].checked){
blnchecked = true;
}
}
if (!blnchecked){
alertMsg += " - " + fieldDescription[i] + "\n";
}
}
}
}
if (alertMsg.length == l_Msg){
return true;
}else{
alert(alertMsg);
return false;
}
}
// -->
</script>
<script language="javascript">
function populateTextField()
{
var selectedQuestion=document.getElementById("selectionPanel").value;
if(selectedQuestion!="select")
{
document.getElementById("questionPopulate").value=selectedQuestion;
}
}
</script>
</head>
<body>
<center>
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("a", $con);
$query = " SELECT * FROM a " .
"ORDER BY id DESC";
$result = mysql_query($query) or die('Error, query failed');
echo("<form method='post' onsubmit='return formCheck(this);'>
<select name='selectionPanel' id='selectionPanel' onChange='populateTextField()')>
<option name='a' value='Select'>Select</option>
");
while($row = mysql_fetch_array($result))
{
echo "<option name='a' value='".$row['comment']."'>".$row['question']."</option>";
}
echo("</select><br />");
echo("<br /><input type='text' name='questionPopulate' id='questionPopulate'></input>
<button type='submit' value='submit'>Submit</button>
</form>");
if(isset($_POST['submit']))
{
$uComment = $_POST['questionPopulate'];
$quest = $_POST['selectionPanel'];
$query = "UPDATE `a` SET `comment`='$uComment' WHERE (`comment`='$quest')";
mysql_query($query);
}
mysql_close($con);
?>
</center>
</body>
</html>
Gewijzigd op 01/01/1970 01:00:00 door Stefan Candan
Niemand een idee?
Dan kunnen we zien of de query wel goed gaat.
Dan zegt ie niks
2. Rare kopieen van variabelen
3. Onoverzichtelijk door niet in te springen
Zodra je dat verbeterd heb durf ik te wedden dat je de fout zelf al ziet.
Daarnaast zou ik ook ff $quest echo'en en kijken of een waarde uitkomt die ook echt bestaat.
Ik zie het al, de submit button was niet genamed dus $_POST['submit'] bestond helemaal niet dus de IF werd niet uitgevoerd lol
Overigens doe je dat met $_SERVER['REQUEST_METHOD'] en niet met $_POST['submit'].