thedigicraft / Atom.CMS

Atom.CMS
56 stars 52 forks source link

Part 56: Admin - Switch statement #172

Closed dbashby closed 8 years ago

dbashby commented 8 years ago

Everything that is meant to be working does right up until video 56 and the switch statement.

I have gone through the video several times and bar the if statement the code is the same

if (isset($_POST['id']) && $_POST['id'] != '') {

I have even tried to use Alans switch statement trying both his exact code but also with the edited if as above.

The Update and Insert queries have been a major headache but now I have no idea as to why right up until the switch everything is functioning.

By the end of part 56 I am unable to edit pages despite not doing anything with the pages since copying and pasting the if/update and insert into the switch.

And even if I cut the user case out and try to run pages.php I have lost the ability to edit pages and add new ones.

Once I paste

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

Into both pages and users editing the users

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

The form on pages.php does not load the data into the relevant fields anymore but prior to this switch they did.

The links below show the code up until the end of Part 57

The full form code is http://pastebin.com/a7e16Bxz The full switch statement code is http://pastebin.com/JJg9rM2N The setup file code is http://pastebin.com/Pdx6d89c

From starting the switch I have lost the ability to show the active state, edit or create a page and display the data for selected option from the menu.

On the user.php page I have all the users displayed but again I have lost the active state and again I am not retrieving the selected users data.

I have no idea why this is happening as the switch should not be causing this issue

dbashby commented 8 years ago

If I take the if statement that we cut from the setup.php file

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

and paste it back in setup.php I get the active state back but the form is still empty but all users are still listed

However I do now have the user.php form fields populating, unfortunately it will not let me edit a users details but the active state is still working.

creptor commented 8 years ago

The code from line 25-33 (The $_GET['page']) must be before calling the switch statement (or more precisely queries.php), or else the switch would have a null value, returning error or nothing.

dbashby commented 8 years ago

So if I am understanding you the code in setup.php

`if(isset($_GET['page'])){

    $page = $_GET['page']; // Set $pageid to equal the value in the URL

} else {

    $page = 'dashboard'; // Set $pageid = to 1 or the home page

}`

What I do not understand is in the vid it was left in setup so are you saying that I need to put the above into queries.php prior to the switch case?

creptor commented 8 years ago

I mean something like this.

File: setup.php Code:

if(isset($_GET['page'])){
     ...
}
include(queries.php);
creptor commented 8 years ago

That has to be the order, no Mather where you put it in setup.php

dbashby commented 8 years ago

Thanks again Creptor, I finally got past 57, I don't know why I put the queries.php there in the setup file. These update queries are still causing issues but at least I have the form loading now as of the test in Part 58 @ 3:00 but I shall look at that tomorrow.

Thanks again Creptor