Search the Community
Showing results for tags 'crud / cms'.
-
Hello my good people I'm doing a content manager system in PHP and mySQLi, following a serie of video tutorials. But in my project I am using a tree menu. In the front office all works smoothly (the tree menu displays all results - menu and submenus - and each button carries the information of the respective page). The problem is in the back office. The menu is there, in the url appears its id page but the CRUD, I can not put it to work. ======= CODE START ======= <!-- Gestor de Conteúdos Start --> <div class="container-fluid"> <!-- Conteúdo Fluido Start --> <div class="row-fluid row-offcanvas row-offcanvas-left"> <?php // INSERT QUERY if(isset($_POST['enviado']) == 1) { $header = mysqli_real_escape_string($dbc, $_POST['header']); $url = mysqli_real_escape_string($dbc, $_POST['url']); $user = $_POST['user']; $idPai = $_POST['idPai']; $menuNomePT = mysqli_real_escape_string($dbc, $_POST['menuNomePT']); $conteudo_pagina_PT = mysqli_real_escape_string($dbc, $_POST['conteudo_pagina_PT']); $menuNomeEN = mysqli_real_escape_string($dbc, $_POST['menuNomeEN']); $conteudo_pagina_EN = mysqli_real_escape_string($dbc, $_POST['conteudo_pagina_EN']); $q = "INSERT INTO menuCAL (header, url, user, idPai, menuNomePT, conteudo_pagina_PT, menuNomeEN, conteudo_pagina_EN) VALUES ('$header', '$_POST[url]', $_POST[user], '$_POST[idPai], '$menuNomePT, '$conteudo_pagina_PT', '$menuNomeEN', '$conteudo_pagina_EN'"; $r = mysqli_query($dbc, $q); ?> <div> <?php if($r) { $message = '<p>A página foi adicionada!</p>'; } else { $message = '<p>A página não foi adicionada, devido ao seguinte erro: '.mysqli_error($dbc); $message .= '<p>' .$q.'</p>'; } ?> </div> <?php } ?> <!-- Menu CAL Start --> <div class="col-sm-3 sidebar-offcanvas"> <?php //call the recursive function to print category listing category_tree(0); //Recursive php function function category_tree($menuPai){ global $dbc; $q = "SELECT * FROM menuCAL WHERE idPai ='".$menuPai."'"; $r = mysqli_query($dbc, $q); while($btnMenu = mysqli_fetch_assoc($r)): $i = 0; if ($i == 0) echo '<ul class="menuCAL">'; echo '<li><a href="?page='.$btnMenu['id'],'">' . $btnMenu['GlyPrincipal'] . $btnMenu['GlySecundario'] . $btnMenu['menuNomePT'], '</a>'; category_tree($btnMenu['id']); echo '</li>'; $i++; if ($i > 0) echo '</ul>'; endwhile; } ?> </div> <!-- Menu CAL End --> <!-- Conteúdo Start --> <div class="span10"> <div class="col-sm-12"> <!-- Título Start --> <h1 class="page-header"> <i class="fa fa-file"></i> Adicionar Página </h1> <ol class="breadcrumb"> <li> <a href="#"><i class="fa fa-pencil"></i> Conteúdos</a> </li> <li class="active"> <i class="fa fa-file"></i> Nova página </li> </ol> <!-- Título End --> </div> <!-- Textos & Formulários Start --> <div class="row"> <div class="col-lg-12"> <p><?php if(isset($message)) { echo $message; } ?></p> <?php // SELECT QUERY if(isset($_GET['id'])) { $q = "SELECT * FROM menuCAL WHERE id = $_GET[id]"; $r = mysqli_query($dbc, $q); $opened = mysqli_fetch_assoc($r); } ?> <!-- Formulário Start --> <form action="adicionar_pagina.php" method="post" role="form"> <!-- Campo header Start --> <div class="form-group"> <label for="header">Header:</label> <input type="text" class="form-control" name="header" id="header" value="<?php echo $opened['header']; ?>" placeholder="Texto descritivo a colocar no topo do website"> </div> <!-- Campo header End --> <!-- Campo Label Start --> <div class="form-group"> <label for="url">URL:</label> <input type="text" class="form-control" name="url" id="url" value="<?php echo $opened['url']; ?>" placeholder="Texto a colocar na URL (SEO)"> </div> <!-- Campo Label End --> <!-- Campo User Start --> <div class="form-group"> <label for="user">Administrador:</label> <select class="form-control" name="user" id="user"> <option value="0">›› Nenhum administrador</option> <?php $q = "SELECT id FROM users ORDER BY first ASC"; $r = mysqli_query ($dbc, $q); while ($user_list = mysqli_fetch_assoc($r)) { $user_data = data_user($dbc, $user_list['id']); ?> <option value="<?php echo $user_data['id'] ?>" <?php if($user_data['id'] == $opened['id']) { echo 'selected';} ?>><?php echo $user_data['fullname']; ?></option> <?php } ?> </select> </div> <!-- Campo User Start --> <!-- Campo ID Menu Pai Start --> <div class="form-group"> <label for="idPai">Adicionar a:</label> <select class="form-control" name="idPai" id="idPai"> <option value="0">›› Seleccione onde adicionar a nova página:</option> <?php $q = "SELECT menuNomePT FROM menuCAL WHERE idPai = 0"; $r = mysqli_query ($dbc, $q); while ($submenus = mysqli_fetch_assoc($r)) { ?> <option value="<?php echo $submenus['idPai']; ?>"><?php echo $submenus['menuNomePT']; ?></option> <?php } ?> </select> </div> <!-- Campo ID Menu Pai Start --> <!-- Campo menuNomePT Start --> <div class="form-group"> <label for="menuNomePT">Título PT:</label> <input type="text" class="form-control" name="menuNomePT" id="menuNomePT" value="<?php echo $opened['menuNomePT']; ?>" placeholder="Insira o título em Português"> </div> <!-- Campo menuNomePT End --> <!-- Campo conteudo_pagina_PT Start --> <div class="form-group"> <label for="conteudo_pagina_EN">Conteúdos PT:</label> <textarea class="form-control" name="conteudo_pagina_PT" rows="12" id="conteudo_pagina_PT" placeholder="Insira os textos em Português"><?php echo $opened['conteudo_pagina_PT']; ?></textarea> </div> <!-- Campo conteudo_pagina_PT End --> <!-- Campo menuNomeEN Start --> <div class="form-group"> <label for="menuNomeEN">Título EN:</label> <input type="text" class="form-control" name="menuNomeEN" id="menuNomeEN" value="<?php echo $opened['menuNomePT']; ?>" placeholder="Insira o título em Inglês"> </div> <!-- Campo menuNomeEN End --> <!-- Campo conteudo_pagina_EN Start --> <div class="form-group"> <label for="conteudo_pagina_EN">Conteúdos EN:</label> <textarea class="form-control" name="conteudo_pagina_EN" rows="12" id="conteudo_pagina_EN" placeholder="Insira os textos em Inglês"><?php echo $opened['conteudo_pagina_PT']; ?></textarea> </div> <!-- Campo conteudo_pagina_EN End --> <button type="submit" class="btn btn-default adic_concluir">Gravar</button> <input type="hidden" name="enviado" value="1"> </div> </form> <!-- Formulário End --> </div> <!-- Debug Panel Start --> <?php if($debug == 1) { include('widgets/debug.php'); } ?> <!-- Debug Panel End --> </div> <!-- Textos & Formulários End --> </div> <!-- Conteúdo End --> </div> <!-- Conteúdo Fluido Start --> </div> <!-- Gestor de Conteúdos End --> ======= CODE END ======= I can not do the INSERT or UPDATE query, using the form so that the "user" and the "idPai" (a category id), can be created or changed in the database. I tried to echo the database result, but nothing append And in the second query (in red in the code), gives me an error (Undefined variable: opened in …). Obviously something is wrong, but i can't see what! :/ The database: Can Someone help me? Please !! Thank U
- 16 replies