Jump to content

iamLearning

Members
  • Posts

    13
  • Joined

  • Last visited

iamLearning's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hey the code works! Thanks for helping, it's just I wish I understood that method earlier. I need to read more about MYSQL queries. Thanks again.
  2. Thanks for the advice! I'll give it a try! -edit- I have a quick question. In the above code you used the following: sql = "SELECT c.id, c.commentpage, c.user, c.comment,c.avatar, Are you concatenating those fields or are you suggesting I rename the fields to this? I wasn't aware that you could concatenate within an MYSQL query like that.
  3. I am creating a comment system which also displays replies. I am wanting to display the reply underneath the parent comment. As of right now, my code is functional but I can not think of a logical way to list the reply under-neath the parent comment. Here is my code. The code I wrote here is 100% functional. It is even able to sort through the comments and figure out which is a reply and which is not. The problem is I just don't know how to group the replies with the parent comment. If $parent_id = $comment_id then I know that $comment_id is the comment to display the reply underneath, but how would I write than in code? <?php //Retrieve Comments From Database $comments = mysql_query("SELECT id,parentid,commentpage,user,comment,avatar FROM comments WHERE commentpage='$youtubeid' ") or die(mysql_error()); if (!$comments) { //Check to see if there are any comments for this video. exit; }else{ while ($commentrow = mysql_fetch_row($comments)){ //If there are comments, then let's get their information. $comment_id = $commentrow['0']; //Get Comment ID $parent_id = $commentrow['1']; //Check to see if this comment is a reply. $comment_pageid = $commentrow['2']; //Get Comment Page ID $comment_author = $commentrow['3']; //Get Comment Author $comment_message = $commentrow['4']; //Get Comment Author $comment_avatar = $commentrow['5']; //Get Comment Avatar //Loop All Comments Here if ($parent_id == 0){ //Check to see if this is a reply or not. echo $comment_author.' commented <b>'.$comment_message.'</b><br>'; }else { // How do we handle the replies? echo $comment_message.' is a reply'; } //End Loop All Comments Here } } ?>
  4. Yeah? Thanks for the helpful advice..... I'm new to PHP and I was trying to code base on what I had read. Obviously my code is not perfect, but hey? That's why I was trying to get help. Thanks for pointing that out.
  5. When I try to run this script, it sends me back to the homepage instead of the actual processed page. How could I set up the header location file using the bottom script I posted to process the page submitted in the top script? //Start submitting video $dupeid = mysql_query("SELECT * FROM video WHERE youtubeid = '$youtubeid'"); if(mysql_num_rows($dupeid) == 0){ $insertquery = "INSERT INTO video (youtubeid) VALUES ('$youtubeid')"; mysql_query($insertquery); header('Location: ?page=video?id='.$youtubeid); //End Submitting video }else{echo "Sorry that video has already been posted!";} } }else{ echo 'The link provided is not a working Youtube link. Please try again.'; } } ?page is defined in this file <?php if (empty($_GET['page'])){ header('Location: ?page=home'); die(); } $core_path = dirname(__FILE__); $pages = scanDir("{$core_path}/pages"); unset($pages[0],$pages[1]); foreach ($pages as &$page){ $page = substr($page, 0, strpos($page, '.')); } if (in_array($_GET['page'], $pages)){ $include_file = "{$core_path}/pages/{$_GET['page']}.php"; }else{ $include_file = "{$core_path}/pages/home.php"; } if (array_key_exists('page', $_GET)) { $currentpage = $_GET['page']; } ?>
  6. You are a life saver! Thank you so much! LOL i did not realize that.
  7. I understand the problem, but I do not know how to fix this. I am using preg_match function here: function youtube_id_from_url($link) { $pattern = '%^# Match any youtube URL (?:https?://)? # Optional scheme. Either http or https (?:www\.)? # Optional www subdomain (?: # Group host alternatives youtu\.be/ # Either youtu.be, | youtube\.com # or youtube.com (?: # Group path alternatives /embed/ # Either /embed/ | /v/ # or /v/ | /watch\?v= # or /watch\?v= ) # End path alternatives. ) # End host alternatives. ([\w-]{10,12}) # Allow 10-12 for 11 char youtube id. $%x' ; $result = preg_match($pattern, $link, $matches); if (false !== $result) { return $matches[1]; }else{ return false; } } Everything works with my code here as long as preg match finds a match. If it does not find a match it gives me this notice. How would I fix this? <?php include 'functions/common.php'; include 'dbconnect.php'; $link = $_POST['submit']; //Start Youtube Video Submit Process $youtubeid = (youtube_id_from_url($link)); //Get Youtube ID from URL if (checkYoutubeOnline($youtubeid) == 1){ echo "The Youtube video seems to work fine The ID is ".$youtubeid }else{ echo 'Sorry that Youtube video does not exist! Please check that your link is correct and that the video is still online.'; } ?> <form action="submit_video.php" method="post"> <p>Link to video: <input type="text" name="link" /></p> <input type="submit" name="submit" value="Submit" /> </form>
  8. I tried this new code, but then I received: <?php include 'dbconnect.php'; $youtubeid = ($_GET['id']); $youtuberesult = mysql_query('SELECT * FROM videos WHERE youtubeid LIKE $youtubeid'); //Youtube video ID. $youtuberesult; if($youtuberesult === FALSE) { die(mysql_error()); // TODO: better error handling } while($row = mysql_fetch_array($youtuberesult)) { $dbyoutubeid = $row['youtubeid']; //Check to see if video exists within our database. if ($youtubeid==$dbyoutubeid){ //Youtube Embed echo '<iframe width="560" height="315" src="http://www.youtube.com/embed/'.$youtubeid.'" frameborder="0" allowfullscreen></iframe>'; }else{ echo 'Sorry that video does not exist in our library!'; } } ?>
  9. I have been doing this all by myself. I have tried to only look for help when I can't find a possible fix, but I am getting very frustrated now. I have spent like an hour trying to figure out why this keeps happening. Please help me if anyone has time to look at this. I am getting this error: Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\video.php on line 7 in regards to this code: include 'dbconnect.php'; $youtubeid = ($_GET['id']); //Youtube video ID. $query = mysql_query("SELECT * FROM video WHERE youtubeid='$youtubeid' "); $numrows = mysql_num_rows($query); if ($numrows != 0){ while ($row = mysql_fetch_assoc($query)) { $dbyoutubeid = $row['youtubeid']; } //Check to see if video exists within our database. if ($youtubeid==$dbyoutubeid){ //Youtube Embed echo '<iframe width="560" height="315" src="http://www.youtube.com/embed/'.$youtubeid.'" frameborder="0" allowfullscreen></iframe>'; }else{ echo 'Sorry that video does not exist in our library!'; } }
  10. I want to have a unique link for each posted video. Like for instance when a user uploads a video MYSQL asigns that video a unique ID. I know how to to this, but then How could I then take that ID and create a custom page that other users could link to to view that link? possible with the structure like this ?page=video?id=1 Right now this is the only bit of code I have dealing with links. <?php if (empty($_GET['page'])){ header('Location: ?page=home'); die(); } $core_path = dirname(__FILE__); $pages = scanDir("{$core_path}/pages"); unset($pages[0],$pages[1]); foreach ($pages as &$page){ $page = substr($page, 0, strpos($page, '.')); } if (in_array($_GET['page'], $pages)){ $include_file = "{$core_path}/pages/{$_GET['page']}.php"; }else{ $include_file = "{$core_path}/pages/home.php"; } if (array_key_exists('page', $_GET)) { $currentpage = $_GET['page']; } ?>
  11. EDIT: Fixed the problem. Solution - Although, how would I check for both username and password just to be extra safe? <?php session_start(); if (isset($_SESSION['username'])){ echo 'Welcome back <font color = "limegreen">'.$_SESSION['username'].'</font>!'; }else{ echo " <form action ='?page=home' method='POST'> Username: <input type='text' name='username'><br> Password: <input type='password' name='password'><br> <input type='submit' value= 'Log In'> </form> "; } if (isset($_POST['username'])){ $username = $_POST['username']; $password = $_POST['password']; if ($username && $password) { $connect = mysql_connect("localhost","root","") or die("Couldn't connect to server."); mysql_select_db("gameplayhr") or die("Couldn't find database"); $query = mysql_query("SELECT * FROM users WHERE username='$username' "); $numrows = mysql_num_rows($query); if ($numrows != 0) //code to login { while ($row = mysql_fetch_assoc($query)) { $dbusername = $row['username']; $dbpassword = $row['password']; } //check to see if they match! if ($username==$dbusername&&$password==$dbpassword) { //correct login information //You have logged in here. $_SESSION['username'] = $username; }else{ //incorrect login information echo "Incorrect password !"; } } else{ die("That username doesn't exist!"); } }else{ die("Please enter a username and password."); } } ?>
  12. I am trying to create a small login for the left side page of my website. Although the problem is, I keep receiving the error: Notice: Undefined index: username in C:\xampp\htdocs\template\leftsidebar.php on line 15 Notice: Undefined index: password in C:\xampp\htdocs\template\leftsidebar.php on line 16 Alright, so I know what it means. It means username and password have not been set yet. I also know that most often people use isset() to check and that's what I did. Please have a look at my code and try to help me with this problem, thanks. <?php session_start(); if (isset($_SESSION['username'])){ echo 'Welcome back <font color = "limegreen">'.$_SESSION['username'].'</font>!'; }else{ echo " <form action ='?page=home' method='POST'> Username: <input type='text' name='username'><br> Password: <input type='password' name='password'><br> <input type='submit' value= 'Log In'> </form> "; $username = $_POST['username']; $password = $_POST['password']; if ($username && $password) { $connect = mysql_connect("localhost","root","") or die("Couldn't connect to server."); mysql_select_db("gameplayhr") or die("Couldn't find database"); $query = mysql_query("SELECT * FROM users WHERE username='$username' "); $numrows = mysql_num_rows($query); if ($numrows != 0) //code to login { while ($row = mysql_fetch_assoc($query)) { $dbusername = $row['username']; $dbpassword = $row['password']; } //check to see if they match! if ($username==$dbusername&&$password==$dbpassword) { //correct login information //You have logged in here. $_SESSION['username'] = $username; }else{ //incorrect login information echo "Incorrect password !"; } } else{ die("That username doesn't exist!"); } }else{ die("Please enter a username and password."); } } ?>
  13. Ah! I fixed the problem. Funny mistake. I was trying to implement a user generated form, and well I had the submit button going back to a diffrent file which was returning the variable 300. I fixed the problem.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.