Reputation: 2510
I am trying to work with youtube API and trying to send a link from html page to my php script.(I am actually creating an API). But when I click on submit, nothing happens !! even the page is not loaded
Here is my html page
<html>
<title>Youtube Video Information</title>
<body>
<h3>Paste Video Url in the below box</h3>
<form name = "input" name = "input" action="youtubev3.php" method="GET">
<input type = "textarea" name = "videoURL" id = "videoURL"><br>
Comments: <input type = "checkbox" name = "comments"><br>
likes: <input type = "checkbox" name = "likes"><br>
dislikes: <input type = "checkbox" name = "dislikes"><br>
Views: <input type = "checkbox" name = "dislikes"><br>
<input type="button" name="submit" value="submit" name = "submit">
</form>
</body>
</html>
And here is my php source code.
<?php
class youtubev3{
function __construct()
{
}
function getdata(){
$string = $_POST['videoURL'];
$urlID = trim($string,"https://www.youtube.com/watch?v=");
echo $urlID;
$jsonObject = file_get_contents("https://www.googleapis.com/youtube/v3/videos?id={$urlID}&key=AIzaSyDvM6lnjHv5YMBA6I7ROjv2yYbnohN4PNY&part=snippet,contentDetails,statistics,status");
$json = json_decode($jsonObject);
$comentCount = $json->{'kind'};
//var_dump($json);
//echo $videoType;
}
}
$getData1 = new youtubev3();
$getData1->getData();
// $videoType = $json->{'items'}[0]->{'kind'};
?>
I hope my question is clear enough.
Upvotes: 0
Views: 63
Reputation: 495
In your PHP file you are trying to get the URL in $_POST
while from the form you are sending the data through get method.
Also the submit button has two name attributes.
<html>
<title>Youtube Video Information</title>
<body>
<h3>Paste Video Url in the below box</h3>
<form name = "input" name = "input" action="youtubev3.php" method="POST">
<input type = "textarea" name = "videoURL" id = "videoURL"><br>
Comments: <input type = "checkbox" name = "comments"><br>
likes: <input type = "checkbox" name = "likes"><br>
dislikes: <input type = "checkbox" name = "dislikes"><br>
Views: <input type = "checkbox" name = "dislikes"><br>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
Upvotes: 1
Reputation: 9001
Your method is GET
but you're looking for $_POST
.
Your syntax is very messy. Ensure that each HTML tag - including <form>
, <input>
and <button>
- has only one name
attribute and id
attribute.
To post the data, change the button type to type="submit"
instead of "button"
.
Use <textarea>
instead of <input type="textarea">
or, better yet for one-line inputs, use <input type="text">
.
<html>
<title>Youtube Video Information</title>
<body>
<form action="youtubev3.php" id="input" method="post" name="input">
<textarea id="videoURL" name="videoURL"></textarea><br>
Comments: <input name="comments" type="checkbox"><br>
likes: <input name="likes" type="checkbox"><br>
dislikes: <input name="dislikes" type="checkbox"><br>
Views: <input name="dislikes" type="checkbox"><br>
<input name="submit" type="submit" value="submit">
</form>
</body>
</html>
Upvotes: 1
Reputation: 703
Check your html code. It contains lots of spacing and errors. Also the input type should be submit.
Upvotes: 0