• Content count

  • Joined

  • Last visited

  • Days Won


Gabrielphp last won the day on June 29

Gabrielphp had the most liked content!

Community Reputation

4 Neutral

About Gabrielphp

  • Rank

Previous Fields

  • Languages
    PHP, Javascript, jQuery, HTML, CSS, MySQL

Profile Information

  • Gender
  • Interests
    Web development
  1. You can look up for bootstrap landing pages and then you can work yourself up from there. Bootstrap it's easy to customize and you can always create your own pages as you don't need to create the components yourself, just paste the code, make a css file to have your own design, put some js and jquery in it for effects and there it is. And you can always use php and ajax to make it more interactive with users.
  2. It won't redirect you mainly because header cannot be used like that. Instead of using header just echo a javascript script: echo '<script>window.location.href="url";</script>';
  3. First of all you don't need to save the all URL in the database, you just need to save the path like if your view_video.php (example) is in the home directory, where index and other pages are and your video is in uploaded/$name, then you need to insert into the DB only uploaded/$name. If your php page is in other folder like a folder named "videos" and there is your page but then you have your video in the "uploaded" folder outside the videos folder then the path will be ../uploaded/$name and so on. And to stop uploading the URL in the DB you need to check whether the video has done uploading or not (and that's a bit hard cuz you need some kind of a library to check the percentage of the video uploading status) or you can just create a simple function that is being called every time you access the page, so the logic will be something like this "if(DB_URL == HOST_URL) { then show video } else { REDIRECT 404 NOT FOUND AND DELETE URL FROM DB}" this will be the logic, so if in the DB the url will be uploaded/$name but in the folder there is no such video with that url then it will redirect the user to 404 not found. I hope i helped you.
  4. It is so much much easier to do it in PDO, why don't you use it ? And it is even more secure. dbconnection: try { $username = "db_username"; $password = "db_password"; $db = new PDO("mysql:host=localhost;dbname=your_dbname", $username, $password); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); echo "Connected !"; } catch (PDOException $e) { echo $e->getMessage(); } then your script to insert those values: try { $sql = "UPDATE users SET Username=:username, Email=:email, EmployeeID=:empid, Designation=:design, Password=:password WHERE Id = :id"; $stmt = $db->prepare($sql); $stmt->bindParam(":username", $username); $stmt->bindParam(":email", $email); $stmt->bindParam(":empid", $employee); $stmt->bindParam(":design", $designation); $stmt->bindParam(":password", $password); $stmt->bindParam(":id", $id); if($stmt->execute()){ echo "<font face='Verdana' size='2' color='green'> You have successfully updated your profile <br /> </font>"; } else { $msg = "<font face='Verdana' size='2' color='red'> There is some problem in updating your profile. Please contact site admin <br /></font>"; } } catch (PDOException $e) { print_r($e->getMessage()); } This is a clean way to do what you want but in PDO not MySQLi.
  5. Upon refreshing, the video is still uploaded to database ? Not the folder, because i might be thinking that it displays you the page because in database there is a video saved with an url but on your host in the videos folder there is no video with the url from db, that's mostly why you have that error.
  6. <form method="post" action="/post.php"> -> this is wrong. <form method="post" action="post.php"> -> this is right ( if the post.php is in the same directory as the page you are calling on. <form method="post" action="../post.php"> -> goes with a directory up.
  7. I need to know what column do you have in your DB where the value is 1 and where you set the $_SESSION['id'] variable after login, after that i can help you further.
  8. I am not sure, this code won't run as normal php, it might be using some kinda of a framework that uses those operators, but as i said i'm not sure. It's also the possible way that this code was put into some kinda of a software maybe to highlight the syntaxes or something. As @Ingolme said.
  9. Have you tried it? It works just like that, it counts the rows.
  10. Lemme edit it a bit. try { $sql = "SELECT * FROM database WHERE email = :email"; $stmt = $conn->prepare($sql); $stmt->bindParam(":email", $email); $stmt->execute(); $numRows = $stmt->rowCount(); if($numRows > 0) { while($row = $stmt->fetch()) { $id = $row['id']; $name = $row['name']; $age = $row['age']; } } } catch (PDOException $e) { echo "Error: " . $e->getMessage(); } I have corrected a bit of mistyped methods that you used there. This should be secure enough.
  11. First stop using this query as it is not protected. Use prepared statements in order to protect your data from possible attacks. CODE: try { $sql = "UPDATE `user` SET merged = `no` WHERE email IN (:emailuser, :togethelp)"; $unsetmerge = $flash->prepare($sql); $unsetmerge->bindParam(":emailuser", $emailuser); $unsetmerge->bindParam(":togethelp", $togethelp); $unsetmerge->execute(); } catch (PDOException $e) { echo "Error: " . $e->getMessage(); } Using the catch function you can catch the error is being throw by the sql if there is any. This should do your job.
  12. Glad i could help.
  13. Why use success and error ajax functions when you can use .done and .fail? .done and then you do all the checks in the php script even the return so that way you don't need to do that much of a javascript code in order to display an message. For example my way i use to display messages with jquery is very simple. For example index.php <div id="return_php" style="display: none;"></div> <form id="test"> <input type="text" name="something" placeholder="Insert something ..."> <input type="submit"> </form> <script> $('#test').submit(function(e){ e.preventDefault(); $.ajax({ url: 'path/to/something.php', data: $(this).serialize(), dataType: 'html', type: 'POST' }) .done(function(data){ $('#return_php').fadeIn(400).html(data).delay(5000).fadeOut(400); }) .fail(function(){ $('#return_php').fadeIn(400).html('Something went wrong with the ajax script !').delay(5000).fadeOut(400); }) }); </script> This way you just call the php page in which you do the checks and whatever stuff and then you echo an alert which will then be displayed into the return_php div. The .delay(5000) acts as a delay for the fadeOut function, after 5 seconds the message will fade away. something.php $something = $_POST['something']; if(empty($something)) { echo "Something needs to be filled in !"; //This message will be then returned into the div return_php on the index.php page } else { //Example of database try { $sql = "SELECT something FROM something WHERE something = :something"; $stmt = $db->prepare($sql); //$db is from a config file you have to include $stmt->bindParam(":something", $something); $stmt->execute(); $rowCount = $stmt->rowCount(); //This works for every case, at least i use it this way and for me works just fine. if($rowCount > 0) //let us presume that the something has more rows { echo "Ok, there is something in that something !"; } else { echo "There is nothing in something with the something you typed !"; } } catch (PDOException $e) { echo "Error: " . $e->getMesage(); //This will be showed into the return div aswell as the echo is still a part of this page, and this page is called by ajax. } } Now, this is my way to do it time to time when i need live php script calling on my page without needing my page to refresh. Hope it helped at least for your issue with displaying messages. EDIT I've read again through your post and i think i figured out what is all about. When i try to use that ereg_replace() php function is always throwing me an Uncaught error as the function doesn't exist. This may be influencing how you are selecting the data by that variable. Instead of ereg_replace use preg_replace, It does the same thing. $email = $_POST['email']; $email = preg_replace('/\s+/, '', $email); NOTE! Some of the code i wrote may or may not fit your code if you copy paste it as it doesn't contain the same variables or functions that you wrote. You may need to adapt it to your use.
  14. First question, something like this should work: I made this with my own paths so you can understand what is the difference between $dir and $path_images. If you don't use the if condition then your scandir will show other files that will corrupt the img tag. $dir = '/xampp/htdocs/test/uploads'; $path_images = 'uploads/'; $files = scandir($dir); foreach($files as $key) { if(!preg_match('/.jpg|.jpeg/', $key)) continue; echo '<img src="' . $path_images . $key . '">'; } Second question As @Ingolme said you can use n2lbar() for that. Let's take this script as an example: //First we need to access data try { $sql = "SELECT user_comment FROM comments"; $stmt = $db->prepare($sql); $stmt->execute(); } catch (PDOException $e) { echo "Error: " . $e->getMessage(); } //Now fetch it and display it while ($row = $stmt->fetch()) { echo nl2br($row['user_comment']); //This will display row breaks } Third question I don't know to properly resize a picture with php, i think it's not that easy to do that, but, you can just add a if condition so that the user can upload only jpeg file about 200kb, this way will cut a lot of your work to code. And what do you mean by a specific directory? You want like an user to have it's own directory? Fourth question The user @Ingolme explained it pretty well with str_replace(); .