Page 1 of 1

Form submission help and other question

Posted: Thu Feb 13, 2014 7:37 pm
by fredrock
Hello, i'm working on a "cms" for my website and its supposed to be individual dashboards. Its 3 ranks, admin, partner and trainee. This is for my youtube network and i'm trying to create a form so they can submit videos from there dashboards and then it sends it to my admin panel so I can check it out. I want to have a table display and I want just there submissions they've done displayed and I want it to display like all the fields they have entered and like a status section where i'll like be able to change the status through the admin dashboard. I have no idea how to do the table and have them see just there submissions and me be able to edit it through the admin panel. If any help on that, that would be great. Now i've been working on the form and getting it to submit, but for some reason it won't submit. If any of you can help me out with this it would be great. I'm pretty sure its the query, but not quiet positive. I'm new to php so any help is appreciated.



php:


Code: Select all

 <?php
    if(isset($_POST['submit']))
    {
      $c_name = $_POST['channel_username'];
      $v_link = $_POST['video_link'];
      $v_title = $_POST['video_title'];
      $v_desc = $_POST['vido_description'];
      $v_tags = $_POST['video_tags'];
      $m_sources = $_POST['music_sources'];
      $s_requests = $_POST['special_requests'];
    
      if(empty($c_name) or empty($v_link) or empty($v_title) or empty($v_title) or empty($v_desc) or empty($v_tags))
      {
        echo 'You must fill in the first 5 fields.';
      }
      else
      {
        $getRank = $db->query("SELECT * FROM users WHERE username = '".$_SESSION['username']."'");
        while ($row = $getRank->fetch_assoc())
        {
          $usename = $row['username'];
          $rank = $row['rank'];
        }
       $db->query("INSERT INTO submitted_forms (username, rank, channel_username, video_link, video_title, video_description, video_tags, music_sources, special_requests) VALUES ('$username', '$rank', '$c_name', '$v_link', '$v_title', '$v_desc', '$v_tags', '$m_sources', '$s_requests')");
        echo 'Form submitted successfully.';
        }
      }
    ?>

Html:

Code: Select all

 <form method="POST">
      <p>Channel name <input type="text" name="channel_name" required>*</p>
      <p>Video Link   <input type="text" name="video_link" required>*</p>
      <p>Video Title  <input type="text" name="video_title" required>*</p>
      <p>Video Description <input type="text" name="video_description" required>*</p>
      <p>Video Tags   <input type="text" name="video_tags" required>*</p>
      <p>Music Sources <input type="text" name="music_sources"></p>
      <p>Special Requests <input type="text" name="special_requests"></p>
      <br></br>
      <p><input type="submit" name="submit" value="Submit"></p>
    </form>=

Re: Form submission help and other question

Posted: Fri Feb 14, 2014 6:27 am
by Celauran
fredrock wrote:Now i've been working on the form and getting it to submit, but for some reason it won't submit.
That doesn't really give us much to go on. What errors are you encountering?

Re: Form submission help and other question

Posted: Fri Feb 14, 2014 8:05 am
by fredrock
Like no errors pop up, its just that it just refreshes when I hit submit, nothing else and it doesn't populate in the database,, so i'm guessing its in the query

Re: Form submission help and other question

Posted: Fri Feb 14, 2014 8:18 am
by Celauran
Have you checked for errors? Looks like you're using mysqli, so try $db->error_list. Also make sure you have error reporting turned on, at least for development.

Re: Form submission help and other question

Posted: Fri Feb 14, 2014 9:59 am
by fredrock
Celauran wrote:Have you checked for errors? Looks like you're using mysqli, so try $db->error_list. Also make sure you have error reporting turned on, at least for development.
Its probably the query, I guarantee it, but I have no idea whats wrong with it. And yes I have error reporting on.

Re: Form submission help and other question

Posted: Sun Feb 16, 2014 11:35 am
by social_experiment
you can find more information about error reporting for mysqli below
mysqli.error

the logic in the snippet below isn't very helpful to you because you success message will display, whether your query is successful or not.

Code: Select all

<?php
$db->query("INSERT INTO submitted_forms (username, rank, channel_username, video_link, video_title, video_description, video_tags, music_sources, special_requests) VALUES ('$username', '$rank', '$c_name', '$v_link', '$v_title', '$v_desc', '$v_tags', '$m_sources', '$s_requests')");
        echo 'Form submitted successfully.';
?>
Take a look at the examples for ideas on how to handle any failure in your queries;
mysqli.query

the example below (from the page above) shows how to check whether the query returns true, i.e was successful and based on that returns a success message.

Code: Select all

<?php
if (mysqli_query($link, "CREATE TEMPORARY TABLE myCity LIKE City") === TRUE) {
    printf("Table myCity successfully created.\n");
}
?>