thedigicraft / Atom.CMS

Atom.CMS
56 stars 50 forks source link

Video 35 - Insert form #20

Closed jmlab closed 10 years ago

jmlab commented 10 years ago

Hi Alan, first i must congratulate you!!! This is the best of all tutorials that i've seen in all web! I'm on tut 35 and until now, everything worked perfectly. But i have a problem in the insert query. When submit the form, he said that it was sent, but the form data do not enter the databse table.

It shows this error: "Notice: Undefined index: nome in /Users/joaomirra/localhost/HPAcademy/sitecake/admin/index.php on line 146" "Notice: Undefined index: conteudo in /Users/joaomirra/localhost/HPAcademy/sitecake/admin/index.php on line 146"

Below is the code of my index.php


Menu

A nova formação foi inserida com sucesso!

'; } else { $message = '

A página não foi adicionado. Motivo: '.mysqli_error($dbc); $message .= '

'.$q.'

'; } } ?>

```
  • › Logout
  • Admin Panel

    HP Academy © 2014  |  Todos os Direitos Reservados

    
    
    ---
    
    I'm sure it's a stupid mistake on my part, but I am not able to resolve. 
Thanks for the help.
    
    PS: Please do not be surprised with some of the texts. They are written in Portuguese :)
    jmlab commented 10 years ago

    Some code is missing and i cant edit the post :( Again below:


    A nova formação foi inserida com sucesso!

    '; } else { $message = '

    A página não foi adicionado. Motivo: '.mysqli_error($dbc); $message .= '

    '.$q.'

    '; } } ?>

                  <li><a href="logout.php">&rsaquo;&nbsp;Logout</a></li>
                </ul>
            </div>
      </div>

    Admin Panel

    ```
    jmlab commented 10 years ago

    Solved. It really was a stupid mistake :p Different "Form name fields" Sorry!

    thedigicraft commented 10 years ago

    Hey thanks for the kind words!

    Don't worry! Even us seasoned pros make those same mistakes all the time ;-)

    jmlab commented 10 years ago

    Hello, thanks for the quick response! It is one of those errors that do too often! lolol I'm currently in the tutorial video 40 and despite having seen and reviewed all the code, this error happens:   (/> <br Notice </ b>: Undefined variable: opened in / Users / joaomirra / localhost / HPAcademy / sitecake / admin / index.php </ b> on line 213 </ b> <br / >)

    In its place the text that is in the database should appear. I do not know what's going on: p Thank you

    jmlab commented 10 years ago

    Here is part of the code:

    <?php
    
                            if(isset($_POST['enviado']) == 1) {
    
                                $conteudo = mysqli_real_escape_string($dbc, $_POST['conteudo']);
                                $nome = mysqli_real_escape_string($dbc, $_POST['nome']);
    
                                $q = "INSERT INTO formacoes (user, url, nome, conteudo) VALUES ($_POST[user], '$_POST[url]', '$nome', '$conteudo')";
                                $r = mysqli_query($dbc, $q);
    
                                if($r) {
    
                                    $message = '<p>A nova formação foi inserida com sucesso!</p>';    
    
                                } else {
                                    $message = '<p>A página não foi adicionado. Motivo: '.mysqli_error($dbc);
                                    $message .= '<p>'.$q.'</p>';
                                }
                            }
    
                        ?>
    
                        <?php
    
                            $q = "SELECT * FROM formacoes ORDER BY nome ASC";
                            $r = mysqli_query($dbc, $q);
    
                            while($lista_formacoes = mysqli_fetch_assoc($r)) { ?>
    
                            <a class="" href="index.php?id=<?php echo $lista_formacoes['id']; ?>">
                                <p><?php echo $lista_formacoes['nome']; ?></p>
                            </a>
    
                        <?php } ?>
                        </div>
    
                      <li><a href="logout.php">&rsaquo;&nbsp;Logout</a></li>
                    </ul>
                </div>
          </div>
    
            <section>
                <div id="principalPag01">               
                <div class="principalPag01">
                    <h1> Admin Panel </h1> 
    
                    <div id="painel-erros">
                    <?php if(isset($message)) { echo $message; } ?>
    
                    <?php
    
                        if(isset($_GET['id'])) {
                            $q = "SELECT * FROM formacoes WHERE id = $_GET[id]";
                            $r = mysqli_query($dbc, $q);
    
                            $opened = mysqli_fetch_assoc($r);   
                        }
    
                    ?>
    
                    </div>
    
                    <form class="insert" method="post" action="index.php">
    
                    <label id="titulo_formacao" for="titulo_formacao">Título Formação:</label>
                    <input id="campo_titulo_formacao" name="nome" type="text" value="<?php echo $opened['nome']; ?>">
    
                    <label id="slug_id" for="url">Url:</label>
                    <input id="campo_slug" name="url" value="<?php echo $opened['url']; ?>" type="text">
    
                    <label id="info_formacao" for="info_formacao">Info Formação:</label>
                    <textarea name="conteudo"><?php echo $opened['conteudo']; ?></textarea>
    
                    <label id="user_id" for="user">Usuário:</label>
                    <select class="dropdown" id="user" name="user">
                        <option value="0">Nenhum usuário</option>
    
    thedigicraft commented 10 years ago

    Since we dont have line numbers here I need a bit more info...

    What is on line 213 on index.php? That will help me find the problem better.

    jmlab commented 10 years ago

    Sorry about that!

    1st error:
    Notice: Undefined variable: opened in /Users/joaomirra/localhost/HPAcademy/sitecake/admin/index.php on line 207
    2nd error:
    Notice: Undefined variable: opened in /Users/joaomirra/localhost/HPAcademy/sitecake/admin/index.php on line 210
    3th error:
    Notice: Undefined variable: opened in /Users/joaomirra/localhost/HPAcademy/sitecake/admin/index.php on line 213

    Seems to be an error in $opened

    Here is the code:

    <?php
    
                        if(isset($_GET['id'])) {
                            $q = "SELECT * FROM formacoes WHERE id = $_GET[id]";
                            $r = mysqli_query($dbc, $q);
    
     (197)                  $opened = mysqli_fetch_assoc($r);   
                        }
    
                    ?>
    
                    </div>
    
                    <form class="insert" method="post" action="index.php">
    
                    <label id="titulo_formacao" for="titulo_formacao">Título Formação:</label>
     (207)      <input id="campo_titulo_formacao" name="nome" type="text" value="<?php echo $opened['nome']; ?>">    (has an error here)
    
                    <label id="slug_id" for="url">Url:</label>
     (210)      <input id="campo_slug" name="slug" value="<?php echo $opened['url']; ?>" type="text">    (has an error here)
    
                    <label id="info_formacao" for="info_formacao">Info Formação:</label>
     (213)      <textarea name="conteudo"><?php echo $opened['conteudo']; ?></textarea>   (has an error here)
    
                    <label id="user_id" for="user">Usuário:</label>
                    <select class="dropdown" id="user" name="user">
                        <option value="0">Nenhum usuário</option>
    
                        <?php
                            $q = "SELECT id FROM users ORDER BY primeiro_nome 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 echo $user_data['nome_completo']; ?></option>
    
                            <?php } ?>
    
                    </select>
    
                    <div class="conjunto_btn_individual">
                        <input type="hidden" name="enviado" value="1">
                        <input type="reset" id="limpar" name="limpar" value="Limpar" class="limpar">
                        <input type="submit" id="enviar" name="enviar" value="Enviar" class="enviar">
                    </div>
                    </form>
    

    I hope you understand the code. I do not know how to export with the line numbers

    I would like if possible to ask another question (there will probably be something about this in other videos, but I have not seen them all). How can I make a dropdown menu with 3 levels and with information sent from the database?

    Thank you very much!!!


    João Mirra JMlabdesign Marketing & Branding Key Manager

    www.facebook.com/jmlabdesign

    jmlabdesign@gmail.com Tel.: 210.896.148 Tlm.: 968.937.474

    A 2014/03/18, às 00:28, The Digital Craft escreveu:

    Since we dont have line numbers here I need a bit more info...

    What is on line 213 on index.php? That will help me find the problem better.

    — Reply to this email directly or view it on GitHub.

    jmlab commented 10 years ago

    Hello Alan, any luck finding my error? :p

    Thank you

    thedigicraft commented 10 years ago

    Hey João,

    Sorry for the delay.

    It would seem that $opened is not set so that means that $_GET['id'] is not set either. This is fine though if you do not have something opened at the moment. If that is the case and you just want to hide those pesky notices when a variable/array is not set then run this in your setup.php

    error_reporting(E_ALL ^ E_NOTICE); this will keep error reporting ON for everything except NOTICES

    jmlab commented 10 years ago

    screen01 screen02

    Hello Alan! No, thank you for answering me :)

    Speaking of the problem, in fact my goal is to appear all the data I have in the database. Everything has worked perfectly except the $ opened.

    My code is correct? I have a table called "formacoes" that has 5 rows (id, user, slug, name and content).

    It will be easier if you see my files? Should I send them? Do not want to give too much work. But that would be a great help, because I really don't understand why it doesn't work! :(

    Thanks once again!

    thedigicraft commented 10 years ago

    Is there an id in the URL?

    jmlab commented 10 years ago

    Very fast! :)

    I'll be honest, when the error appeared I was so upset that I didn't click any button! But the question you asked me (about the "id"), made ​​me navigate the menu and really appears the "id" in the URL and all the information from the database.

    Putting the code you sent me, the error notification disappears and everything works normally. :)

    Thank you so much! And I apologize again for my lack of attention. But for me it was an error that prevented the information coming.