Jump to content

fael097

Members
  • Posts

    27
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

fael097's Achievements

Member

Member (2/5)

0

Reputation

  1. actually I don't know why not to use sessions. guess I learned with cookies some time ago. I fixed my problem by simply adding a header after setting the cookie. setcookie("User", "value", time()+3600); header("location: admin.php?ref=login"); that would refresh the page again, and therefore it could properly check if cookie has been set. same thing worked with logout. but now that you mentioned, it would be better to use sessions indeed. I'd still have to use cookies if I wanted a "remember me" option, right? suggestions?
  2. ok, so I found out that you can't set the cookie and retrieve it's value on the same request, that's why you need to refresh it twice. but how do i do this then? what's a workaround for that?
  3. thanks, and yeah, I just made both fields "admin" as a placeholder. but that didn't fix the problem. when I enter username and password, and press login, it runs form action, fields reset, but it doesn't login. cookies are set, but page is still the same. then if I press again, or simply refresh the page or even press enter on adress bar again, page changes, and I can see that I'm logged in, and the "hello administrator" message. then if I press logout, same thing. the hello page will still be there, until I press logout a second time, or refresh my page. and I have no idea why that's happening, but no errors or anything. I tried this on my local xampp server, and on an online host, same thing on both, so it's my code
  4. hi, I'm coding a website, after being away from php for a while, and there's this simple thing that's driving me crazy. I made a simple login system to test, and I have to refresh the page twice so it becomes active, and I can't figure out why. what's wrong with this code? (keep in mind that it's just a test, I plan to get username from database, send encrypted info to cookies, and all that, but after I get this working) <?php if (isset($_POST['submitlogin'])) { if ((($_POST['username'])&&($_POST['password']))=="admin") { setcookie("user", "Administrator", time()+3600); } else { $loginerror="1"; } } if (isset($_GET['logout'])) { setcookie("user", "", time()-3600); } ?> <html> <head> </head> <body> <?php if (isset($_COOKIE['user'])) { echo "Hello, ".$_COOKIE['user']; ?> <br /><a href="?logout=yes">Logout</a> <?php }else{?> <form action="" method="post"> <input name="username" type="text" /><br /> <input name="password" type="password" /><br /> <input name="submitlogin" type="submit" value="Login" /> </form> <?php }?> </body> </html> thanks for any help!
  5. hi, im making a simple blgo system, and i'd like to show a list of the last ten months, so the user can click the month name, and it will open the blog page with all the posts from that month, just like we usually see in blogs. any ideas? thanks in advance
  6. I made a simple test for debugging, heres my code: (I typed "ácéntôão" e "tôrrãodeaçúcar" directly on html for testing, those are exactly the same words I've put on my database.) <?php session_start(); $host_db="localhost"; $name_db="test"; $login_db="root"; $pass_db="123456"; $conn_db=mysql_connect($host_db, $login_db, $pass_db)or die("Could not connect. ".mysql_error()); $select_db=mysql_select_db($name_db, $conn_db)or die("Could not select database. ".mysql_error()); ?> <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Untitled Document</title> </head> <body> ácéntôão<br /> tôrrãodeaçúcar<br /> <?php $sql="SELECT * FROM test ORDER BY id LIMIT 3"; $result=mysql_query($sql); if(mysql_num_rows($result)) { while($row=mysql_fetch_row($result)) { echo $row[1]."<br />"; } } ?> </body> </html> my result: words in HTML appear exactly as I typed them, but the ones coming from DB appear with those unknown characters. what to do? i tried everything
  7. hi, I'm making a website, in portuguese, and i'm trying to retrieve characters with accent signals such as é ê á etc. while when I directly type words with such characters directly in my HTML, it displays correctly (i'm using utf-, if i save the same words into a mysql DB, and echo them out with php, they will appear with missing characters, you know, the "?" inside a square. im clueless. any help is appreciated. thanks in advance
  8. hi, im making a database for a really simple e commerce, and i need to publish products, for that ill have to store their prices on the database. i tried storing them with dots for the cents, but if i sort by price, it will return weird results like 530.00 510.00 50.00 490.00 (it will put the 50.00 between 500 and 400, like 50 was the same as 500) so dot is not an option. also, making a field for the value and another for the cents, sounds strange, but so far is the only option. anyone have better ideas? i also need a way to make users type the cents value on the price field, like a javascript that automatically adds a dot for the last 2 digits when you type something. also need better ideas on this. thanks in advance
  9. hi, i have a question, that i didnt manage to figure out myself. you know when you have a search engine, and you want to apply filters, and sort stuff by given parameter? if you simply make this: <a href="?filter1=low">low prices</a> <a href="?filter2=best">best rated</a> it wont keep both filters, if you click the first one, and then click the second one, it will replace the first clicked. my workaround for this so far: <a href="?filter1=low&filter2=<?php echo $_GET['filter2']; ?>">low prices</a> <a href="?filter2=best&filter1=<?php echo $_GET['filter1']; ?>">best rated</a> but thats not good when you have like 10 filters (wich is my case) you'll have an extense code for each anchor href... so i was trying to figure out a way to simply add variables to a $url variable, like if $_GET[variable] is set, $url.="add variable", and if that variable is already set, replace if its different, or keep if its equal, but i dont know if thats possible cuz i didnt manage to make it. is it doable? thanks in advance!
  10. hi, my question is simple, and i have no clue how to achieve that. i made a while(mysql fetch array) loop to put each database result on a <td>, but i want it to make a new <tr> each 4 tds, how to achieve that? thanks in advance
  11. my pagination is done, i just need to retrieve this number
  12. hi, i have like 93 entries on a database table, divided to show 20 per page, but i wanted to display something like "showing results 1 to 20" on each page, and on the last page, it would display "showing results 81 to 93". to get the first number, i use the same variable that i use to define where the page starts, but i dont know how to get the last entry that is being displayed. any clues? thanks in advance!
  13. hi! i have this real simple code to display result pages: <?php include("includes/connect_db.php"); if (isset($_GET["page"])) { $page=$_GET["page"]; } else { $page=1; } $start_from=($page-1)*10; $sql="SELECT * FROM test ORDER BY name ASC LIMIT $start_from, 10"; $rs_result=mysql_query($sql,$conn_db); ?> <table> <tr><td>Name</td><td>Surname</td></tr> <?php while ($row=mysql_fetch_array($rs_result)) { echo ' <tr> <td>'.$row["name"].'</td> <td>'.$row["surname"].'</td> </tr> '; } ?> </table> <?php $sql="SELECT COUNT(name) FROM test"; $rs_result=mysql_query($sql,$conn_db); $row=mysql_fetch_row($rs_result); $total_records=$row[0]; $total_pages=ceil($total_records/10); for ($i=1; $i<=$total_pages; $i++) { if($page==$i) { echo "<b>$i </b>"; } else { echo "<a href='?page=".$i."'>".$i."</a> "; } } ?> you can see it in action here: http://teapot.justca.me/test.php but the problem is that it displays how many pages there will be, and i need to display a maximum of 5 pages (1 2 3 4 5 ... [next] ), then a link to show the next set of 5 pages (the 3 dots, would return something like [previous] ... 6 7 8 9 10 ... [next]) and i have no clue how to do that. any help is highly appreciated! thanks
×
×
  • 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.