thedigicraft / Atom.CMS

Atom.CMS
56 stars 52 forks source link

#lecture19 Error while fetching settings #112

Open sami313 opened 9 years ago

sami313 commented 9 years ago

Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\series\dynamic\AtomCMS\functions\data.php on line 8

sami313 commented 9 years ago

<?php

function data_setting_vlaue($dbc, $id){

$q = "SELECT * FROM settings WHERE id = '$id'";
$r = mysqli_query($dbc, $q);

$data = mysqli_fetch_assoc($r);

return $data['value'];

}

function data_page($dbc, $id){

    $q = "SELECT * FROM pages WHERE id=$id";
    $r =  mysqli_query($dbc, $q);

    $data = mysqli_fetch_assoc($r);

    $data['body_nohtml'] =strip_tags($data['body']);

    if($data['body'] == $data['body_nohtml']){

        $data['body_formatted'] = '<p>'.$data['body'].'</p>';

    }else{

        $data['body_formatted'] =$data['body'];

    }

    return $data;

}

?>

sami313 commented 9 years ago

function data_page is working fine ...as i wore the function data_setting_value it throught that error please help me :)

JasonMate commented 9 years ago

Is that a typo in function data_setting_vlaue($dbc, $id){}

On Sat, Mar 21, 2015 at 11:39 AM, sami313 notifications@github.com wrote:

function data_page is working fine ...as i wore the function data_setting_value it throught that error please help me :)

— Reply to this email directly or view it on GitHub https://github.com/thedigicraft/Atom.CMS/issues/112#issuecomment-84408113 .

sami313 commented 9 years ago

ohhh sorry i got it thanks alot for helping out God bless you

sami313 commented 9 years ago
function data_setting_value($dbc, $id){

$q = "SELECT * FROM settings WHERE id = '$id'";
$r = mysqli_query($dbc, $q);

$data = mysqli_fetch_assoc($r);

return $data['value'];

} //function call in site page

Site Setup

$debug = data_setting_value($dbc, 'debug-status');

i am still getting that error Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\series\dynamic\AtomCMS\functions\data.php on line 8

creptor commented 9 years ago

please I would be gratefull if you read this when placing code so I can help you better -link-

now I need you to check if you actually have a table named settings and that your table has a colum with the id equals to debug-status

sami313 commented 9 years ago

yah sorry i will try to place the code that way i am new to github i will try to fallow the instructions

sami313 commented 9 years ago

localhost 127 0 0 1 atom settings phpmyadmin 4 2 11

sami313 commented 9 years ago

localhost 127 0 0 1 atom settings phpmyadmin 4 2 11 2

sami313 commented 9 years ago

localhost 127 0 0 1 atom settings phpmyadmin 4 2 11 3

sami313 commented 9 years ago

i took the screen shot i hope it will help you to have a nice look thanks for your support :)

creptor commented 9 years ago

I have found no error on that code... are you sure that it's the code where line 8 is?

creptor commented 9 years ago

You could try with my prepared statements query, I know they work for me so.. maybe I couldn't see the error and using this code will fix it.

Code:

function data_setting_value($dbc, $id){
    $stmt = $dbc->query("SELECT * FROM settings WHERE id = '$id'");
    $data = $stmt->fetch_assoc();
    return $data['value'];
}
sami313 commented 9 years ago

yah i am pretty sure should i delete that table and make it again ?

function data_setting_value($dbc, $id){

        $q = "SELECT * FROM  settings WHERE id=$id";
        $r = mysqli_query($dbc, $q) or die(mysql_error());

        $data = mysqli_fetch_assoc($r);

         return $data['value'];

}

sami313 commented 9 years ago

Fatal error: Call to a member function fetch_assoc() on boolean in C:\xampp\htdocs\series\dynamic\AtomCMS\functions\data.php on line 5### i am getting this error after using the code you have told

function data_setting_value($dbc, $id){
    $stmt = $dbc->query("SELECT * FROM settings WHERE id = '$id'");
    $data = $stmt->fetch_assoc();
    return $data['value'];

}

creptor commented 9 years ago

the sql comand is what's inside the query.

I'm sorry i guess your php version does not support prepared statements.

creptor commented 9 years ago

this is the sql comand: "SELECT * FROM settings WHERE id = (place any id)"

sami313 commented 9 years ago

ok i will try to look in update phpversion

sami313 commented 9 years ago

localhost 127 0 0 1 atom settings phpmyadmin 4 2 4 11

creptor commented 9 years ago

hey you had to change the (place any id) for an existing id like:

SELECT * FROM settings WHERE id = 'debug-status'

sami313 commented 9 years ago

*i am sorry i think i might have gone goofy .. i didnt understand...i had put id = debug-status

creptor commented 9 years ago

Also i don't recoment you update the php version.... the problem is just why it's not working the code. I'll come back in like an ahour because i have to go now, but in the meanwile i'll try to figure out this problem.

sami313 commented 9 years ago

thanks for you great support me to i am also banging my head in the problem :+1:

creptor commented 9 years ago

to use mysqli_erorr you have to put the $dbc inside.... example:

$r = mysqli_query($dbc, $q) or die(mysql_error($dbc));

creptor commented 9 years ago

I guess to help you in this case i'll need the files. Could you please add them (the site) to like dropbox or something and share it with me.. my email is creptor@live.com

sami313 commented 9 years ago

i had made the table again with name set but same problem i almost pulled my half hairs of my head lol yah thats really supportive of you i am just gone send you the code

creptor commented 9 years ago

I got it, when I arrive home i'll look it for any errors

creptor commented 9 years ago

hey I just noticed that in the files you gave me the function has this in is query: $q = "SELECT * FROM set WHERE id = '$id'" and not this: $q = "SELECT * FROM settings WHERE id = '$id'" ... look it up please

sami313 commented 9 years ago

i did that intentionly because i drop the settings table and make it as set so i thought it might work

sami313 commented 9 years ago

hello any body there

creptor commented 9 years ago

I was on school, I just came back :cry:

creptor commented 9 years ago

I'll try to recreate your error to see what's not working....

creptor commented 9 years ago

hey this works perfectly, the code is not the problem... it should work, I have try to recreated but it just don't send errors(the same code, can't get your error :cry:)

code:

function data_setting_value($dbc, $id){

    $q = "SELECT * FROM settings WHERE id = '$id'";
    $r = mysqli_query($dbc, $q);

    $data = mysqli_fetch_assoc($r);

    return $data['value'];

} 

check your $debug, it should be like this:

$debug = data_setting_value($dbc, 'debug_status');
sami313 commented 9 years ago

i feel there is something wrong with my database i wonder what have gone wrong so far in code i dont even my self find any error and you have a look as well

JasonMate commented 9 years ago

In the screenshot you provided, It looks like there is a extra space included on the name of your settings table. Take a look: ' settings'

sami313 commented 9 years ago

i even drop the table settings and made a new one with name set but my error is still the same :(

JasonMate commented 9 years ago

What does your setup.php look like? Do you have a line that looks something like this?

$debug = data_setting_value($dbc, 'debug-status');
JasonMate commented 9 years ago

I dont see anything wrong with that file, but I would remove that comment off github because it's showing your database information.

On Thu, Mar 26, 2015 at 10:01 AM, sami313 notifications@github.com wrote:

[image: untitled] https://cloud.githubusercontent.com/assets/11160392/6850471/3879f64c-d3fb-11e4-9573-85165d3d7877.png

— Reply to this email directly or view it on GitHub https://github.com/thedigicraft/Atom.CMS/issues/112#issuecomment-86591045 .

sami313 commented 9 years ago

yah i will remove it as well point was that to figure the problem

sami313 commented 9 years ago

can any of you guy can look remotely into my problem ?

creptor commented 9 years ago

to look remotelly you have to be connected when whe're but be carefull I'll not harm in any way your computer but do not give your ip to any stranger(facebook, youtube, etc)

PD: Don't post your ip!

creptor commented 9 years ago

@JasonMate you're right.... It seems the table that you have created has spaces inside of the name! that's why is not working, nice catch.

sami313 commented 9 years ago

that settting table i have drop that long ago i made that with set name i thought that if i had some problem there i might get rid of it and make new table with set name @creptor can you please tell me which software you use to connect so i can install it ..i heard about teamviewer if you have any other option please tell me

creptor commented 9 years ago

i use the web software preinstalled with xampp or wamp wich is php my admin :3 - and sql,but it's basically the same thing.

sami313 commented 9 years ago
sami313 commented 9 years ago

*its my bed time ..please leave any link regarding remote connection or i guess can even use windows remote connection

creptor commented 9 years ago

to continue this with remote connection email me at creptor@live.com (time: UTC−03:00) with your ip, and i'll contact you if you have any errors...by mail, so keep your router UP(ON), and your computer and server running.