Jump to content

Gabrielphp

Members
  • Posts

    32
  • Joined

  • Last visited

Everything posted by Gabrielphp

  1. You need to have a name attribute in your input aswell, id doesn't work with Post just names. Otherwise you don't send any value to php logic to work with. <input id="FavMonster" name="FavMonster" type = "text" value = "" />
  2. You can use a php function called is_numeric(). if(is_numeric($var)) { //do stuff } else { //do other stuff } Hope this is what you want.
  3. Gabrielphp

    mail() max loop

    I think you will find this post on stackoverflow interesting. https://stackoverflow.com/questions/1543153/is-there-a-limit-when-using-php-mail-function
  4. It doesn't have a plain reading. You use that question mark because it is a query string. From https://www.freeformatter.com/url-parser-query-string-splitter.html What's the 'query string' in a URL? The query contains extra information that is usually in the key-pair format. Each pair is usually separated by an ampersand & character. It follows the ? character. Examples: http://www.foo.bar/image.jpg?height=150&width=100 https://www.secured.com:443/resource.html?id=6e8bc430-9c3a-11d9-9669-0800200c9a66#some-heade
  5. So what's your idea of coding a comment section? Before we can help you and eventually give you some code examples you need to show us some code too, we can't just give you the code without you doing something first because this way you won't learn to do it by yourself.
  6. If you are doing such coding use the : form and not { }, it will be much easier to understand the code when you mix them. <?php if(condition): ?> Html here <?php else: ?> Html here <?php endif; ?>
  7. So this is my answer for your problem: index.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Name Control</title> </head> <body> <form method="post" action="namecontrol.php" > <input type="text" name="name" placeholder="Insert your name ..." /><br/> <input type="text" name="lastname" placeholder="Insert your last name ..." /><br/> <input type="submit" value="Submit" name="submit" /><br/> </form> </body> </html> namecontrol.php (HTML LIST) <?php if($_SERVER['REQUEST_METHOD'] == "POST") { if(isset($_POST['submit'])) { $name = $_POST['name']; $lastName = $_POST['lastname']; if(empty($name) || empty($lastName)) { echo "Please complete all fields to proceed !"; } else { echo "<ul>"; echo "<li>name: " . $name . " </li>"; echo "<li>lastname: " . $lastName . "</li>"; echo "</ul>"; } } } ?> namecontrol.php (ARRAY) <?php if($_SERVER['REQUEST_METHOD'] == "POST") { if(isset($_POST['submit'])) { $name = $_POST['name']; $lastName = $_POST['lastname']; if(empty($name) || empty($lastName)) { echo "Please complete all fields to proceed !"; } else { $array = array("name" => $name, "lastname" => $lastName); print_r($array); } } } ?>
  8. I think you're missing something to tell us. I've recreated the same environment as yours and also added an echo "Ok!"; in the c.php and at me it works fine, exactly the same settings as yours. As i did it, i used Windows to do it, so it might aswell be the thing that you're using linux, and it might be possible that the paths don't work as are working in windows. Try putting the "../obj/c.php"; as path in the b.php althought you have it in the same directory and see if that works, if not then i don't know what should work as on my pc (windows) works just fine.
  9. What does it reffers to when it says has to see the data as a list? You mean like a html <ul><li> or an array() in php and echo that?
  10. It shouldn't let him log in as long as there is no other user with the same "Matricola" as in his SQL, i'm using fetchAll myself and i intentionally created another username with the same password as my other username and it won't log me in.
  11. What do you mean by encoding your php code? All i know is encoding charachters (UTF-8 etc) or json_encode(). What should your encoded code do?
  12. As long as my php knowledge goes is that you can't do it in pure php, you need some javascript aswell. Unfortunately i can't tell you diretly how is done cuz i never did something like that myself, but i found some tutorials that might help: http://subinsb.com/create-profile-picture-framer-web-app https://www.experts-exchange.com/articles/217/Framing-images-in-PHP.html Hope it helps.
  13. Try using fetchAll() instead of fetch().
  14. Ah, true, it has an or die statement. Sorry.
  15. In your code at the mysqli_connect() it misses this ";" it cannot work if you don't put it.
  16. Yes. <?= ?> is a shortcut for <?php echo ""; ?> All of the above will translate as follows: <?php echo ++$a; ?> <?php echo ++$b; ?> <?php echo $private_id; ?> <?php echo session_id(); ?>
  17. In your users table you should have a column called group or rang or whatever you want your admin to be named. After that you simply create a table called groups with your different ranks and functions, when you done that, you make sure that the id of the rang in the groups table match the id the user has in it's column. For example you make 2 different groups, Super User, and Moderator. Super User has the id of 1 and can access all administrative pages, in that case you make an IF condition between the Super User record's ID in the table and the user's ID in the column. The script will be something like this: if($_SESSION['user_rank'] == rank_required('page.php')) { //display page } else { //use a redirect method to a 404 not found or some kind of access restricted page } In the rank_required('page.php') will be a function that you will make and will check the rank's you've set for those pages, so that you make it a bit dynamically. But if you want an easy way, just set up it like: if($_SESSION['user_rank'] == 1) //in our case the super user { //display super user content } else { //display error or redirect } /* Also you can do something like this: */ if($_SESSION['user_rank'] == 1) { //display super user content } else if($_SESSION['user_rank'] == 2) //in our case the moderator rank { //display moderator content } else //in our case none of the above { //redirect page / error page } Easy enough, if you have any questions, feel free to ask, i personally didn't try the dynamically part as i never had a big website in which the dynamics would make a difference. But, in theory this should work pretty fine. I'm sure there are other methods out there. Oh, and for the rank_required('page.php'); function, never made a function like that, but i assume in order to work properly you will need to have another table in your database called page_ranks, in which will be a column with the name of the physical name of the page, the rank required (id from the groups table). After that it's all about if conditions with database record for that page. //Function function rank_required($page) { try { $sql = "SELECT * FROM pages_ranks WHERE page_name = :page"; //first we crate our sql to the database, we assume you already have a db connection $stmt = $db->prepare($sql); $stmt->bindParam(":page", $page); //now we bind the paramter in the sql with the variable from our function that we get from a page through basename() function; $stmt->execute(); $rowCount = $stmt->rowCount(); //warning as the rowCount(); function doesn't work if the previous statement that affected the db was an SELECT statement, but as long as you don't change records, i assume you will add all of your pages at one time, and then with the time the last sql statement would change, this should work just fine. if($rowCount > 0) { $row = $stmt->fetch(); //we fetch the result return $row['page_required_rank']; //this result will echo a value like: 1 or 2, depending on what id you have for your page in the page_required_rank collumn. Don't forget the ID depends on the group record's ID. And then this value will be compared into the header of the page with the $_SESSION['user_rank']; } else { return false; } } catch (PDOException $e) //catching possible errors { echo $e->getMessage(); } } But if you don't want to get complicated with all of this database stuff you can just use the define function and you can change the ranks whenever you want through the variables you defined, this will make a lot easier to work with grades, still, you will need to edit the user's column in the database. //Create a page like ranks.php and include it in everypage you need a rank system. //ranks.php define('SUPER_USER_RANK', '1'); define('MODERATOR', '2'); //page.php if($_SESSION['user_rank'] == SUPER_USER_RANK) { //display super user settings } else { //display error, redirect } //This helps you from later changing of the variable's value, so in that way you don't need to change the value from 1 to 2 or so on in everypage, you just have to change it in ranks.php to change the level of the required_rank. This is just a concept, to help you understand how this thing works, of course this is some basic php scripting, as i said before, i'm sure there are more complex and way efficient ways to do this, but if you're a beginner, this might help. It helped me in the past, and still helps me now. Hope i could help.
  18. Gabrielphp

    Sending mail

    You could just use XAMPP as your default webbrowser, xampp comes with pre-installed mysql, php and apache server, and it also have a firezilla ftp server and the mercury mail server. Just look up on it.
  19. 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.
  20. 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>';
  21. 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.
  22. 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.
  23. 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.
  24. <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.
  25. 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.
×
×
  • Create New...