Jump to content

Claite

Members
  • Posts

    16
  • Joined

  • Last visited

    Never

Everything posted by Claite

  1. That totally worked! Thank you very much!
  2. I'm writing a login script for a site I'm making. I made a file called loginScript.php which contains the following code: <?php function loggedIn () { session_start(); if(isset($_SESSION['phone']) && isset($_SESSION['pass']){ return true; } else { return false; } session_write_close() } function login ($phone, $pass){ $connect = mysql_connect(stuff); if(!$connect) { die(mysql_error()); } mysql_select_db('site') or die(mysql_error()); session_start(); $newPass = base64_encode($pass); $phoneQry = "SELECT * FROM members WHERE phone = '$phone'" $qry = mysql_query($phoneQry); if(mysql_num_rows($qry) > 0){ $table = mysql_fetch_assoc($qry); if($newPass = $table['pass']){ $_SESSION['phone'] = $phone; $_SESSION['pass'] = $newPass; $_SESSION['username'] = $table['username']; } else { $errorLogin = "You typed in the wrong password"; } } else { $errorLogin = "That phone number does not exist"; } include "index.php"; session_write_close(); } Then, my index.php does as follows: if(loggedIn()){ <center>Welcome <?php $_SESSION['username']; ?>!</center> <a href="controlP.php">User Panel</a> } else { <form action="login.php" method="post"> Phone Number: <br><input type="text" name="username" maxlength="60"><br> Password: <br><input type="password" name="pass" maxlength="60"><br> <input type="submit" value="submit"> } And last but no least, login.php: <?php include "loginScript.php"; login($_POST['phone'], $_POST['pass']); ?> So, here's my issue. The line "include "loginScript.php" in login.php is causing this error: Fatal error: Cannot redeclare loggedin() (previously declared in *path*/loginScript.php:3) in *path*/loginScript.php on line 12 where *path* is an actual path. If I remove it however, it tells me login() is not defined. If I remove it from my index.php it'll throw errors because is use "if(loggedIn())" I tried maybe having my form call the function, but I don't know how to do that :S Any suggestions?
  3. I can't find the edit button. It would seem that after a period of time you can't modify your post... strange. So I solved the problem. It would seem that !isset($submit) does not require $submit to be declared, so I can change it in the registerscript.php to a value, and then it'll come up as true. Here is why I have now in case anyone else runs into this issue: register.php <html> <head> <?php session_start(); if (!isset($submit)){ $error = ""; session_destroy(); } ?> stuff stuff stuff <?php echo $error ?> <form action="registerscript.php" method ="post"> <b>Username:</b> <input type="text" name="username" maxlength="60" value="<?php if(isset($submit)){ echo $_SESSION['username']; }?>" ><br><br> <b>Password:</b> <input type="password" name="pass" maxlength="60" value="<?php if(isset($submit)){ echo $_SESSION['pass']; } ?>"><br><br> <b>Age:</b> <input type="text" name="age" maxlength="3" value="<?php if(isset($submit)){ echo $_SESSION['age']; } ?>"><br><br> <b>Email:</b> <input type="text" name="email" maxlength="100" value="<?php if(isset($submit)){ echo $_SESSION['email']; } ?>"><br><br> <input type="submit" name="submit" value="Submit"> </form> registscript.php <?php stuff session_start(); session_regenerate_id(); $_SESSION['username'] = $username; $_SESSION['pass'] = $pass; $_SESSION['age'] = $age; $_SESSION['email'] = $email; session_write_close(); if($username=='' | $pass == '' | $age == '' | $email == ''){ $submit = 1; $error = '<b>You have left one of the datafields blank. Please fill out all the information</b><br><br>'; include 'register.php'; exit(); } more stuff ?>
  4. Haku, Sorry, but I don't understand the need of a doctype. What exactly does it do? I'm pretty new to the HTML/PHP scene, so I don't really understand some of these things. Claite
  5. Haku, I'm getting a problem when I try it as you suggested. First. I had to convert my page to a .php to read the script of <?php ?> inside of the value quotes. This resulted in an error for my $error variable that I through when I do an include of the page, since it's undefined until they type something wrong. To solve this i put $error = ""; at the beginning of the page code, but now when it re-writes it in if($username=='' | $pass == '' | $age == '' | $email == ''){ $error = '<b>You have left one of the datafields blank. Please fill out all the information</b><br><br>'; include 'register.php'; exit(); } it gets RE-written again when doing the include. How do I make it so it doesn't re-initialize to "" when it re-loads the page? Or is there a better way to make it print the error? The same goes for the $_SESSION['username'] etc variables. I want to re-write them to nothing the first time in, then save them from then on after they enter something. I'm thinking along the lines of some if statement but I don't know how that'd work without initializing the variable before the statement. Maybe something like $failed = 0; if ($failed == 0) { $error = "" $_SESSION[.... .... .... $failed = 1; } but that'd also mess up when it includes the page. And just for reference, here is my form/error script: <?php echo $error ?> <form action="registerscript.php" method ="post"> <b>Username:</b> <input type="text" name="username" maxlength="60" value="<?php echo $_SESSION['username'] ?>"><br><br> <b>Password:</b> <input type="password" name="pass" maxlength="60" value="<?php echo $_SESSION['pass'] ?>"><br><br> <b>Age:</b> <input type="text" name="age" maxlength="3" value="<?php echo $_SESSION['pass'] ?>"><br><br> <b>Email:</b> <input type="text" name="email" maxlength="100" value="<?php echo $_SESSION['pass'] ?>"><br><br> <input type="submit" name="submit" value="Submit"> </form> God I hate notepad's formatting. Any suggestions on a better text editor? Preferably one with highlighting. EDIT: I deeply apologize for this going from a HTML help topic to a php one. If you want to move it to the PHP help section so I can get some feedback there, that'd be fine. Thank you!
  6. Not sure if this is the right section. I made a registry page that works just fine. But one thing is that when the person doesn't enter info into a field, I print a message saying "You haven't filled out all the fields.. yaadaa yaadaa" But all the forms are blank since the page reloaded. How do I make it so I can still display the message, but keep the fields they filled in still filled in. I'm using a register.html, which calls a register.php to process the data. If they didn't fill out a field, I include register.html with a variable $error that prints out the error if they didn't put in the info. Here's the register.html code: <?php echo $error ?> <form action="register.php" method ="post"> <b>Username:</b> <input type="text" name="username" maxlength="60"><br><br> <b>Password:</b> <input type="password" name="pass" maxlength="60"><br><br> <b>Age:</b> <input type="text" name="age" maxlength="3"><br><br> <b>Email:</b> <input type="text" name="email" maxlength="100"><br><br> <input type="submit" name="submit" value="Submit"> and here's the register.php code: if($username=='' | $pass == '' | $age == '' | $email == ''){ unset($username); unset($password); unset($email); unset($age); $error = '<b>You have left one of the datafields blank. Please fill out all the information</b><br><br>'; include 'register.html'; exit(); }
  7. Super apologies from the double post, but I want any mod that might have read the message above to also read this one (since edits don't appear as new posts) I fixed the issue. Everything still shifts but I just made the sidebar a little thinner (the login area) so when the page shifts due to the exceeded page size, it doesn't overlap. Thanks for all the help, Claite
  8. If you're talking about the shift in the title/header, that has to do with the rest of the page moving. The problem is that the scroll bar appears, and that scrunches my page, but I don't understand why. Shouldn't a page remain the same size and have the browser just add a necessary bottom scroll bar?
  9. That part is working though... I need to fix the strange part... I posted how I'm doing the php loop now, and it works just fine
  10. Haku, yes. That's been a bother very much. Since I want it to remain the sizes they are (and the code has definite table size) but they still change. I've tried changing the table values (increasing) to try to push it right... now thinking about it. I think the addition of the scroll bar (since page exceeds browser height) it shoves everything right. How can I prevent this? I'm ok with some of the page being covered by the scroll bar... Landavia, I'll try to use that. Thank you very much. It just seems pretty counter-intuitive to have all those variables and have it re-assigned so many times. Thanks again for all your help! I'm using $myFile = "news.txt"; $news = fopen($myFile, 'r'); while (!feof($news)){ $title = fgets($news); after I get more news, I'll add the for loop to 5. But this will work for the first... few days lol EDIT: Btw, I'm using 5.2.8
  11. Explode? I'm sorry, I'm really new to PHP (with only a little experience of html) Is that basically adding it to an array then I just check if the array has contents, then do the print out stuff, if not, stop? And if it is like that, how would I do it in my code?
  12. I used a text file because it's easier for me as a user to edit. I just need to open it up and write what I want, then the code for the site takes it and produces the format. Here is my full code after what I post (including what I posted as well): <!-- ~~~~~~~~~~~~~~~~~~~~~ NEWS ~~~~~~~~~~~~~~~~~~~~~~ --> <?php $myFile = "news.txt"; $news = fopen($myFile, 'r'); for ($i = 1; $i <= 5; $i++){ $title = fgets($news); ?> <font style="font-family:Cambria" size=5><b><?php echo $title ?></b></font> <img src="images/newsbar2point0.png"></img> <br> <img src="images/avatar.png" align="left"></img> <?php $name = fgets($news); ?> <font color="#AAAAAA" size="2">By <?php echo $name ?></font><br> <?php $theData = fgets($news); ?> <p><?php echo $theData ?></p><br><br> <?php $blankline = fgets($news); } fclose($news); ?> and here's my text file: Let me know if you want to see anything else.
  13. I really hope I can explain this properly. I'll try my best but if you still don't understand, please ask. I'm currently working on a page (using tables), and everything is lined up and working properly. However, when I put more content than the height of the browser window, everything shifts and is mis-aligned. Below you can see pics of what happens from being normal, to exceeding text. I put in a scrollable cell for the news, so that it never goes over the size of the browser, but that limits me on how many links I can put, and scrunches the page. I'd prefer to just fix the formatting problem. (posting links do to size) http://i59.photobucket.com/albums/g287/Claite/PHP%20page/okpage.jpg http://i59.photobucket.com/albums/g287/Claite/PHP%20page/pooppage.jpg Also, so I don't start a new topic for no reason. I wrote my own news script in php that reads from a file. The only problem is that I'm using a for loop. How do I write a "while file still has lines" code? What I have: <?php $myFile = "news.txt"; $news = fopen($myFile, 'r'); for ($i = 1; $i <= 5; $i++){ but I want it to go for just how many news things I have. Also, later I want to put a limit to 5 news articles. But that's a later problem. Thanks for all the help in advance! Claite
  14. Thank you so much for your help! I love it when stuff actually.... works
  15. So, if I add the file into the www directory under my own folder and run through localhost, it works. Thank you for that. But is there any way to allow a .php file opened from anywhere on the computer to be executed as such and run as PHP? Or will all my files and projects have to be within the wamp/www folder? I figure if not, then I'll just do all my stuff in that folder and be done with it
  16. I tried a search, and couldn't find anything related so I apologize if it has been already asked. I'm having very basic issues with PHP, which leaves me baffled. I installed Wamp server v. 2.0 with PHP, Apache, and MySQL. I'm running Windows vista Home basic 32 bit, and customarily use Firefox to run my pages. I'm still learning, so I was trying a login script that communicates with a MySQL database and writes in information (like a username and a password). When I started getting issues with it not writing, I tried a few echos to see what's up. That's when I found the problem. Nothing was echoing. I tried opening a new notepad file and simply wrote: <?php echo "Hello World"; ?> I tried also Hello World and 'Hello World'. Nothing is being printed. The page comes up blank. What's weird is that if I go to localhost on my browser, it comes up with the wamp page, and if I click the phpinfo() on there, it works. But if i wrote phpinfo(); in my code, still blank. Wamp is fully white, I've tried restarting and refreshing and wamp comes back online with all services running. Does anyone know the issue? I'm wondering if my computer isn't even processing PHP being installed on my computer... I feel bad that echo is the most basic function, and I can't even get that to work :'( Thanks in advance for all your help! If I wasn't clear, please ask. I really want to start learning/using PHP but if I can't even run it on my computer... Claite
×
×
  • 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.