1

I am trying to get a video play to play from a database. I have a form with the following code:

<form action="abs3xvideos.php" method="POST" enctype="multipart/form-data">

<input type="file" name="id" />
<input type="submit" name="submit" value="UPLOAD!" />

<form action="abs3xvideos.php">
  Search ABS3X:
  <input type="search" name="googlesearch">
  <input type="submit">
</form>

I then have another page the form is linked to with the following code:

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

define('DB_Name', 'gaufensr_abs3x');
define('DB_User', 'gaufensr_owner');
define('DB_Password', 'password');
define('DB_Host', 'localhost');

$link = mysql_connect(DB_Host, DB_User, DB_Password);

if (!$link) {
      die('could not connect:' . mysql_error());
}

$db_selected = mysql_select_db(DB_Name, $link);

if (!@db_selected) {
    die('can\t use' . DB_Name. ': ' . mysql_error());
}

echo 'CONNECTED SUCCESSFULLY';
$id = $_POST['id'];
$value = $_POST['id'];

$sql = "INSERT INTO videos (video_name) VALUES ('$value')";

if (!mysql_query($sql)) {
     die(`ERROR: ` .mysql_error());
}

if (isset($_POST['id'])){
      $id = $_POST['id'];
      $query = mysql_query("SELECT * FROM `videos` WHERE id='$id'");
       while($row = mysql_fetch_assoc($query))
       {
             $id = $row['id'];
         $video_name = $row['video_name'];      
       }

    echo "You are watching " .$id. "<br />";
    echo "<embed src=`$id` width='560' height='315'></embed>";
}
else
{
   echo "Error!";
}  
mysql_close();
?>

I get the following error message when I try to upload a video using the form page that I created:

CONNECTED SUCCESSFULLY
Notice: Undefined index: id in /home1/gaufensr/public_html/abs3xvideos.php on line 39

Notice: Undefined index: id in /home1/gaufensr/public_html/abs3xvideos.php on line 40 Error!

I am at a loss. I spoke with someone on stackflow earlier and they suggested that something might be wrong with my while loop but I am not to sure what the mistake could be. Should I separate the PHP code into different pages maybe?

4
  • 3
    Did you just post your password...? Commented Apr 14, 2015 at 17:45
  • Why do you have two <form> tags? One of them isn't closed either. Commented Apr 14, 2015 at 17:48
  • And does the upload not work? These errors SHOULD show, when you navigate to the page, without submitting the form, because $_POST is not yet set. Do the errors also show after submitting a file? Commented Apr 14, 2015 at 18:03
  • Btw, I just realized ... "upload"? There's no code to handle uploading a file. Commented Apr 14, 2015 at 18:07

2 Answers 2

1

Did you urlencode the name?

$video_name = urlencode($row['video_name']); 

Or rawurldecode may work better.

$video_name = rawurldecode($row['video_name']); 
Sign up to request clarification or add additional context in comments.

Comments

0

you forget to close form

Use

<form action="abs3xvideos.php" method="post" enctype="multipart/form-data">
<input type="file" name="id" />
<input type="submit" name="submit" value="UPLOAD!" />
</form>//from close here

<form action="abs3xvideos.php">
  Search ABS3X:
  <input type="search" name="googlesearch">
  <input type="submit">
</form>

2 Comments

"POST" will work the same as "post". "POST" will generate and HTML error with an XHTML DocType, but will still work.
I don't think it matters

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.