thedigicraft / Atom.CMS

Atom.CMS
56 stars 50 forks source link

Cant for the life of me get pages and users to add/update #50

Closed iboutsikas closed 10 years ago

iboutsikas commented 10 years ago

I got the pages working after hours of trying and trying again, then once i got to moving stuff to header and footer.php and creating the views it broke and can't get it working again. From what i saw in the debug window $opened is empty the whole time, no matter what i try. I obviously messed something up while copying and moving, but after so many hours of trying to find out what i'm all warn out.

Here is the whole of my code for anyone interested to help:https://mega.co.nz/#!7ZFjjL6Q!6oqkFofybRsOszOmDiLtgkA5E8Mt_-Uv3FeJLC3Cpc4

I failed getting it up to github :( . Thanks to anyone willing to help out!

iboutsikas commented 10 years ago

Ok, after some more digging (and some rest) i am almost sure it's $opened not getting any id with_GET['id'] under queries.php ( i could always be wrong though, not a web design expert). Here is my querries.php :

<?php
    switch ($page) {
        case 'dashboard':

        break;
        case 'pages':

                if(isset($_POST['submitted']) == 1) {

                    $title = mysqli_real_escape_string($dbc, $_POST['title']);
                    $header = mysqli_real_escape_string($dbc, $_POST['header']);
                    $body = mysqli_real_escape_string($dbc, $_POST['body']);

                    if(isset($_POST['id']) != '') {
                        $action = 'updated';
                        $query = "UPDATE pages SET user_id = $_POST[user_id], slug = '$_POST[slug]', title = '$title', header = '$header', body = '$body' WHERE id = $_GET[id]";
                    } else {
                        $action = 'added';                          
                        $query = "INSERT INTO pages (user, slug, title, header, body) VALUES ($_POST[user], '$_POST[slug]', '$title', '$header', '$body')";
                    }

                    $r = mysqli_query($dbc, $query);

                    if($r){

                        $message = '<p>Page was '.$action.'!</p>';

                    } else {

                        $message = '<p>Page could not be '.$action.' because: '.mysqli_error($dbc);
                        $message .= '<p>Query: '.$q.'</p>';

                    }

                }

                if(isset($_GET['id'])) { $opened = pullPageData($dbc, $_GET['id']); }

            break;      
            case 'users':
                if(isset($_POST['submitted']) == 1) {
                    //Escape all the text to avoid headache
                    $first_name = mysqli_real_escape_string($dbc, $_POST['first_name']);   
                    $last_name = mysqli_real_escape_string($dbc, $_POST['last_name']);
                    if($_POST['password'] != ''){

                        if($_POST['password'] == $_POST['passwordv']) {
                            $password = " password = SHA1('$_POST[password]'),";
                            $verify = true;
                        } else {
                            $verify = false;
                        }                                               
                    }else {
                        $verify = false;
                    }
                    if(isset($_POST['id']) && $_POST['id'] !=""){
                        $action = 'updated';
                        $query = "UPDATE users SET first_name = '$first_name', last_name = '$last_name', email = '$_POST[email]', $password status = '$_POST[status] WHERE id = $_GET[id]";                         
                    } else {
                        $action = 'added';      
                        $query = "INSERT INTO users (first_name, last_name, email, password, status) VALUES ('$first_name', '$last_name', '$_POST[email]', SHA1('$_POST[password]', '$_POST[status]'))";

                        if($verify == true){
                            $result = mysqli_query($dbc, $query);
                        }
                    }           
                    //Success or failure
                    if($result) {
                        $message = '<p class="bg-success">User was '.$action.' !</p>';
                    } else {
                        $message = '<p class="bg-danger"> User could not be '.$action.' because: '.mysqli_error($dbc);
                        if(verify == false){
                                $message .='<p class="bg-danger">Password fields empty and/or do not match.</p>';                       
                        }
                        $message .='<p class="bg-warning">Query: '.$query.'</p>';
                    }
                }   
                if(isset($_GET['id'])) { $opened = pullUserData($dbc, $_GET['id']); }

        break;
        case 'settings':

        break;
        case 'producers':

        break;
        case 'consortiums':

        break;
        case 'fields':

        break;

        default:

            break;
    }

?>

As a sidenote, how can i add the whole code in a box, instead of the autothing it does? Thanks anyone who is willing to help!

thedigicraft commented 10 years ago

Hello,

I am curious. Are you seeing a value in the url? or is it blank?

?id=

or

?id=3

you might also add another clause to the if() statement...


if(isset($_GET['id']) && $_GET['id'] != '') {
...
}

I don't really know if that is the issue but it is good to have there in case it is sending an empty string .

iboutsikas commented 10 years ago

Yes i am getting the id in the url now, but i didn't before. Some more info, when clicking on an entry on the left panel, it doesn't load into the form so i can edit it. And after i try to add a user/page i get an ?id= at the end.

iboutsikas commented 10 years ago

Apparently if i remove the whole switch construct, and leave only the pages part for example, under queries.php pages work fine, adding, editting, everything. So where can i possible have messed up with the $page variable causing the switch to never work? Cuz if i put the pages queries under default, pages work fine.

EDIT: Fixed by just re-assigning the $page variable before the switch construct. Works like a charm