JoshuaDempsey
-
Posts
12 -
Joined
-
Last visited
Posts posted by JoshuaDempsey
-
-
Maybe you should get a different hobby/job/pastime then.
But it works absolutely fine. I now have it re-directing to a new page on success. So I don't think there is a problem here?
-
the error means that your SELECT query failed with an error of some kind. for debugging, echo mysql_error(); on the next line after the mysql_query() statement to find out why the query failed.
also, since you don't have any logic in your code to test if the query worked before tyring to use the result from that query, mysql_num_rows() will always be a zero and your code will never run the echo "The username you have entered is already exist. ... logic. you need to always test if a query works without any errors.
Thanks very much, code is working now.
I just got the output spat back onto the same page by the PHP, I have centred it etc. so it looks OK, I don't see the point of adding logic if I don't have too?
-
Hi guys, I was just making a simple login for my website when I came over this bug which I cannot for the life of me work out how to fix.
Whenever I enter a password etc. and submit the form it throws up this error, but inserts the information into the database correctly...
Strange. Anyway, I will dump my config.php file and the code in question and if anyone would give any hints as to why this is happening it'd be much appreciated.
Thanks
Config.php<?php $ver = 0.1; $database = "hidden"; // the name of the database. $server = "localhost"; // server to connect to. $db_user = "root"; // mysql username to access the database with. $db_pass = ""; // mysql password to access the database with. $table = "users"; // the table that this script will set up and use. $link = mysql_connect($server, $db_user, $db_pass); mysql_select_db($database,$link); ?>
Signup.php:
<?php # Grab the info from the config file to connect to the database require 'config.php'; ?> <!DOCTYPE HTML> <html> <head> <title> <?php if(session_id() == "" || !isset($_SESSION)){ echo "Sign Up"; } else{ echo "Re-Directing to the homepage"; } ?> </title> <meta charset="utf-8"> <link rel="stylesheet" href="css/global.css"> </head> <body class="signupPage"> <?php require 'LIP/topbar.php'; # LIP are pages: log in page and the sign up page if(session_id() == "" || !isset($_SESSION)){ } else{ Header ('Location: index.php'); } ?> <div class="title-container"> <h1 class="page-title"> Sign up for hidden </h1> </div> <div class="signup-description"> <p>hidden</p> </div> <div class="form-container"> <form class="" name="" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" autocomplete="on"> <input type="text" class="input-text" name="firstname" placeholder="First name" title="Enter your first name" required autofocus x-webkit-speech /> <br /> <input type="text" name="lastname" class="input-text" placeholder="Last name" title="Enter your last name" required x-webkit-speech /> <br /> <input type="text" name="emailaddress" class="input-text" placeholder="E-Mail Address" title="Enter your E-Mail Address" required x-webkit-speech /> <br /> <input type="password" name="password" class="input-text" placeholder="Password" title="Enter your password" required /> <br /> <input type="submit" class="input-button" name=""> </form> </div> </body> </html> <?php # Start of the code for the login form if(!empty($_POST['firstname']) && !empty($_POST['lastname']) && !empty($_POST['emailaddress']) && !empty($_POST['password'])){ // Above we check if all the fields have been entered // Now we take the input, change it to variables and cleanse it $firstname = $_POST['firstname']; $firstname = ucfirst($firstname); $firstname = htmlentities($firstname); $firstname = stripslashes($firstname); $firstname = mysql_real_escape_string($firstname); $lastname = $_POST['lastname']; $lastname = ucfirst($lastname); $lastname = htmlentities($lastname); $lastname = stripslashes($lastname); $lastname = mysql_real_escape_string($lastname); $eaddr = $_POST['emailaddress']; $eaddr = stripslashes($eaddr); $eaddr = mysql_real_escape_string($eaddr); $passcode = $_POST['password']; $passcode = hash("sha512", $passcode); $check = "SELECT * from emailaddress where eaddr = '".$eaddr."'"; $qry = mysql_query($check); $num_rows = mysql_num_rows($qry); if($num_rows > 0){ echo "The username you have entered is already exist. Please try another username."; echo '<a href="signup.php">Try Again</a>'; exit; } $query = "INSERT INTO users (fname,sname,emailaddress,password) VALUES ('".$firstname."','".$lastname."','".$eaddr."','".$passcode."');"; mysql_query($query); echo "Thank You for Registration."; echo '<a href="register.html">Click Here</a> to login you account.'; exit; } ?>
-
Thanks Ignace. I think I nearly have the program working, but I am stuck here:
function GetUserInput(){ echo "Please pick a minibeast from the menu"; echo " 1. Slug 2. Centipede 3. Ladybird 4. Snail 5. Woodlouse 6. Worm 7. Exit"; fwrite(STDOUT, "\n\nEnter your choice:\n"); $selected = fgets(STDIN); switch ($selected) { case ($selected == 1): UserChoice1(); break; case ($selected == 2): UserChoice2(); break; case ($selected == 3): UserChoice3(); break; case ($selected == 4): UserChoice4(); break; case ($selected == 4): UserChoice5(); break; case ($selected == 6): UserChoice6(); break; case ($selected == 7): UserChoice7(); break; } } // now each individual case function UserChoice1(){ 1 == 0; 1 == 1++; }
I get "error, unexpected ++ on line 55 (2nd last line). So how can I set the default value of the var 1 to 0, then every time someone hits 1 have it incriment by 1?
-
I tried this, but keep getting "undeclared variable" out. So I put it in front of the function, still didn't work, and it didn't work with the global keyword either for some reason?
I now have it like this:
fwrite(STDOUT, "\nEnter your choice:\n"); $selected = fgets(STDIN); function ProcessUserSelection($selected){ if($selected == "1"){ echo "hi"; } }
But get the undeclared variable out.?
-
I have these two functions:
function GetUserSelection(){ fwrite(STDOUT, "\nEnter your choice:\n"); $selected = fgets(STDIN); } function ProcessUserSelection(){ if($selected == "1"){ echo "hi"; } }
How can I make it that the second function can access "$selection" as the variables in a function are local, right? Is there a way I can make it global or accessible to other functions?
Thank you.
-
if they enter nothing, it will capture this:
\n
so you will likely have to check for it too.
echo (!empty($te) && $te != "\n") ? $te : "nothing";
Excellent help! Thank you. I replaced "nothing" with the function for them to enter the number again, but I noticed it only runs twice before exiting the program. Is there anyway I could use a loop to continue running the function again if certain conditions aren't met e.g. number less than 1 and more than 7 and no input. Thanks
EDIT: now there is a bug whereby anything I input it asks me for more input ):
-
What did you test this with, computermax2328?
-
I have been tasked to create a small program in any language I know, which is PHP.
It will be a console app (I can't install a LAMP stack etc) and it has to:
Allow one of six minibeasts to be selected from a menu
Enter and store the name and grid co-ordinates of the selected minibeast
Display how often each minibeast was found
Display the minibeasts found in each grid co-ordinate
So far in PHP I have got a welcome screen, then some of the menu from which they can input what minibeast they want to select information for (sort of). I have the actual menu worked out, it's a simple "echo" after all, but I need to work out how to execute different code based on their input.
This is my main file:
require_once 'functions.php'; require_once 'config.php'; welcome(); // Adds the welcome message to the program menu(); // Adds the selection menu to the console app getUserInput();
This is functions.php with all my functions:
<?php // This holds all of the functions for the // program // Welcome function (just text really) function welcome(){ echo " Welcome to the console application. "; echo " To begin using the program, type a number from the list below and then press \"ENTER\" to execute it. "; echo " For help, type \"help\" and execute it, for credits type \"credits\" and execute and for prog. info type \"info\". Version $vernumber "; } // Next is the selection menu function menu(){ echo " Please execute a number from below: 1. Slug 2. Centipede 3. Ladybird 4. Snail 5. Woodlouse 6. Worm 7. Exit "; } // Add the input catcher function getUserInput(){ fwrite(STDOUT, "Enter your choice\n"); $selected = fgets(STDIN); if ($selected = "1"){ echo "hi"; } elseif($selected = "2"){ } } ?>
This is where the problems start. I take their input as $selected, but the if statement is for some reason not working. Then I need to work out how to execute the function again if they enter nothing.
Could this be accomplished in a while.. loop?
Thanks a lot
-
= is assignment. == is comparison.
$selected = "josh" will ALWAYS be true. As you've discovered.
Silly me, thank you for the help Jessica, it is very much appreciated!
-
I am trying to get user input from the command line, but everytime I run this no matter what I enter I get "hi" returned. I don't know why this isn't working, and was hoping someone could take a quick look at it. Thank you:
function getUserInput(){ fwrite(STDOUT, "Enter your choice\n"); $selected = fgets(STDIN); if ($selected = "josh"){ echo "hi"; } else{ break; } }
Warning: mysql_num_rows() expects parameter 1 to be resource
in PHP Coding Help
Posted
If you are on about Header ('Location: index.php'); - then this works fine when there is a session?
The !isset checks if information has been entered to the page? But if the user is logged in they are re-directed to index.php anyway?
I know, I'm just getting the hang of this.