Page 2 of 4

Re: Form to let users post a youtube video

Posted: Sat Aug 27, 2011 8:36 am
by stijn22
Hi,

Everything is working fine, except one thing. I have problems with the display of the links. See the attachment please.
Site2.jpg is what it is now, and site1.png is what i want it to look like, but I don't know how to edit the code that it displays it that way. And when users click on a link that is shown in site1.png the combobox shows up.

Re: Form to let users post a youtube video

Posted: Sat Aug 27, 2011 2:11 pm
by phphelpme
What do you mean everything works fine apart from one thing?

What you mean is the script I coded for you works fine but now you want it to look different is that right?

Sorry buddy but I can not code the whole thing for you. You have to learn something for yourself and at least have a go. I have coded the whole thing at the moment and I am not comfortable with you changing your mind and asking for somebody else to code it for you.

HAVE A GO YOURSELF FIRST, otherwise you aint gonna get any more help buddy.

Best wishes

Re: Form to let users post a youtube video

Posted: Sat Aug 27, 2011 5:49 pm
by stijn22
Ok, I think I can agree with you on that. But there's still a problem I just discovered. When I have submitted a video and then I want to look at it, I can click the link with the correct title. Then the combobox shows up. And there it stops. The combobox doesn't show a video. I don't see where the fault is. Maybe it's a problem that "embed" is not echo-ed? Like you see in this piece of code:

<BR><a class='example6' href="http://www.youtube.com/embed/fMBj5phmdJ ... ransparent" title="Black Ops: DHT# hanoi HCTF">2: Black Ops: DHT# hanoi HCTF</a>

Between the video-id (fMBj5phmdJM) of the yt video and the youtube.com is "embed", and after the video-id there's "rel=0&wmode=transparent", and I don't see any of that in the echo. If I could edit that echo myself I would have tried it, but I don't know how to edit the echo, and maybe split the link.

I hope I explained it good enough :)

Re: Form to let users post a youtube video

Posted: Sun Aug 28, 2011 8:28 am
by phphelpme
What ever you save as the link will be echoed buddy.

So you are talking about this combobox? what are you refering to as I did not code a combo box?

The code that echo's is this:

Code: Select all

echo "<a class=\"example6\" href=\"".$row['Link']."\" title=\"".$row['Title']."\">".$row['Title']."</a>"; // Includes your CSS class
That will echo everything in the link as required as the code is still on my system and works fine buddy. If it didn't then I would not have posted the code not working... lol

I do not understand this combobox you speak of?

As for your layout here is the code you need to insert into your display_video.php file and replace the old code:

Code: Select all

// Begin to build table for sql results
echo "<table border=\"0\" width=\"50%\" >"; // initial table width 50% of page
echo "<tr><th width=\"100%\">Title</th>"; // Title width share is 100%

// Display results in your table
while ($row =mysql_fetch_array($result)){ // Fetch your results and place in an array to call each value
               
        // Make sure you include your css file for your class="example6" to work with the popup function for each video    
        echo "<tr><td>";
        echo "<a class=\"example6\" href=\"".$row['Link']."\" title=\"".$row['Title']."\">".$row['Title']."</a>"; // Includes your CSS class      
        echo "</td></tr>";
        }
                echo "</table>";
Best wishes

Re: Form to let users post a youtube video

Posted: Wed Aug 31, 2011 3:33 am
by stijn22
Ok, i'll show you what's not working. Please visit this link and click on test. http://dht-clan.nl/source/showvideouploads.php (dutch site)
Then you'll see that the combobox is not working as it should.

Re: Form to let users post a youtube video

Posted: Wed Aug 31, 2011 3:38 am
by phphelpme
Your issue is the saved link in your database:

http://www.youtube.com/watch?v=WXy1KhUQMug

The above link is a direct link to Youtube website to play the video so it wont work with your css popup.

That does not have the required format to play the video and theres no embed anyway. Check your database or send me temp logins via pm so I can check it out for you as it might be your database that is stripping the link... lol

By simply adding: embed/ to the link like this: http://www.youtube.com/embed/watch?v=WXy1KhUQMug that would embed the video but its best to save the link in the correct format first.

Plus I dont get where you are coming from as you have used the code and works fine on this page: http://dht-clan.nl/source/filmpjes.html so your combobox is working if you save the correct link format to the database which I can only guess from your page example that the link you are uploading is not the correct one.

Best wishes

Re: Form to let users post a youtube video

Posted: Fri Sep 02, 2011 3:17 pm
by stijn22
Thanks for that, but you're not exactly right. The link has to be put in the database like this: http://www.youtube.com/embed/WXy1KhUQMug
And user's give then in this form: http://www.youtube.com/watch?v=WXy1KhUQMug

Can't we make a php script that transforms the link from the second to the first? Otherwise it will be too complicated for the users to put in the link.

Re: Form to let users post a youtube video

Posted: Fri Sep 02, 2011 8:56 pm
by phphelpme
hahaha its the exact same link that you just said it has to be. I used the watch?= etc but its just the same as yours accept I specified the param to begin with. lol

No worries either way. if you enter the correct link to begin with you should not have this issue full stop.

How can I help when I have not got the code for the css popup nor have I access to your database to see how the exact link is being saved.

I have this script running on my local server and I see the correct embed link echoed no issues at all.

I am trying to help you but your making if difficult for me too. I will not code a script to strip or alternate the link to the required standard as thats just not required. You need to save the correct link format into the database and no additional scripts are required.

PM me and we can sort it.

Best wishes,

Shaun.

Re: Form to let users post a youtube video

Posted: Mon Sep 05, 2011 9:18 am
by stijn22
Sice you're not reacting in the pm, i'll post it here:

I think I just can't explain it good enough. What I want to make clear is that, when an user submits a yt link, it is stored in the database as: http://www.youtube.com/watch?v=WXy1KhUQMug. Because that is what the users fill in in the form. When you click that link in showuservideos.php the combobox is not working. When I change the link that's stored in the database from: http://www.youtube.com/watch?v=WXy1KhUQMug to http://www.youtube.com/embed/WXy1KhUQMug, and then click that link in showuservideos.php the combobox IS working.

So I thought I had two options:
1. let the users put in the link as above (http://www.youtube.com/embed/WXy1KhUQMug), but that's maybe too complicated and will result in a lot not working videos.
2. make a script that transforms the link from http://www.youtube.com/watch?v=WXy1KhUQMug to http://www.youtube.com/embed/WXy1KhUQMug when you click submit and puts it in the databse after transforming it.

I hope I made myself clear.

Re: Form to let users post a youtube video

Posted: Tue Sep 06, 2011 4:14 am
by phphelpme
Hi there,

I was still waiting for your PM buddy. So I assume you have sent one to me already it would look like that did not come arrive successfully.

Anyway, I have PM'd you the details and also posted them here for your information.

Firstly, you would need to change the link using strpos(), strlen() and substr() functions.

Code: Select all

// ************************************** NEW SECTION - CHANGE LINK *************************************
	
    //$Link = "http://www.youtube.com/watch?v=WXy1KhUQMug"; // Link submitted by user

    $Find = "watch?v="; // Value to find in $Link

    $Locate_Find = strpos($Link, $Find) + strlen($Find); // Find location of $Find and moves starting point to end of $Find

    //echo $Locate_Find . "<br/> "; // Displays value location of $Find

    $Strip_Link = substr($Link, $Locate_Find); // Strips everything before $Find including $Find value

    //echo $Strip_Link . "<br />"; // Displays new string value $Link

    $Link = "http://www.youtube.com/embed/" . $Strip_Link; // Create your new link to be save to the database

    //echo $Link; // Displays new value of $Link
	
	// ****************************************** NEW SECTION - ENDS *****************************************
So, the above code needs entering into your existing insert_video.php file just after the:

Code: Select all

} else {
To make it less confusing I have provided a copy of the new insert_video.php file so you can just copy and paste if you have not made any alterations yourself that you need to keep. If you have then I suggest you just copy the new code into the right place.

Code: Select all

<?php

require_once("includes/connect.php"); // Your database connect file in a directory outside your root called 'includes'

// Gather the user input values
$Title = $_POST["Title"]; // Grabs your users Title
$Link = $_POST["Link"]; // Grabs your users Link

// Set error location link values for Title & Link
$error1 = "video_submit.php?e=1"; // Sets the string value for error redirect on Title
$error2 = "video_submit.php?e=2"; // Sets the string value for error redirect on Link

// Check to see user values have something in them
if (empty($Title)) {
                header("Location: $error1"); // Direct them back to your form with error Title missing
} elseif (empty($Link)) {
            header("Location: $error2"); // Direct them back to your form with error Link missing
} else {
	
	
	// ************************************** NEW SECTION - CHANGE LINK *************************************
	
	//$Link = "http://www.youtube.com/watch?v=WXy1KhUQMug"; // Link submitted by user

    $Find = "watch?v="; // Value to find in $Link

    $Locate_Find = strpos($Link, $Find) + strlen($Find); // Find location of $Find and moves starting point to end of $Find

    //echo $Locate_Find . "<br/> "; // Displays value location of $Find

    $Strip_Link = substr($Link, $Locate_Find); // Strips everything before $Find including $Find value

    //echo $Strip_Link . "<br />"; // Displays new string value $Link

    $Link = "http://www.youtube.com/embed/" . $Strip_Link; // Create your new link to be save to the database

    //echo $Link; // Displays new value of $Link
	
	// ****************************************** NEW SECTION - ENDS *****************************************
	
       
// Insert the values 'Title', 'Link' in your columns within your database (uservideos) table (????????)
        $insert = "INSERT INTO videos (Title, Link) VALUES  ('$Title', '$Link')"; // Create string of required actions
                mysql_query($insert) OR DIE (mysql_error()); // Saves values in to database or stops on mysql error

            header("Location: confirm.php"); // redirects to confirmation page
}
?>
This would change your link to how you have requested. If however, the link saved into the database is not the exact one you want them too this solution might not work. You might want to consider some error handling if the user submits an incorrect link format.

I hope this is what you need.

Best wishes

Re: Form to let users post a youtube video

Posted: Tue Sep 06, 2011 4:28 am
by phphelpme
So, I guess after reading my last post you would want to know how to incorporate a link error check maybe so here is a simple solution:

Code: Select all

<?php

//$Link = "http://www.youtube.com/watch?v=WXy1KhUQMug"; // Link submitted by user

$Find = "watch?v="; // Value to find in $Link

$Locate_Find = strpos($Link, $Find); // Find location of $Find and moves starting point to end of $Find

if ($Locate_Find == TRUE) { // Sets if statement $Find string value found equals TRUE
	
$Locate_Find = strpos($Link, $Find) + strlen($Find); // Find location of $Find and moves starting point to end of $Find

//echo $Locate_Find . "<br/> "; // Displays value location of $Find

$Strip_Link = substr($Link, $Locate_Find); // Strips everything before $Find including $Find value

//echo $Strip_Link . "<br />"; // Displays new string value $Link

$New_Link = "http://www.youtube.com/embed/" . $Strip_Link; // Create your new link to be save to the database

//echo $New_Link; // Displays new value of $Link

// Insert the values 'Title', 'Link' in your columns within your database (uservideos) table (????????)
        $insert = "INSERT INTO videos (Title, Link) VALUES  ('$Title', '$New_Link')"; // Create string of required actions
                mysql_query($insert) OR DIE (mysql_error()); // Saves values in to database or stops on mysql error

            header("Location: confirm.php"); // redirects to confirmation page

}

// Only executes this if the $Find value is not found in your $Link value and redirects the user to your video_submit.php with error code 3

else { header("Location: $error3"); } // Direct them back to your form with error Incorrect Link Format

?>
So, you can see from the above code the slight change in layout and additional lines. But the basics are all there. Now, you have in the above code stipulated another error code (3) so this needs creating in your video_submit.php like so:

Code: Select all

<?php if ($e == "3") { echo "<p>Please enter the correct link format: http://www.youtube.com/watch?v=XXXXXXXXXX"; } ?>
The above code would need to be inserted just below this line in your video_submit.php file:

Code: Select all

<?php if ($e == "2") { echo "<p>Please enter your link"; } ?>
You will also need to add the following code to your insert_video.php file:

Code: Select all

$error3 = "video_submit.php?e=3"; // Sets the string value for error redirect on Link
You need to add the error code 3 text below this line:

Code: Select all

$error2 = "video_submit.php?e=2"; // Sets the string value for error redirect on Link
Just on another note, you might want to replace the error codes in your insert_video.php with the follow:

Code: Select all

// Set error location link values for Title & Link
$error1 = "video_submit.php?e=1&Title=" . $Title . "&Link=" . $Link; // Sets the string value for error redirect on Title
$error2 = "video_submit.php?e=2&Title=" . $Title . "&Link=" . $Link; // Sets the string value for error redirect on Link
$error3 = "video_submit.php?e=3&Title=" . $Title; // Sets the string value for error redirect on Link but leaves the incorrect Link out
This will populate the form input boxs with what the user has entered if they make a mistake and will stop them having to fill in the form again with title etc. Notice if they type an incorrect Link format that link will not be passed back to the form becuase it is incorrect so you are forcing the user to type another (correct format) link in the input field.

Becuase of this you will also need to change the content of your video_submit.php file to the following:

Code: Select all

<?php
$e = $_GET["e"]; // Gets the error code if insert_video.php sends user back because of error
$Title = $_GET["Title"]; // Gets the error code if insert_video.php sends user back because of error
$Link = $_GET["Link"]; // Gets the error code if insert_video.php sends user back because of error
?>
<form method="post" action="insert_video.php">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td>Title:</td></tr>
<?php if ($e == "1") { echo "<p>Please enter a title"; } else {}?>
<tr><td><input type="text" name="Title" value="<?php echo $Title; ?>"></td></tr>
<tr><td>Link:</td></tr>
<?php if ($e == "2") { echo "<p>Please enter your link"; } else {}?>
<?php if ($e == "3") { echo "<p>Please enter the correct link format: http://www.youtube.com/watch?v=XXXXXXXXXX"; } else {}?>
<tr><td><input type="text" name="Link" value="<?php echo $Link; ?>"></td></tr>
</select></td></tr>
<tr><td>
<input type="Submit" name="Submit" value="Submit">
</td></tr>
</table>
</form>
I hope this gives you everything you want.

Best wishes

Re: Form to let users post a youtube video

Posted: Sat Sep 10, 2011 3:59 pm
by stijn22
Hi, I can't thank you enough for this, and sorry for reacting so slowly, I had little time these weeks.
However there's still a small problem. I have inserted all the code like you said in your previous posts. This is what my current insert_videos.php looks like:

Code: Select all

<?php

require_once("includes/connect.php"); // Your database connect file in a directory outside your root called 'includes'

// Gather the user input values
$Title = $_POST["Title"]; // Grabs your users Title
$Link = $_POST["Link"]; // Grabs your users Link

// Set error location link values for Title & Link
$error1 = "video_submit.php?e=1&Title=" . $Title . "&Link=" . $Link; // Sets the string value for error redirect on Title
$error2 = "video_submit.php?e=2&Title=" . $Title . "&Link=" . $Link; // Sets the string value for error redirect on Link
$error3 = "video_submit.php?e=3&Title=" . $Title; // Sets the string value for error redirect on Link but leaves the incorrect Link out

// Check to see user values have something in them
if (empty($Title)) {
                header("Location: $error1"); // Direct them back to your form with error Title missing
} elseif (empty($Link)) {
            header("Location: $error2"); // Direct them back to your form with error Link missing
} else {
       
       
        // ************************************** NEW SECTION - CHANGE LINK *************************************
       
        
//$Link = "http://www.youtube.com/watch?v=WXy1KhUQMug"; // Link submitted by user

$Find = "watch?v="; // Value to find in $Link

$Locate_Find = strpos($Link, $Find); // Find location of $Find and moves starting point to end of $Find

if ($Locate_Find == TRUE) { // Sets if statement $Find string value found equals TRUE
       
$Locate_Find = strpos($Link, $Find) + strlen($Find); // Find location of $Find and moves starting point to end of $Find

//echo $Locate_Find . "<br/> "; // Displays value location of $Find

$Strip_Link = substr($Link, $Locate_Find); // Strips everything before $Find including $Find value

//echo $Strip_Link . "<br />"; // Displays new string value $Link

$New_Link = "http://www.youtube.com/embed/" . $Strip_Link; // Create your new link to be save to the database

//echo $New_Link; // Displays new value of $Link

// Insert the values 'Title', 'Link' in your columns within your database (uservideos) table (????????)
        $insert = "INSERT INTO videos (Title, Link) VALUES  ('$Title', '$New_Link')"; // Create string of required actions
                mysql_query($insert) OR DIE (mysql_error()); // Saves values in to database or stops on mysql error

            header("Location: confirm.php"); // redirects to confirmation page

}

// Only executes this if the $Find value is not found in your $Link value and redirects the user to your video_submit.php with error code 3

else { header("Location: $error3"); } // Direct them back to your form with error Incorrect Link Format

?>
I've included the better errors, or at least tried. Maybe that's what's wrong.
When I click Submit this error line comes in:

Parse error: syntax error, unexpected $end in /home/a3612771/public_html/source/insert_videos.php on line 120

Line 120 is the closing of the html tag. I don't get it. I hope you know what's wrong (it's probably my fault :roll: ).

Re: Form to let users post a youtube video

Posted: Sun Sep 11, 2011 4:58 am
by phphelpme
Add a closing bracket to the end before your ?> end tag.

Code: Select all

}

?>
You have missed one out or probably deleted it.

That would make it work ok.

Best wishes

Re: Form to let users post a youtube video

Posted: Sun Sep 11, 2011 5:27 am
by stijn22
Thanks, it is working now! Only when I put in a wrong link I get a 404 page not found error.

Re: Form to let users post a youtube video

Posted: Sun Sep 11, 2011 8:31 am
by phphelpme
You must have changed something else because the code above would direct you to the correct page like the other error codes do.

When you dont type in a name (Title) does it redirect you ok? if it does then you need to check your last redirect error3 code top and bottom because the code above would work fine.

I can't do anything without seeing all your files and exactly what you have added, taken out etc.

Best wishes