Database wil niet updaten
Klein probleempje
De gegevens uit mijn database worden netjes gelezen, maar als ik ze dan wil aanpassen lijkt alles het te doen alleen de database zelf wordt niet geupdate. hieronder de codes.
1 update.php
2 update_ac.php
1:
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
$host="db01.xxxx.nl"; // Host name
$username="xxxx"; // Mysql username
$password="xxxx"; // Mysql password
$db_name="db01"; // Database name
$tbl_name="members"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// get value of id that sent from address bar
$id=$_GET['id'];
// Retrieve data from database
$sql="SELECT * FROM $tbl_name WHERE id='$id'";
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);
?>
$host="db01.xxxx.nl"; // Host name
$username="xxxx"; // Mysql username
$password="xxxx"; // Mysql password
$db_name="db01"; // Database name
$tbl_name="members"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// get value of id that sent from address bar
$id=$_GET['id'];
// Retrieve data from database
$sql="SELECT * FROM $tbl_name WHERE id='$id'";
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);
?>
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<form name="form1" method="post" action="update_ac.php">
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
<td> </td>
<td colspan="3"><strong>Update data in mysql</strong> </td>
</tr>
<tr>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
</tr>
<tr>
<td align="center"> </td>
<td align="center"><strong>Username</strong></td>
<td align="center"><strong>Password</strong></td>
<td align="center"><strong>Email</strong></td>
</tr>
<tr>
<td> </td>
<td align="center"><input name="user_name" type="text" id="user_name" value=""></td>
<td align="center"><input name="pass_word" type="text" id="pass_word" value="" size="15"></td>
<td><input name="e_mail" type="text" id="e_mail" value="" size="15"></td>
</tr>
<tr>
<td> </td>
<td><input name="id" type="hidden" id="id" value=""></td>
<td align="center"><input type="submit" name="Submit" value="Submit"></td>
<td> </td>
</tr>
</table>
</td>
</form>
</tr>
</table>
2: update_ac.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
34
35
36
37
38
39
40
41
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
<?php
$host="db01.xxxx.nl"; // Host name
$username="xxxx"; // Mysql username
$password="xxxx"; // Mysql password
$db_name="db01"; // Database name
$tbl_name="members"; // Table name
$link = mysql_connect('db01.michelvanboordt.nl', 'bp_admin', 'admin');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db('db01');
/* Update records */
mysql_query("UPDATE $tbl_name SET used=1 WHERE id < 10");
printf ("Updated records: %d\n", mysql_affected_rows());
mysql_query("COMMIT");
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// update data in mysql database
$sql="UPDATE ".$tbl_name." SET user_name='".$user_name."', pass_word='".$pass_word."', e_mail='".$e_mail."' WHERE id='".$id."'";
$result=mysql_query($sql);
// if successfully updated.
if($result){
echo "$sql";
echo "<BR>";
echo "<a href='edit.php'>View result</a>";
}
else {
echo "ERROR: " . mysql_error();
}
// close connection
mysql_close();
?>
$host="db01.xxxx.nl"; // Host name
$username="xxxx"; // Mysql username
$password="xxxx"; // Mysql password
$db_name="db01"; // Database name
$tbl_name="members"; // Table name
$link = mysql_connect('db01.michelvanboordt.nl', 'bp_admin', 'admin');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db('db01');
/* Update records */
mysql_query("UPDATE $tbl_name SET used=1 WHERE id < 10");
printf ("Updated records: %d\n", mysql_affected_rows());
mysql_query("COMMIT");
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// update data in mysql database
$sql="UPDATE ".$tbl_name." SET user_name='".$user_name."', pass_word='".$pass_word."', e_mail='".$e_mail."' WHERE id='".$id."'";
$result=mysql_query($sql);
// if successfully updated.
if($result){
echo "$sql";
echo "<BR>";
echo "<a href='edit.php'>View result</a>";
}
else {
echo "ERROR: " . mysql_error();
}
// close connection
mysql_close();
?>
In mijn browser krijg ik na het klikken op update
Updated records: -1 UPDATE members SET user_name='', pass_word='', e_mail='' WHERE id=''
ik ben niet heeeeeeel bekend met php misschien doe ik wel iets kleins fout en kijk ik er gewoo overheen
let me know
thnx
Gewijzigd op 01/01/1970 01:00:00 door Michel van B
Dank!
Thnx anyway
stom foutje
Vertel dan ook even wat er fout is