Reputation: 31
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?
Upvotes: 1
Views: 624
Reputation: 22532
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>
Upvotes: 0
Reputation: 5665
Did you urlencode the name?
$video_name = urlencode($row['video_name']);
Or rawurldecode may work better.
$video_name = rawurldecode($row['video_name']);
Upvotes: 1