thedigicraft / Atom.CMS

Atom.CMS
56 stars 52 forks source link

Update Data or Insert Data into Database #148

Closed ghost closed 8 years ago

ghost commented 8 years ago

First Thank you for your support in other issue @thedigicraft and @creptor.

I test now the Update/Insert script and see that when I run the script with condition if(isset($_POST['id']) != '') the server interpret this as the $_POST['id'] is with a value but not run the else statement so I can't never do the insert, but if I change the if statement to if(isset($_POST['id']) != ' ') it runs in the oposite way the server understand that this is empty and never update and the error message is the following:

error 2

Sorry for bothering you but my code is like a boat with a hole when I fix in a place opens up another hole just like that.

Thank you for your support.

creptor commented 8 years ago

so, just to get the thing right.... where you creating a new user, or updating the data of one?

thedigicraft commented 8 years ago

@ricmach along with what @creptor asked, could you paste the code for the page and the queries

ghost commented 8 years ago

Good afternoon,

I send below the code from queries.php.

<?php

    if(isset($_POST['submitted']) == 1){
    $slug = mysqli_real_escape_string($dbc, $_POST['slug']);
    $title = mysqli_real_escape_string($dbc, $_POST['title']);
    $label = mysqli_real_escape_string($dbc, $_POST['label']);
    $header = mysqli_real_escape_string($dbc, $_POST['header']);
    $body = mysqli_real_escape_string($dbc, $_POST['body']);

        if(isset($_POST['id']) != ''){
                            $q = "UPDATE pages SET user = $_POST[users], slug = '$slug', label = '$label', title = '$title', header = '$header', body = '$body' WHERE id = $_GET[id]";
                                                                                                        $action = 'updated';
                                                                                                        }else{
                            $q = "INSERT INTO pages (user, slug, label, title, header, body) VALUES ($_POST[users], '$slug', '$label', '$title', '$header', '$body')";
                            $action = 'added';
                            }
    $r = mysqli_query($dbc, $q);
    if($r){
    $message = '<p>Page was '.$action.'!</p>';
    }else{
    $message =  '<p>Page could not be '.$action.' because:'.mysqli_error($dbc);
        $message .= '<p>'.$q.'</p>';
        }
        }       

?>

And next is the setup.php.

<?php
    /*Setup File:

    */

    #Database Conection here

    //$dbc = mysqli_connect('localhost', 'dev', 'thepassword1', 'sipre') OR die('Could not connect because:'.mysqli_connect_error());

    error_reporting(0);

    #Functions:

    include ('functions/data.php');
    include ('functions/sandbox.php');

    #Page Settings:

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

    if(isset($_GET['page'])){
                                        $page_id = $_GET['page'];
                        }else{
                            $page_id = 1;
                            }

    #User Data:

    $user = data_user($dbc, $_SESSION['username']);

    #Page Setup:

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

    include ('config/queries.php');

    $page = data_page($dbc, $page_id);

    $site_title = 'Plataforma de E-Commerce';

    $page_title = 'Home';

?>
ghost commented 8 years ago

title, slug and other atributes are for pages table.

creptor commented 8 years ago

try this in that line: if(isset($_POST['id'])&&is_numeric($_POST['id'])){ sry for the other comment, my mistake

creptor commented 8 years ago

A no WAIT You used get, and it's $_POST['id'] in the query :smile:

ghost commented 8 years ago

@creptor if(isset($_POST['id'])&&is_numeric($_POST['id'])){ works perfectly.

Again thank you for your support.

thedigicraft commented 8 years ago

Thank you again @creptor !!