Jump to content

Nightasy

Members
  • Posts

    65
  • Joined

  • Last visited

Everything posted by Nightasy

  1. @maxxd - Thanks for catching that deprecation. I completely missed it and the .on() is really identical in functionality so all I had to do with change that one command. It didn't solve the issue I was having here though. The issue revolves around how Wordpress makes use of Ajax on the backend. In the wordpress documentation on it they try to make it sound like they way they handled the use of Ajax is the "greatest most easiest thing evar!!!" when in reality they just made it ten times more complex to do. From my readings it had to do with security issues they ran into quite awhile back. Either way though, it doesn't matter anymore. My team has decided to make the menu external from wordpress anyhow for added security measures since it controls our entire entry database. No sense in taking any risks with wordpress (which has been known to have been hacked) when we know that we can lock it up like fort knox using an external platform if you know what I mean. I would like to know how to do ajax with wordpress plugins but I suppose that's just something that will have to wait. Thanks for taking a look either way.
  2. Greetings all, Been trying to make a plugin in wordpress and ran into an issue with the way wordpress makes use of ajax in the administration menu. The problem is that I completely don't understand it. I've read all the docs on it and even tried messing with a variety of tutorials on the matter to no avail. What I am trying to do is a simple task outside of wordpress. The form has two select fields, the first field populates the second selection field. While this works fine on a standard html page, trying to do it in wordpress is another story. Form.php: <div id="wrapper"> <h1>Second dropdown selection based </h1> <form action="" method="post"> <p><label>Main Menu :</label> <select name="main_menu_id" id="main_menu_id"> <option value="">Select</option> <?php // Connect to database. $connect = mysqli_connect('<!--DB connection info-->"); $q = mysqli_query($connect, "SELECT cfid,cfname FROM categoryfiles ORDER BY cfid"); while($row = mysqli_fetch_array($q)) { echo '<option value="' . $row['cfname'] . '">' . $row['cfname'] . '</option>'; } ?> </select> </p> <p><label>Sub Menu: </label> <select name="sub_menu_id" id="sub_menu_id"></select> </p> </form> </div> The script.js $(function() { $("#main_menu_id").bind("change", function() { $.ajax({ type: "GET", url: "scripts/get_sub_category.php", data: "main_menu_id="+$("#main_menu_id").val(), success: function(html) { $("#sub_menu_id").html(html); } }); }); }); The get_sub_category.php <?php // Connect to database. $connect = mysqli_connect('<!--My connection info-->); $id = $_GET['main_menu_id']; $q = mysqli_query($connect, "SELECT sfid, sfname FROM subjectfiles WHERE sfcategory='" . $id . "' ORDER BY sfname"); while($row = mysqli_fetch_array($q)) { echo '<option value="' . $row['sfname'] . '">' . $row['sfname'] . '</option>'; } ?> Like I said, it works just fine outside of wordpress so really I just need help getting it to work in wordpress. I just don't understand it. Thanks to anyone that takes the time to look this over. Best Regards, Nightasy
  3. That was it. See, I knew it was something simple and staring me right in the face. Sometimes you just need a fresh pair of eyes to point out a blatant mistake. Thank you very much.
  4. Greetings all, I have been developing a comment box for my site and I ran into an issue I can't seem to figure out. In my comment box when I am logged in as an admin I want to be able to delete comments by simply clicking a button. The comments are printed out from a database using a while loop: <?php echo '<div id="commentMainTitle"><h3>Video Comments</h3></div>'; while($row = mysqli_fetch_array($results, MYSQLI_ASSOC)){ echo '<div id="commentUniqueWrap"> <div id="commentUniqueTitleMessageWrap"> <div id="commentUniqueTitle"> <h4>'. stripslashes($row['name']) .'</h4>';?> <?php if (isset($_SESSION['admin'])){?> <!--If admin add form for delete comment.--> <form enctype="multipart/form-data" action="includes/function/deletecomment.php" method="post"> <input type="hidden" name="cursect" value="<?php echo $sect1;?>" /> <input type="hidden" name="curvideored" value="<?php echo $_GET['curvideo'];?>" /> <input type="hidden" name="postID" value="<?php echo $row['id'];?>" /> <input type="submit" name="submit" value="Delete" /> <?php echo $row['id']; } echo '</div> <div id="commentUniqueMess"> <p>' . stripslashes($row['comment']). '</p> <p class="datealign">' . $row['date'] . '</p> </div> </div> </div>'; } ?> When the comments are listed out a Delete button is listed next to the commentors name. A comment is deleted however it is not the comment that is selected for deletion. Instead the last comment that was echo'd out from the while loop is deleted. Here is the script that deletes the comment: <?php if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['postID'])){ //Requires the database connection script. require $_SERVER['DOCUMENT_ROOT'] . '/mywebsite/masters/connect.php'; $qdelete = "DELETE FROM comment WHERE id ='".$_POST['postID']."' LIMIT 1"; if (!mysqli_query($connect,$qdelete)){ die('Error: ' . mysqli_error($connect)); } // Close database connection. mysqli_close($connect); // Set path for redirect. $redirect = 'http://www.mywebsite.com/myvideos.php?sect=' . $_POST['cursect'] . '&curvideo=' . $_POST['curvideored']; // Redirect to previous page. echo '<script type="text/javascript"> setTimeout(redirect, 0000); function redirect() { location.href="'.$redirect.'" } </script>'; } ?> I'm not sure what the issue is or how to go about solving it. I feel like the answer is staring me in the face but I've been looking at the code for too long and it has me at a loss. Any help would be greatly appreciated. Thank you for your time. Best Regards, Nightasy
  5. Yea, I completely understand it. In my case, adding a ../ basically leaves out the folder that the page is in, since it is not in the root folder. I completely get it now, I just never looked into why and now I know. Adding a ../ would send it to my root/videos folder instead of the root/folder_my_page_is_in/videos folder. It makes sense.
  6. Well, I suppose that explains it. Like I said I never looked into it but yea, my entire site is inside of a folder and uses a splash screen index page at the root. So I guess that explains why I had the issue on my new server and why I had it in college too. In college I had to put my site in a folder due to the way they taught some restrictions with .htaccess and folder permissions. Perhaps this is the case for eatc7402, I'm happy to have learned what you just told me though. I always wondered why that was an issue for my current server (and in my college course too). Learn something new everyday.
  7. If you are asking me for an example, I suppose this would suffice. This is from the index.php page on my most recent project. <div id="introvideodiv"> <video poster="videos/1.jpg" preload="auto" controls> <source src="videos/placeholder.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"' /> </video> If you'll notice, I have no ../ in the addresses for the poster and the video. If I add the ../ they won't work at all. No poster would show and no video would be located. My GoDaddy server is a shared server as far as I know and this is probably why I can't add the ../ in the addresses. I just figured I would mention it here because that little issue on my server stumped me for a couple hours when I first got the server through GoDaddy. Now my testing server is WAMP and it requires the ../ so I just do live test now in a password protected section (using sessions) on my server as it became a pain to keep changing that little detail on every page. Needless to say, though, aside from the white text on a white background my only assumption is that the address to the text file is not correct for whatever the reason. Be it the ../ or it needing an absolute path. On a side note however, the issue would also occur if for some reason the php folder is not permitting access. Just brain storming here. Perhaps an issue with the folder permissions or .htaccess restrictions?
  8. Nope, I'm serious. But I'm also still learning. I always figured there was a reason for it but I just remove the ../ and everything works as a result so I never looked into it. Ya know what, it also occurred to me that the server at my last college had the same issue. I had to remove the ../ on that server too.
  9. Not sure if this is the case here but I have encountered servers where adding a "../" in front of an address causes it to not work at all. You have: $info_test_file ="../php/info_test.txt" ; Just to test, try removing the ../ Like this: $info_test_file ="php/info_test.txt" ; I know it sounds silly but that actually matters on my GoDaddy server. It won't locate files if there is a ../ in front of addresses.
  10. I got it working. I had to add the javascript to an onload function. Turned out like this. <?php if(isset($_GET['vidhist'])){ ?> <script type="text/javascript"> onload = function() { create_window(<?php echo '"' . $_GET['vidhist'] . '"'; ?>,640,360); }; </script> <?php } ?>
  11. Alright, so I tried to set up the other page to create the popup when it loads if the GET variable is set. Unfortunately this did not work. Here is what I placed on the other page. if(isset($_GET['vidhist'])){ ?> <script type="text/javascript"> create_window(<?php echo $_GET['vidhist']; ?>,640,360); </script> <?php } ?> The javascript is not working when the page loads. It should create a pop up window.
  12. Greetings all, I have a bit of challenge that I don't know exactly how to solve. What I am trying to do is open a popup window using javascript and also redirect the page that has the original link on it to a new page. Basically what I want to happen is, user clicks on link, page redirects and a popup window opens at the same time. Sort of like having two links in one. Here's what I tried. It didn't work. echo ' <a href="sectvideo.php?sect=' . $row[0] . '"> ' . "<a href=\"javascript:create_window('".$row[1]."',640,360)\">" . ' <div id="historyUniqueWrap"> <div id="historyUniqueImage"> <img src="'. $row[2] .'"/> </div> <div id="historyUniqueTitleMessageWrap"> <div id="historyUniqueTitle"> <h4>Section: ' . $row[0] . " >>" . '</h4> <p>' . stripslashes($post1). "..." . '</p> </div> </div></a></a> Any ideas? Best Regards, Nightasy Edit: I just had an idea, I could set a condition to be met in the page that is being linked to using a GET. That would solve this issue. I'll try that and report back if it works or not.
  13. Well, apparently stripslashes solves this issue. Are there other ways besides stripslashes or preg_replace?
  14. Greetings all, I have a question about escaping characters prior to entering a field into a database and than echo'ing that escaped data back onto a page. My problem is that the slash marks are echo'ing out of the database onto another page. For instance if I were to do something along the lines of: $hpintrotitle = mysqli_real_escape_string($connect, trim($_POST['hpintrotitle'])); $q = "UPDATE homepage SET mstitle='$hpintrotitle' WHERE msid='1' LIMIT 1"; $r = @mysqli_query($connect, $q); If I place the word "You've" or "Isn't" into that field when I echo it out from the database it comes back as "You\'ve" or "Isn\'t" I know this is probably basic stuff but I apparently missed this lesson in school. Any help would be appreciated. Side note: I am bringing this data back as an array using something along these lines: $rowintro = mysqli_fetch_array ($rintro, MYSQLI_NUM); echo $rowintro[0]; echo $rowintro[1]; and so on.... Thanks for taking a look.
  15. I got it working. Doing some more google searches (gotta love google), I found a forum written in a foreign language which had the solution. Well, at least it works for me. The forums is here: http://www.php.net.my/forum/abs-mysql They talked about using 'abs' which is absolute value. I used Google translate to read it, I don't speak that language. I did the following: $q = "SELECT * FROM videofiles WHERE folder='" . $sect . "' ORDER BY abs(vidname)"; And now it sorts naturally. Works great! Figured I'd put the solution I found on here in case it helps anyone else. Thanks for taking a look. For more on abs take a look here: http://php.net/manual/en/function.abs.php
  16. Didn't seem to do the trick. I did this: $q = "SELECT * FROM videofiles WHERE folder='" . $sect . "' ORDER BY vidname REGEXP '^[A-Za-a]+$' ,CAST(vidname as SIGNED INTEGER) ,CAST(REPLACE(vidname,'-','')AS SIGNED INTEGER) ,vidname"; It's giving me the same output though.
  17. Greetings all, So I'm starting to play around with incorporating databases into dynamic pages and I've come across an issue that was only vaguely covered during my PHP course in college. The script below works great except that it needs a natsort and I'm not sure how to do a natsort and still make the while loop work. I'm not even sure how to go about writing it. The script queries the database for the video names, video descriptions and then turns them into links (with a little css and java help). But after video 9 it starts to order incorrectly. It goes ...1, 10, 11, 12, 2, 3, 4, 5.... you get the idea, needs a natsort. I just don't have a clue how to go about doing that and keeping the while loop working. I tried a couple things but I'm just not figuring this out. <?php require ('masters/connect.php'); // Define the query: $q = "SELECT * FROM videofiles WHERE folder='" . $sect . "' ORDER BY vidname"; $r = @mysqli_query ($connect, $q); // Count the number of returned rows: $num = mysqli_num_rows($r); if ($num > 0) { // Table header: echo '<h1>Section Lessons</h1>'; echo '<table id="link-table">'; // Set up array to remove beginning url from database section names. $sectpattern = $sect; $patterns = array(); $patterns[0] = '/videos/'; $patterns[1] = '/\//'; $patterns[2] = '/' . $sectpattern . '/'; $patterns[3] = '/\\.[^.\\s]{3,4}$/'; $replacements = array(); $replacements[0] = 'Lesson '; // Fetch and print all the records: while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { echo '<tr> <td>' . "<a href=\"javascript:create_window('".$row['vidname']."',640,360)\">Click Here</a>" . '</td> <td align="left"> <div id="tabledataimage1"> <img src="'. $row['vidimage'] .'" width="100"/> </div> <div id="tabledatatitle1"> <h4>' . preg_replace($patterns, $replacements, $row['vidname']) . '</h4> </div> <div id="tabledatadesc1"> ' . $row['viddesc'] . ' </div> </td> </tr>'; } echo '</table>'; mysqli_free_result ($r); } else { // Inform that no entries were returned from the query. echo '<p>There are currently no videos in this section.</p>'; } // Close database connection: mysqli_close($connect); ?> As always any help is greatly appreciated. I'm having a lot of fun learning PHP but I still have a long ways to go. Best Regards, Nightasy
  18. @mac_gyver - Yea, I get what you're saying. The issue actually wasn't even the upload script though, it had something to do with WAMP not being happy with me moving a file on my computer. Not exactly sure what causes that issue but the script does work when I test it on my live server. It uploads to the live server and works without a hiccup, which means that last night I spent several hours trying to fix a script that wasn't even broken in the first place. In the future I will definitely test upload scripts on the remote server instead of on my testing server. I have a secure testing environment setup with a password login on my remote live server anyhow that I put into place just for this type of issue.
  19. Actually, never mind. This script does work, well, it has issues that need worked out but it definitely uploads to the server just fine. Apparently this works on the live server but not on my local testing server. Thanks anyhow to anyone that looked it over, yes I know it needs more work. 8D
  20. Greetings all, So I'm trying to set up a video upload page and I can't seem to get it to upload the video. Here's the script. <?php //Start the Session. session_start(); //Set variable for page title prior to loading header which needs variable. $pagetitle = 'Home Page'; //Set variable for css file prior to loading header which needs variable. $navstyle = 'includes/styles/responsivemobilemenu.css'; //Set variable for css file prior to loading header which needs variable. $pagestyle = 'includes/styles/firstlevel.css'; //Set variable for responsive css prior to loading header which needs variable. $pageboiler = 'includes/styles/boilerplate.css'; //Add in header. include ('includes/header.php'); //Requires the database connection script. require ('masters/connect.php'); ?> <form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <fieldset> <legend>Select an mp4 video file:</legend> <br/> <label for="file">Select a video: </label><input type="file" name="upload" /> <br/> <label for="vidname">Video Name: </label><input type="text" name="vidname" size="25" maxlength="25" value="<?php if(isset($_POST['vidname'])) echo $_POST['vidname'];?>"/> <p><b>Video Description</b></p> <textarea name="viddesc" cols="40" rows="10" maxlength="255"> <?php if(isset($_POST['viddesc'])) echo $_POST['viddesc'];?></textarea> <br/> <div class="buttonHolder"> <br/> <input type="submit" name="submit" value="Begin Upload" /> </div> <br/> </fieldset> </form> <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { $errors = array(); /* // Check that video file is selected and mp4. if (!isset($_FILES['upload'])) { $errors[] = 'You forgot to select a video for upload.'; } else { $allowed = array("video/mpeg"); if (in_array($_FILES['upload']['type'], $allowed)) { // Get extension to variable. (Added this in case I want to allow other formats in future.) $oldvidname = $_FILES['upload']['name']; $ext = substr($oldvidname,strpos($oldvidname, '.')); } else { $errors[] = 'The file you selected is not an mp4!'; } } */ // Check for a video name: if (empty($_POST['vidname'])) { $errors[] = 'You forgot to enter a name for your video.'; } else { $vidname = mysqli_real_escape_string($connect, trim($_POST['vidname'])); $vidnamecheck = "SELECT * from videofiles WHERE vidname='$vidname'"; $vidresult = mysqli_query($connect,$vidnamecheck); $resultvidcheck = mysqli_num_rows($vidresult); if ($resultvidcheck > 0){ // If vid name exists display message. $errors[] = 'The video name you entered is already being used!';} } // Check for a video description. if (empty($_POST['viddesc'])) { $errors[] = 'You forgot to give the video a description!'; } else { $viddesc = mysqli_real_escape_string($connect, trim($_POST['viddesc'])); } // If no errors upload video and add to database, else report errors. if (empty($errors)) { // Upload Script Begin $oldvidname = $_FILES['upload']['name']; $ext = substr($oldvidname,strpos($oldvidname, '.')); $newviddest = 'videos/' . $vidname . $ext; $newvidname = $vidname . $ext; move_uploaded_file($_FILES['upload']['tmp_name'], $newviddest); // Display success messaage. echo "<p class='message'>Your video has uploaded successfully.</p>"; $query = "INSERT INTO videofiles (vidname, viddesc) VALUES ('$newvidname','$viddesc')"; if (!mysqli_query($connect,$query)){ die('Error: ' . mysqli_error($connect)); } // Close database connection. mysqli_close($connect); // Delete the file if it still exists: if (file_exists ($_FILES['upload']['tmp_name']) && is_file($_FILES['upload']['tmp_name']) ) { unlink ($_FILES['upload']['tmp_name']); } } else { echo '<div id="errorbox">'; foreach ($errors as $msg) { // Print each error. echo " - $msg<br />\n"; } echo '</p><p>Please try again.</p>'; echo '</div>'; } } ?> <?php include ('includes/footer.php'); ?> Ignore the validation check for the file selection. I'm having issues there as well and I commented it out. I plan to take a look at that once I can get the file to even upload. The script adds the fields into the database just fine but the video doesn't upload to the videos folder. Any help is greatly appreciated. Best Regards, Nightasy
  21. @mac_gyver : YES, this makes so much sense. Thank you very much. I actually had to walk away from my computer trying to figure this out. It was getting frustrating. Now that I see your code it's so obvious. Much appreciated!!! Edit: Oh, I kind of got rid of this little bit here: if($p == $current_page){ echo "[$p] "; // current_page not a link } else { It was throwing my divs all out of wack lol. This works great though and is exactly what I wanted. Thank you again!
  22. Greetings all, So, I'm working on my page navigation and I'm having a little trouble with my math here. It's probably a brain freeze from too much coding in one day but anyhow. What I'm trying to get my code to do is always show 9 pages and never show anymore then 9 pages in the navigation. Unfortunately that's not the result that I am getting with this script. // List page selectors. for($j = max(1, $current_page - ; $j <= min($current_page + 8, $total_pages); $j++) { $p = $j; echo "<a href='?p=" . $p . "'>" . $p . "</a> "; } I have a different script for the first page, previous page, next page and last page links. They all work fine of course since those are super easy scripts. Any help would be appreciated. Best Regards, Nightasy
  23. Oh I see now. I removed the true from the argument and just to test, so I better understood it, I also removed the $files = array_values($files); I didn't need to use array_values provided I removed the true from the second argument. It makes sense now after a good nights sleep.
  24. Thanks for the heads up. I'm pretty new to really playing with arrays. They covered arrays in my college course but for me it takes playing with this stuff outside of course material to really learn it. One code at a time I suppose. I really just needed the index to match the natsorted array in order to make use of a $files[$i] type loop further down in my script. Funny thing though, it was working with it set to true. I removed the true and it's still working exactly how it is supposed to. The example in the manual doesn't make much sense to me about how that true bool affects it though. Maybe I'm just tired lol. Regardless, it works one way or the other for my purposes so I just removed it. Edit: I mean, if you think about it. It wouldn't matter because I'm immediately following the array_reverse with array_values so it's all getting re-indexed anyways. Right?
×
×
  • 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.