Error:Trying to get property of non-object
Ik krijg de volgende error en ik kan de fout niet vinden. Zou iemand eens kunnen kijken en mij dan uitleggen wat ik fout doe?
Code (php)
Gewijzigd op 30/12/2017 23:02:55 door Bollie Zwollie
Kan je vermelden welke error het precies is, en waar die heen verwijst?
Notice: Trying to get property of non-object in C:\xampp\htdocs\local-dev\controller\ajax.php on line 1818
Notice: Trying to get property of non-object in C:\xampp\htdocs\local-dev\controller\ajax.php on line 1829
{"status":"success","text":"update succesvol"}
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
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
<?php
if (isset($_POST['sites_cu'])){
if($_SESSION['role'] == 'admin' or $_SESSION['role'] == 'moderator'){
$site_id = trim($_POST['site_id']);
$site_name = trim($_POST['site_name']);
$site_url = trim($_POST['site_url']);
$site_state = $_POST['site_state'];
$site_owner = trim($_POST['site_owner']);
$sql= "SELECT site_name from sites WHERE site_name='".$db->escape_string($site_name);
$result = $db->query($sql);
if ( $result->num_rows >= 1){
//$num_rows = mysqli_num_rows($result);
//var_dump($result);
//die();
$r = array('status'=> 'error', 'text'=>'The sitename is already used');
debug($r,config::debug);
}
$sql= "SELECT site_url from sites WHERE site_url='".$db->escape_string($site_url);
$result = $db->query($sql);
if ( $result->num_rows >= 1){
$r = array('status'=> 'error', 'text'=>'The URL is already used');
debug($r,config::debug);
}
$sql= "SELECT site_state from sites WHERE site_state='".$db->escape_string($site_state);
$result = $db->query($sql);
$sql= "SELECT site_owner from sites WHERE site_owner='".$db->escape_string($site_owner);
$result = $db->query($sql);
if ( $result->num_rows >= 1){
$r = array('status'=> 'error', 'text'=>'The owner is already used');
debug($r,config::debug);
}
if ($_SESSION['role'] != 'moderator'){
/* admin can do everything */
$site_state = trim($_POST['site_state']);
if ($site_id ==''){
$sql= "INSERT INTO sites (site_id, site_name, site_url, site_state, site_owner) VALUES ('".$db->escape_string($site_id)."', ".$db->escape_string($site_name).", '".$db->escape_string($site_url)."', '".$db->escape_string($site_state)."', '".$db->escape_string($site_owner)."'";
}else{
$sql= "UPDATE sites SET
`site_id`= '".$db->escape_string($site_id)."',
`site_name`= '".$db->escape_string($site_name)."',
`site_url`= '".$db->escape_string($site_url)."',
`site_state`= '".$db->escape_string($site_state)."',
`site_owner`= '".$db->escape_string($site_owner)."'
WHERE site_id =".$site_id;
}
}
if ($db->query($sql))
$r = array('status'=> 'success', 'text'=>'update succesvol');
else
$r = array('status'=> 'error', 'text'=>'er is een fout opgetreden'.$db->error);
}
debug($r,config::debug);
}
?>
if (isset($_POST['sites_cu'])){
if($_SESSION['role'] == 'admin' or $_SESSION['role'] == 'moderator'){
$site_id = trim($_POST['site_id']);
$site_name = trim($_POST['site_name']);
$site_url = trim($_POST['site_url']);
$site_state = $_POST['site_state'];
$site_owner = trim($_POST['site_owner']);
$sql= "SELECT site_name from sites WHERE site_name='".$db->escape_string($site_name);
$result = $db->query($sql);
if ( $result->num_rows >= 1){
//$num_rows = mysqli_num_rows($result);
//var_dump($result);
//die();
$r = array('status'=> 'error', 'text'=>'The sitename is already used');
debug($r,config::debug);
}
$sql= "SELECT site_url from sites WHERE site_url='".$db->escape_string($site_url);
$result = $db->query($sql);
if ( $result->num_rows >= 1){
$r = array('status'=> 'error', 'text'=>'The URL is already used');
debug($r,config::debug);
}
$sql= "SELECT site_state from sites WHERE site_state='".$db->escape_string($site_state);
$result = $db->query($sql);
$sql= "SELECT site_owner from sites WHERE site_owner='".$db->escape_string($site_owner);
$result = $db->query($sql);
if ( $result->num_rows >= 1){
$r = array('status'=> 'error', 'text'=>'The owner is already used');
debug($r,config::debug);
}
if ($_SESSION['role'] != 'moderator'){
/* admin can do everything */
$site_state = trim($_POST['site_state']);
if ($site_id ==''){
$sql= "INSERT INTO sites (site_id, site_name, site_url, site_state, site_owner) VALUES ('".$db->escape_string($site_id)."', ".$db->escape_string($site_name).", '".$db->escape_string($site_url)."', '".$db->escape_string($site_state)."', '".$db->escape_string($site_owner)."'";
}else{
$sql= "UPDATE sites SET
`site_id`= '".$db->escape_string($site_id)."',
`site_name`= '".$db->escape_string($site_name)."',
`site_url`= '".$db->escape_string($site_url)."',
`site_state`= '".$db->escape_string($site_state)."',
`site_owner`= '".$db->escape_string($site_owner)."'
WHERE site_id =".$site_id;
}
}
if ($db->query($sql))
$r = array('status'=> 'success', 'text'=>'update succesvol');
else
$r = array('status'=> 'error', 'text'=>'er is een fout opgetreden'.$db->error);
}
debug($r,config::debug);
}
?>
Waar komt $db vandaan?
Code (php)
1
$db = new mysqli($config['db_host'], $config['db_user'], $config['db_password'], $config['db_name']);
en die staat op deze page included. Andere dingen werken wel
je hebt ook foutafhandeling met $db->connect_errno, mag ik hopen?
Code (php)
- Ariën - op 30/12/2017 23:24:09:
Een instance hoort eigenlijk niet in een config, hé ;-)
Ik snap niet precies wat je hiermee bedoelt. Dit script heb ik ooit een paar jaar geleden gekocht. En nu wil ik het zelf onder de knie krijgen en probeer er daarom wat bij in te bouwen.
In je ajax.php wordt ook je instance ingeladen?
Zullen we het op $db->real_escape_string houden?
En hoe ga ik daar precies achter komen
Kijk gewoon eens goed, en met name naar het vetgedrukte, en wat jij hebt ;-)
Gewijzigd op 30/12/2017 23:44:27 door - Ariën -
Fijne jaarwisseling :)
Jij ook een fijne jaarwisseling!