Kan niet editen in PHP script
Ik zit echt met een heel vaag probleem. Ik kan bepaalde gegevens niet updaten maar wel adden en in PHPmyAdmin kan ik ze ook editen ik kan het probleem niet echt vinden.
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
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
<?php
//connect with the db
require_once 'inc/connect.php';
error_reporting(E_ALL);
//getting the posted information
$id = htmlspecialchars($_POST['id']);
$name = htmlspecialchars($_POST['name']);
$price = htmlspecialchars($_POST['price']);
$category = htmlspecialchars($_POST['category']);
$discription = $_POST['text'];
$image= strtolower($_FILES['image']['name']);
if($image != NULL){
//Variables needed for uploadImage function:
$img_ff = 'image';
$dst_path = '../articles/';
$dst_img = strtolower($_FILES['image']['name']);
$dst_cpl = $dst_path . basename($dst_img);
if((uploadImage($img_ff, $dst_path, $dst_img)) == true){
//Variables needed for resizeImage function:
$src_img = $dst_img;
$dst_img = preg_replace('/\.[^.]*$/', '', $src_img) . '_thumb.jpg';
$src_path = $dst_path;
$dst_path = '../articles/thumbs/';
$dst_w = '150';
$dst_h = '150';
$dst_quality = '100';
if((resizeImage($src_img, $dst_img, $src_path, $dst_path, $dst_w, $dst_h, $dst_quality)) == false){
die ('<p>Could not resize the image</p>');
}
}else{
die ('<p>Could not upload the image</p>');
}
$query = "UPDATE article SET name='$name', price='$price', discription='$discription', image='$image', thumb='$dst_path$dst_img', category='$category' WHERE id='$id'";
if (!mysql_query($query)){
die('<h1>Something went wrong!!</h1><p>The article has not been edit because of this following mysql error : ' . mysql_error() . '</p>');
}else{
echo '<h1>Edit Succesfully</h1>';
echo '<p>The article "' . $name . '" has been edit succesfull</p>';
echo '<p><a href="art.index.php">Click here to go to the article </a></p>';
}
}else{
$query = "UPDATE article SET name='$name', price='$price', discription='$discription', category='$category' WHERE id=$id";
if (!mysql_query($query))
{
die('<h1>Something went wrong!!</h1><p>The article has not been edit because of this following mysql error : ' . mysql_error() . '</p>');
}else{
echo '<h1>Edit Succesfully</h1>';
echo '<p>The article "' . $name . '" has been edit succesfull</p>';
echo '<p><a href="art.index.php">Click here to go to the article </a></p>';
}
}
?>
//connect with the db
require_once 'inc/connect.php';
error_reporting(E_ALL);
//getting the posted information
$id = htmlspecialchars($_POST['id']);
$name = htmlspecialchars($_POST['name']);
$price = htmlspecialchars($_POST['price']);
$category = htmlspecialchars($_POST['category']);
$discription = $_POST['text'];
$image= strtolower($_FILES['image']['name']);
if($image != NULL){
//Variables needed for uploadImage function:
$img_ff = 'image';
$dst_path = '../articles/';
$dst_img = strtolower($_FILES['image']['name']);
$dst_cpl = $dst_path . basename($dst_img);
if((uploadImage($img_ff, $dst_path, $dst_img)) == true){
//Variables needed for resizeImage function:
$src_img = $dst_img;
$dst_img = preg_replace('/\.[^.]*$/', '', $src_img) . '_thumb.jpg';
$src_path = $dst_path;
$dst_path = '../articles/thumbs/';
$dst_w = '150';
$dst_h = '150';
$dst_quality = '100';
if((resizeImage($src_img, $dst_img, $src_path, $dst_path, $dst_w, $dst_h, $dst_quality)) == false){
die ('<p>Could not resize the image</p>');
}
}else{
die ('<p>Could not upload the image</p>');
}
$query = "UPDATE article SET name='$name', price='$price', discription='$discription', image='$image', thumb='$dst_path$dst_img', category='$category' WHERE id='$id'";
if (!mysql_query($query)){
die('<h1>Something went wrong!!</h1><p>The article has not been edit because of this following mysql error : ' . mysql_error() . '</p>');
}else{
echo '<h1>Edit Succesfully</h1>';
echo '<p>The article "' . $name . '" has been edit succesfull</p>';
echo '<p><a href="art.index.php">Click here to go to the article </a></p>';
}
}else{
$query = "UPDATE article SET name='$name', price='$price', discription='$discription', category='$category' WHERE id=$id";
if (!mysql_query($query))
{
die('<h1>Something went wrong!!</h1><p>The article has not been edit because of this following mysql error : ' . mysql_error() . '</p>');
}else{
echo '<h1>Edit Succesfully</h1>';
echo '<p>The article "' . $name . '" has been edit succesfull</p>';
echo '<p><a href="art.index.php">Click here to go to the article </a></p>';
}
}
?>
Code (php)
1
2
3
2
3
<?PHP
$query = "UPDATE article SET name='$name', price='$price', discription='$discription', image='$image', thumb='$dst_path$dst_img', category='$category' WHERE id='$id'";
?>
$query = "UPDATE article SET name='$name', price='$price', discription='$discription', image='$image', thumb='$dst_path$dst_img', category='$category' WHERE id='$id'";
?>
verander naar:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
<?PHP
$query = "UPDATE article
SET
name='".$name."',
price='".$price."',
discription='".$discription."',
image='".$image."',
thumb='".$dst_path$dst_img."',
category='".$category."'
WHERE
id=".$id."";
?>
$query = "UPDATE article
SET
name='".$name."',
price='".$price."',
discription='".$discription."',
image='".$image."',
thumb='".$dst_path$dst_img."',
category='".$category."'
WHERE
id=".$id."";
?>
ik denk trouwens dat die thumb niet klopt
het werkt niet maar ik krijg nog steeds geen foutmelding of iets dergelijks.
En waar controleer jij of er wel daadwerkelijk records geupdate zijn? Gebruik mysql_affected_rows() na je update query om dat te bepalen...
@blanche hij geeft nu aan dat hij 0 affected rows heeft. hoe kan dat?
Ruben schreef op 25.11.2008 20:33:
@blanche hij geeft nu aan dat hij 0 affected rows heeft. hoe kan dat?
Er zijn geen rijen bijgewerkt
doe eens
echo $query;
Oke hij doet het. Ik had een id uit een verkeerde tabel gepost.. heel handig :S