Form submission help and other question

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:

<?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:

<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>

Check for possible spelling errors.

$v_desc = $_POST[‘vido_description’];

Can I assume you have session_start(); at the top of your page???

I made a slightly different copy you might try or compare to what you have.

&lt;?php
session_start();

$host = "localhost";
//Database user name.	
$login = "";
//Database Password.
$dbpass = "";
//Database name.
$dbname = "";
$PDO = new PDO("mysql:host=localhost;dbname=$dbname", "$login", "$dbpass");

$message = "";

if(isset($_POST['submit']))
{
	$c_name = trim($_POST['channel_name']);
	$v_link = trim($_POST['video_link']);
	$v_title = trim($_POST['video_title']);
	$v_desc = trim($_POST['video_description']);
	$v_tags = trim($_POST['video_tags']);
	$m_sources = trim($_POST['music_sources']);
	$s_requests = trim($_POST['special_requests']);
	
	$username = $_SESSION['username'];
	
	if(empty($c_name) || empty($v_link) || empty($v_title) || empty($v_title) || empty($v_desc) || empty($v_tags))
	{
		$message = 'You must fill in the first 5 fields.';
	}
	else
	{	
		
		try{
			$getRank = $PDO-&gt;prepare("SELECT rank FROM users WHERE username = :username");
			$getRank-&gt;bindParam(":username", $username);
			$getRank-&gt;execute();
			while($row = $getRank-&gt;fetch(PDO::FETCH_ASSOC)){
				$rank = $row['rank'];
			}

		}catch (PDOException $e){
		    echo "Database error: ".$e-&gt;getMessage();
		}
		
		try{
			$query = $PDO-&gt;prepare("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)");
			$query-&gt;bindParam(":username", $username);
			$query-&gt;bindParam(":rank", $rank);
			$query-&gt;bindParam(":c_name", $c_name);
			$query-&gt;bindParam(":v_link", $v_link);
			$query-&gt;bindParam(":v_title", $v_title);
			$query-&gt;bindParam(":v_desc", $v_desc);
			$query-&gt;bindParam(":v_tags", $v_tags);
			$query-&gt;bindParam(":m_sources", $m_sources);
			$query-&gt;bindParam(":s_requests", $s_requests);
			$query-&gt;execute();

		}catch (PDOException $e){
		    echo "Database error: ".$e-&gt;getMessage();
		}
		$message = 'Form submitted successfully.';
	}
}
?&gt;
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
&lt;title&gt;&lt;/title&gt;
&lt;style type="text/css"&gt;
.label {
float:left;
clear:left;
display:inline;
width:115px;
}
.input {
float:left;
display:inline;
width:165px;
}
.input input{
margin-right:3px;
}
.submit {
float:left;
clear:left;
margin-top:10px;
width:280px;
text-align:center;
}
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
	&lt;?php if(isset($message) && !empty($message)){ echo $message; } ?&gt;
	&lt;form action="" method="post"&gt;
		&lt;div class="label"&gt;Channel name&lt;/div&gt;&lt;div class="input"&gt;&lt;input type="text" name="channel_name" required&gt;*&lt;/div&gt;
		&lt;div class="label"&gt;Video Link&lt;/div&gt;&lt;div class="input"&gt;&lt;input type="text" name="video_link" required&gt;*&lt;/div&gt;
		&lt;div class="label"&gt;Video Title&lt;/div&gt;&lt;div class="input"&gt;&lt;input type="text" name="video_title" required&gt;*&lt;/div&gt;
		&lt;div class="label"&gt;Video Description&lt;/div&gt;&lt;div class="input"&gt;&lt;input type="text" name="video_description" required&gt;*&lt;/div&gt;
		&lt;div class="label"&gt;Video Tags&lt;/div&gt;&lt;div class="input"&gt;&lt;input type="text" name="video_tags" required&gt;*&lt;/div&gt;
		&lt;div class="label"&gt;Music Sources&lt;/div&gt;&lt;div class="input"&gt;&lt;input type="text" name="music_sources" &gt;&lt;/div&gt;
		&lt;div class="label"&gt;Special Requests&lt;/div&gt;&lt;div class="input"&gt;&lt;input type="text" name="special_requests"&gt;&lt;/div&gt;
		&lt;div class="submit"&gt;&lt;input type="submit" name="submit" value="Submit"&gt;&lt;/div&gt;
	&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;

You need add to submitted_forms new row like show_now - enum(‘yes’, ‘no’)

Now in the index.php or page where all guests can see the publication, add to WHERE in select query the new row like show_now = ‘yes’

create new or edit page, where you will do the check (Edit Page), out all information for check with while… and add to select WHERE show_now = ‘no’

add simple html with 2 input type=“radio” to change the value.

sorry for my english

Please explain more. Are you talking about the table thing? I don’t want to display it to guests as you have to login to see the dashboard anyway. I want to show them in there own dashboard only there submissions in a table. I don’t want anyone else to see there submissions except the person and admins is all.

Thanks, i’m going to try yours out and see, i’ll update this post if it works.

This did not work.

Hmm. I just tested my copy and it did work.

Do you have $_SESSION[‘username’] defined before using this page?
Do all DB table fields match what is on the page?
Are you using the full page copy I made, or just part of it?

Sorry, I forgot to tell you why it doesn’t work. Its because its using PDO, my server doesn’t have PDO, I use mysqli

Well if you can post your current copy maybe someone can spot an error. I know there was a spelling issue before… maybe something else.

I did post my current copy. Its in my original post above.

That’s why I asked…

Did you fix the spelling issue mentioned a few times?

How about the condition check line?

if(empty($c_name) || empty($v_link) || empty($v_title) || empty($v_title) || empty($v_desc) || empty($v_tags))

There might be other issues which is why I wanted to see the latest copy you are testing.

And you really are only posting parts in your OP of the page so it’s unknown if you have session_start(); on the page or other factors that could cause the failure of the script.

Trust me the rest are’t causing the issue, I know its the query no doubt. I do have session start.

…And if you were to echo this line where the INSERT query is, all values are present and not empty, correct?


echo "$username, $rank, $c_name, $v_link, $v_title, $v_desc, $v_tags, $m_sources, $s_requests"; 

If they are, you probably need to bind or escape your values.

Ok, i’m getting this error Fatal error: Call to a member function query() on a non-object. And this is the line its on. The one above is the line its on, but i’m just posting the line under it just to see what you think. I completely forgot about this error. I’ve had it for awhile, its when I submit it.

$getRank = $db->query("SELECT * FROM users WHERE username = '".$_SESSION['username']."'");
        while ($row = $getRank->fetch_assoc());

As I mentioned, if you post the whole code, we could spot errors.
Where is $db defined?

This version fixes a number of
spelling issues ($_POST[‘vido_description’], $usename or $username)
and your condition line (removing duplicate $v_title and replacing “or” with ||)
and escapes data before insert.

Like I said, you say you’re using the code in OP but I’ve asked if you’ve fixed issues that have been pointed out to you.

&lt;?php
	if(isset($_POST['submit']))
	{
		$c_name = $_POST['channel_username'];
		$v_link = $_POST['video_link'];
		$v_title = $_POST['video_title'];
		$v_desc = $_POST['video_description'];
		$v_tags = $_POST['video_tags'];
		$m_sources = $_POST['music_sources'];
		$s_requests = $_POST['special_requests'];
		$username = $_SESSION['username'];
		
		if(empty($c_name) || empty($v_link) || empty($v_title) || empty($v_desc) || empty($v_tags))
		{
			echo 'You must fill in the first 5 fields.';
		}
		else
		{	
			$username = mysqli_real_escape_string ($db, $username);
			$getRank = $db-&gt;query("SELECT rank FROM users WHERE username = '$username'");
			while ($row = $getRank-&gt;fetch_assoc())
			{
				$rank = $row['rank'];
			}
			
			$rank = mysqli_real_escape_string ($db, $rank);
			$c_name = mysqli_real_escape_string ($db, $c_name);
			$v_link = mysqli_real_escape_string ($db, $v_link);
			$v_title = mysqli_real_escape_string ($db, $v_title);
			$v_desc = mysqli_real_escape_string ($db, $v_desc);
			$v_tags = mysqli_real_escape_string ($db, $v_tags);
			$m_sources = mysqli_real_escape_string ($db, $m_sources);
			$s_requests = mysqli_real_escape_string ($db, $s_requests);
			
			$db-&gt;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.';
		}
	}
?&gt;

I did fix the issues and $db is defined in my config, which i’m including at the top. The error here is that fatal error which needs fixed. I never saw it before. I guess when it refreshed it was there so i think thats been the error all along. It was hidden because the page is black so I never saw it. Guess its not the query.

I did fix the issues and $db is defined in my config, which i’m including at the top. The error here is that fatal error which needs fixed. I never saw it before. I guess when it refreshed it was there so i think thats been the error all along. It was hidden because the page is black so I never saw it. Guess its not the query.
Yet once again you haven’t posted your latest code. Guess we can’t help you.

Ok one second, geez.

PHP:

<?php session_start();

if(isset($_SESSION['rank']) and $_SESSION['rank'] == "partner")
  {
  $_SESSION['username'];

  } else {
  header("location: ../index.php");
  }

        include "menu.php";
        include "header.php";
        ?>
  

<?php
        if(isset($_POST['submit']))
    {
      $c_name = $_POST['channel_username'];
      $v_link = $_POST['video_link'];
      $v_title = $_POST['video_title'];
      $v_desc = $_POST['video_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:

<?php if(isset($message) && !empty($message)){ echo $message; } ?> 
    <form action="" method="POST"> 
        <label Channel Name></label><div class="input"><input type="text" name="channel_username" required>*</div> 
        <div class="label">Video Link</div><div class="input"><input type="text" name="video_link" required>*</div> 
        <div class="label">Video Title</div><div class="input"><input type="text" name="video_title" required>*</div> 
        <div class="label">Video Description</div><div class="input"><input type="text" name="video_description" required>*</div> 
        <div class="label">Video Tags</div><div class="input"><input type="text" name="video_tags" required>*</div> 
        <div class="label">Music Sources</div><div class="input"><input type="text" name="music_sources" ></div> 
        <div class="label">Special Requests</div><div class="input"><input type="text" name="special_requests"></div> 
        <div class="submit"><input type="submit" name="submit" value="Submit"></div> 
    </form>

Notice anything wrong here?

 $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')");

No?