edit / delete
lijst wordt netjes getoond, bij edit worden velden netjes gevuld maar bij submit of delete geen succes.
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?
//connect to mysql
mysql_connect("localhost","login","password");
//select which database you want to edit
mysql_select_db("mijn_DB");
//If cmd has not been initialized
if(!isset($cmd))
{
//display all
$result = mysql_query("select * from locaties order by id");
//run the while loop
while($row=mysql_fetch_array($result))
{
//grab the names
$id = $row["id"];
$lat = $row["lat"];
$lon = $row["lon"];
$naam = $row["naam"];
$adres = $row["adres"];
$postcode = $row["postcode"];
$plaats = $row["plaats"];
$url = $row["url"];
$icon = $row["icon"];
$tel = $row["tel"];
//make edit / delete links
echo "$id $naam <a href='edit.php?cmd=edit&id=$id'> Edit</a> / <a href='edit.php?cmd=delete&id=$id'> Delete</a>";
echo "<br>";
}
}
?>
<?
//edit option
if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
{
if (!isset($_POST["submit"]))
{
$id = $_GET["id"];
$sql = "SELECT * FROM locaties WHERE id=$id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
?>
<?
//delete option
if($_GET["cmd"]=="delete")
{
$sql = "DELETE FROM locaties WHERE id=$id";
$result = mysql_query($sql);
echo "Row deleted!";
}
?>
<form action="edit.php" method="post">
<input type=hidden name="id" value="<?php echo $myrow["id"] ?>">
<TABLE>
<TR>
<TD>Locatienaam:</TD>
<TD><INPUT TYPE='TEXT' NAME='naam' VALUE='<?php echo $myrow["naam"] ?>' size=60></TD>
</TR>
<TR>
<TD>Adres:</TD>
<TD><input type='TEXT' name='adres' value='<?php echo $myrow["adres"] ?>' size=60></TD>
</TR>
<TR>
<TD>Postcode</TD>
<TD><input type='TEXT' name='postcode' value='<?php echo $myrow["postcode"] ?>' size=60></TD>
</TR>
<TR>
<TD>Plaats</TD>
<TD><input type='TEXT' name='plaats' value='<?php echo $myrow["plaats"] ?>' size=60></TD>
</TR><br>
<TR>
<TD>Website</TD>
<TD><input type='TEXT' name='url' value='<?php echo $myrow["url"] ?>' size=60></TD>
</TR>
<TR>
<TD>Telefoon</TD>
<TD><input type='TEXT' name='tel' value='<?php echo $myrow["tel"] ?>' size=60></TD>
</TR>
<TR>
<TD>Soortlocatie</TD>
<TD>
<SELECT NAME='icon'>
<OPTION VALUE='gray'>winkel
<OPTION VALUE='green'>autoclub
<OPTION VALUE='red'>vliegclub
<OPTION VALUE='blue'>botenclub
</SELECT>
</TD>
</TR>
<TR>
<TD>Lat</TD>
<TD>
<INPUT TYPE='TEXT' NAME='lat' VALUE='<?php echo $myrow["lat"] ?>' size=60>
</TD>
</TR>
<TR>
<TD>Lon</TD>
<TD>
<INPUT TYPE='TEXT' NAME='lon' VALUE='<?php echo $myrow["lon"] ?>' size=60>
</TD>
</TR>
<TR>
<TD></TD><br>
<TD><INPUT TYPE="submit" name="submit" value="submit"></TD>
</TR>
</TABLE>
<input type="hidden" name="cmd" value="edit">
</form>
<? } ?>
<?
if ($_POST["$submit"])
{
$lat = $_POST['lat'];
$lon = $_POST['lon'];
$naam = $_POST['naam'];
$adres = $_POST['adres'];
$postcode = $_POST['postcode'];
$plaats = $_POST['plaats'];
$url = $_POST['url'];
$icon = $_POST['icon'];
$tel = $_POST['tel'];
$sql = "UPDATE locaties SET naam='$naam',adres='$adres',postcode='$postcode',plaats='$plaats',url='$url',icon='$con',tel='$tel',lat='$lat',lon='$lon' WHERE id=$id";
$result = mysql_query($sql);
echo "Thank you! Information updated.";
}
}
?>
//connect to mysql
mysql_connect("localhost","login","password");
//select which database you want to edit
mysql_select_db("mijn_DB");
//If cmd has not been initialized
if(!isset($cmd))
{
//display all
$result = mysql_query("select * from locaties order by id");
//run the while loop
while($row=mysql_fetch_array($result))
{
//grab the names
$id = $row["id"];
$lat = $row["lat"];
$lon = $row["lon"];
$naam = $row["naam"];
$adres = $row["adres"];
$postcode = $row["postcode"];
$plaats = $row["plaats"];
$url = $row["url"];
$icon = $row["icon"];
$tel = $row["tel"];
//make edit / delete links
echo "$id $naam <a href='edit.php?cmd=edit&id=$id'> Edit</a> / <a href='edit.php?cmd=delete&id=$id'> Delete</a>";
echo "<br>";
}
}
?>
<?
//edit option
if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
{
if (!isset($_POST["submit"]))
{
$id = $_GET["id"];
$sql = "SELECT * FROM locaties WHERE id=$id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
?>
<?
//delete option
if($_GET["cmd"]=="delete")
{
$sql = "DELETE FROM locaties WHERE id=$id";
$result = mysql_query($sql);
echo "Row deleted!";
}
?>
<form action="edit.php" method="post">
<input type=hidden name="id" value="<?php echo $myrow["id"] ?>">
<TABLE>
<TR>
<TD>Locatienaam:</TD>
<TD><INPUT TYPE='TEXT' NAME='naam' VALUE='<?php echo $myrow["naam"] ?>' size=60></TD>
</TR>
<TR>
<TD>Adres:</TD>
<TD><input type='TEXT' name='adres' value='<?php echo $myrow["adres"] ?>' size=60></TD>
</TR>
<TR>
<TD>Postcode</TD>
<TD><input type='TEXT' name='postcode' value='<?php echo $myrow["postcode"] ?>' size=60></TD>
</TR>
<TR>
<TD>Plaats</TD>
<TD><input type='TEXT' name='plaats' value='<?php echo $myrow["plaats"] ?>' size=60></TD>
</TR><br>
<TR>
<TD>Website</TD>
<TD><input type='TEXT' name='url' value='<?php echo $myrow["url"] ?>' size=60></TD>
</TR>
<TR>
<TD>Telefoon</TD>
<TD><input type='TEXT' name='tel' value='<?php echo $myrow["tel"] ?>' size=60></TD>
</TR>
<TR>
<TD>Soortlocatie</TD>
<TD>
<SELECT NAME='icon'>
<OPTION VALUE='gray'>winkel
<OPTION VALUE='green'>autoclub
<OPTION VALUE='red'>vliegclub
<OPTION VALUE='blue'>botenclub
</SELECT>
</TD>
</TR>
<TR>
<TD>Lat</TD>
<TD>
<INPUT TYPE='TEXT' NAME='lat' VALUE='<?php echo $myrow["lat"] ?>' size=60>
</TD>
</TR>
<TR>
<TD>Lon</TD>
<TD>
<INPUT TYPE='TEXT' NAME='lon' VALUE='<?php echo $myrow["lon"] ?>' size=60>
</TD>
</TR>
<TR>
<TD></TD><br>
<TD><INPUT TYPE="submit" name="submit" value="submit"></TD>
</TR>
</TABLE>
<input type="hidden" name="cmd" value="edit">
</form>
<? } ?>
<?
if ($_POST["$submit"])
{
$lat = $_POST['lat'];
$lon = $_POST['lon'];
$naam = $_POST['naam'];
$adres = $_POST['adres'];
$postcode = $_POST['postcode'];
$plaats = $_POST['plaats'];
$url = $_POST['url'];
$icon = $_POST['icon'];
$tel = $_POST['tel'];
$sql = "UPDATE locaties SET naam='$naam',adres='$adres',postcode='$postcode',plaats='$plaats',url='$url',icon='$con',tel='$tel',lat='$lat',lon='$lon' WHERE id=$id";
$result = mysql_query($sql);
echo "Thank you! Information updated.";
}
}
?>
pagina heet edit.php en alles hierboven staat erin.
wat gaat er mis en wie wil me helpen zodat het werkt.
Gewijzigd op 01/01/1970 01:00:00 door Milcoi
1. de validatie en controles doet op $_GET
2. de validatie en controles doet op $_POST
En je kan wel brullen geen fouten, echter dien je toch het een en ander af te dwingen door bovenaan in je script(s) het volgende te plaatsen:
En voor de rest:
- maak geen overbodige variabelen aan
- gebruik bij _fetch_array ook de 2de parameter of beter gebruik _fetch_assoc
- qoute je strings met '' en niet met "", je wordt dan gedwongen de php variabelen buiten de string te plaatsen. (muz sql statements!)
- sql injectie --> _real_escape_string() nooit van gehoord zeker
Gewijzigd op 01/01/1970 01:00:00 door Noppes
sorry, ben nieuw met php
Milcoi schreef op 20.06.2009 15:18:
PHP beginnershandleidingsorry, ben nieuw met php
SQL beginnershandleiding
Misschien een idee om dan eens naar deze twee handleidingen te kijken? Succes!
bijv. bij edit, schiet de pagina weer terug naar boven terwijl er onderaan edit velden bij zijn gekomen.
zo ook met delete, dan schiet de pagina ook weer terug naar boven terwijl de confirm text onder komt te staan.
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?
mysql_connect("localhost","xxx_user","xxx");
mysql_select_db("xxx_locaties");
//If cmd has not been initialized
if(!isset($cmd))
{
$result = mysql_query("select * from locaties order by id");
while($r=mysql_fetch_assoc($result))
{
$id=$r["id"];
$naam=$r["naam"];
$adres=$r["adres"];
$postcode=$r["postcode"];
$plaats=$r["plaats"];
$tel=$r["tel"];
$url=$r["url"];
$icon=$r["icon"];
$lat=$r["lat"];
$lon=$r["lon"];
echo "$id $naam<a href='edit.php?cmd=edit&id=$id'> Edit</a> / <a href='edit.php?cmd=delete&id=$id'> Delete</a>";
echo "<br>";
}
}
?>
<?
if($_GET["cmd"]=="delete")
{
$sql = "DELETE FROM locaties WHERE id=$id";
$result = mysql_query($sql);
echo "Row deleted!";
}
?>
<?
if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
{
if (!isset($_POST["submit"]))
{
$id = $_GET["id"];
$sql = "SELECT * FROM locaties WHERE id=$id";
$result = mysql_query($sql);
$myrow = mysql_fetch_assoc($result);
?>
<form action="edit.php" method="post">
<input type=hidden name="id" value="<?php echo $myrow["id"] ?>">
<TABLE width="849">
<TR>
<TD width="150">Locatienaam:</TD>
<TD width="360"><INPUT TYPE='TEXT' NAME='naam' VALUE='<?php echo $myrow["naam"] ?>' size=60></TD>
<TD width="323" rowspan="10" valign="top"></TD>
</TR>
<TR>
<TD>Adres:</TD>
<TD><input type='TEXT' name='adres' value='<?php echo $myrow["adres"] ?>' size=60></TD>
</TR>
<TR>
<TD>Postcode</TD>
<TD><input type='TEXT' name='postcode' value='<?php echo $myrow["postcode"] ?>' size=60></TD>
</TR>
<TR>
<TD>Plaats</TD>
<TD><input type='TEXT' name='plaats' value='<?php echo $myrow["plaats"] ?>' size=60></TD>
</TR><br>
<TR>
<TD>Website</TD>
<TD><input type='TEXT' name='url' value='<?php echo $myrow["url"] ?>' size=60></TD>
</TR>
<TR>
<TD>Telefoon</TD>
<TD><input type='TEXT' name='tel' value='<?php echo $myrow["tel"] ?>' size=60></TD>
</TR>
<TR>
<TD>Soortlocatie</TD>
<TD>
<SELECT NAME='icon'>
<OPTION VALUE='gray'>winkel
<OPTION VALUE='green'>autoclub
<OPTION VALUE='red'>vliegclub
<OPTION VALUE='blue'>botenclub
</SELECT>
</TD>
</TR>
<TR>
<TD>Lat</TD>
<TD>
<INPUT ID='lat' TYPE='TEXT' NAME='lat' VALUE='<?php echo $myrow["lat"] ?>' size=60>
</TD>
</TR>
<TR>
<TD>Lon</TD>
<TD>
<INPUT ID='lon' TYPE='TEXT' NAME='lon' VALUE='<?php echo $myrow["lon"] ?>' size=60>
</TD>
</TR>
<TR>
<TD></TD><br>
<TD>
<input type="hidden" name="cmd" value="edit">
<input type="submit" name="submit" value="submit">
</TD>
</TR>
</TABLE>
</form>
<? } ?>
<?
if ($_POST["submit"])
{
$naam = $_POST["naam"];
$adres = $_POST["adres"];
$postcode = $_POST["postcode"];
$plaats = $_POST["plaats"];
$url = $_POST["url"];
$tel = $_POST["tel"];
$icon = $_POST["icon"];
$lat = $_POST["lat"];
$lon = $_POST["lon"];
$sql = "UPDATE locaties SET naam='$naam',adres='$adres',postcode='$postcode',plaats='$plaats',url='$url',tel='$tel',icon='$icon',lat='$lat',lon='$lon' WHERE id=$id";
$result = mysql_query($sql);
echo "Thank you! Information updated.";
}
}
?>
mysql_connect("localhost","xxx_user","xxx");
mysql_select_db("xxx_locaties");
//If cmd has not been initialized
if(!isset($cmd))
{
$result = mysql_query("select * from locaties order by id");
while($r=mysql_fetch_assoc($result))
{
$id=$r["id"];
$naam=$r["naam"];
$adres=$r["adres"];
$postcode=$r["postcode"];
$plaats=$r["plaats"];
$tel=$r["tel"];
$url=$r["url"];
$icon=$r["icon"];
$lat=$r["lat"];
$lon=$r["lon"];
echo "$id $naam<a href='edit.php?cmd=edit&id=$id'> Edit</a> / <a href='edit.php?cmd=delete&id=$id'> Delete</a>";
echo "<br>";
}
}
?>
<?
if($_GET["cmd"]=="delete")
{
$sql = "DELETE FROM locaties WHERE id=$id";
$result = mysql_query($sql);
echo "Row deleted!";
}
?>
<?
if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
{
if (!isset($_POST["submit"]))
{
$id = $_GET["id"];
$sql = "SELECT * FROM locaties WHERE id=$id";
$result = mysql_query($sql);
$myrow = mysql_fetch_assoc($result);
?>
<form action="edit.php" method="post">
<input type=hidden name="id" value="<?php echo $myrow["id"] ?>">
<TABLE width="849">
<TR>
<TD width="150">Locatienaam:</TD>
<TD width="360"><INPUT TYPE='TEXT' NAME='naam' VALUE='<?php echo $myrow["naam"] ?>' size=60></TD>
<TD width="323" rowspan="10" valign="top"></TD>
</TR>
<TR>
<TD>Adres:</TD>
<TD><input type='TEXT' name='adres' value='<?php echo $myrow["adres"] ?>' size=60></TD>
</TR>
<TR>
<TD>Postcode</TD>
<TD><input type='TEXT' name='postcode' value='<?php echo $myrow["postcode"] ?>' size=60></TD>
</TR>
<TR>
<TD>Plaats</TD>
<TD><input type='TEXT' name='plaats' value='<?php echo $myrow["plaats"] ?>' size=60></TD>
</TR><br>
<TR>
<TD>Website</TD>
<TD><input type='TEXT' name='url' value='<?php echo $myrow["url"] ?>' size=60></TD>
</TR>
<TR>
<TD>Telefoon</TD>
<TD><input type='TEXT' name='tel' value='<?php echo $myrow["tel"] ?>' size=60></TD>
</TR>
<TR>
<TD>Soortlocatie</TD>
<TD>
<SELECT NAME='icon'>
<OPTION VALUE='gray'>winkel
<OPTION VALUE='green'>autoclub
<OPTION VALUE='red'>vliegclub
<OPTION VALUE='blue'>botenclub
</SELECT>
</TD>
</TR>
<TR>
<TD>Lat</TD>
<TD>
<INPUT ID='lat' TYPE='TEXT' NAME='lat' VALUE='<?php echo $myrow["lat"] ?>' size=60>
</TD>
</TR>
<TR>
<TD>Lon</TD>
<TD>
<INPUT ID='lon' TYPE='TEXT' NAME='lon' VALUE='<?php echo $myrow["lon"] ?>' size=60>
</TD>
</TR>
<TR>
<TD></TD><br>
<TD>
<input type="hidden" name="cmd" value="edit">
<input type="submit" name="submit" value="submit">
</TD>
</TR>
</TABLE>
</form>
<? } ?>
<?
if ($_POST["submit"])
{
$naam = $_POST["naam"];
$adres = $_POST["adres"];
$postcode = $_POST["postcode"];
$plaats = $_POST["plaats"];
$url = $_POST["url"];
$tel = $_POST["tel"];
$icon = $_POST["icon"];
$lat = $_POST["lat"];
$lon = $_POST["lon"];
$sql = "UPDATE locaties SET naam='$naam',adres='$adres',postcode='$postcode',plaats='$plaats',url='$url',tel='$tel',icon='$icon',lat='$lat',lon='$lon' WHERE id=$id";
$result = mysql_query($sql);
echo "Thank you! Information updated.";
}
}
?>
Gewijzigd op 01/01/1970 01:00:00 door Milcoi