Jump to content

headrush

New Members
  • Posts

    8
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

headrush's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. what I mean in above is its now showing the errors its showing the result as either the below and not showing the test errors I created. ​The only time it shows the error message is when I don't enter in one or both boxes and submits and echos out the error "You need to enter a username and password" So I know its doing the checks if user and password correct its displaying below int 1 2. 3.int 1 4. 5.Array ( ) if user and password incorrect int 1 2. 3.int 1 4.int 0 5.Array ( ) if not registered int 02. 3.int 0 4.int 0 5.Array ( )
  2. Hi Thank you so much for your response. ​What I have done is created a login form. and on click submit it checks this <?php if (empty($_POST) === false) { $username = $_POST['username']; $password = $_POST['password']; // If submited without entering in 1 box or both if(empty($username) === true || empty($password) === true) { $errors[] = 'You need to enter a username and password'; // If submited but username not in database } else if (user_exists($username) === false) { $errors[] = 'No username found. have you registered?'; } else if (user_active ($username) === false) { $errors[] = 'You need to activate your account to allow log in!'; } else { //somthing } print_r($errors); } ?> And using what you have provided it uses the functions. However When I login if I enter nothing in the username and password it does say 'please enter username and password'. However if I enter the correct username and password. it shows this? int 1 int 1 Array ( ) login.php <?php function user_exists($username) { $db = new mysqli('localhost','','','testing'); $user_exists_stmt = $db->prepare ('SELECT EXISTS (SELECT 1 FROM users WHERE username = ?)'); // Bind values to the parameters $user_exists_stmt->bind_param('s', $username); // Execute statement $user_exists_stmt->execute(); // Bind results to variables and fetch them $user_exists_stmt->bind_result($user_exists); $user_exists_stmt->fetch(); // Inspect result var_dump($user_exists); } function user_active($username) { $db = new mysqli('localhost','','','testing'); $user_active_stmt = $db->prepare ('SELECT EXISTS (SELECT 1 FROM users WHERE username = ? AND active =1)'); // Bind values to the parameters $user_active_stmt->bind_param('s', $username); // Execute statement $user_active_stmt->execute(); // Bind results to variables and fetch them $user_active_stmt->bind_result($user_exists); $user_active_stmt->fetch(); // Inspect result var_dump($user_exists); } ?>
  3. Hi I am trying to create 2 functions. ​one to check that user exists and the other to check that user is active. However I keep getting the error unexpected ',' on line 4 When I remove the ',' I still get errors. ​Does anyone have any idea where I'm going wrong and how to resolve? ​Thanks <?php function user_exists($username) { $username = sanitize($username); $result = $mysqli->query($db,"SELECT COUNT(`user_id`) FROM `users` WHERE `username` ='$username'"), 0) == 1) ? true : false; } function user_active($username) { $username = sanitize($username); $result = $mysqli->query($db,"SELECT COUNT(`user_id`) FROM `users` WHERE `username` ='$username' AND `active` = 1 "), 0) == 1) ? true : false; } ?>
  4. Hi Barand Thank you for your help In this matter It now works! ​I will have a look at the $age query and result Thanks again and have a great day!
  5. Thanks for your reply I understand I can not mix them, I'm just trying to figure out what I should write using Mysqli for the below code, ​ $age = mysql_result($age, 0); Any ideas? Thanks again
  6. Hi, ​On the below script I get this error Warning mysql_result() expects parameter 1 to be resource, object given in data.php on line 33 On another page there is a text box and button,when button is pressed the below file checks if there's a value in the text box, if it's in the database and if it is in the database it displays the results. The below case results being the name and age. In the below I tried to change the MSQL to MSQLI as much as I could except I'm stuck with line 33 which contains $age = mysql_result($age, 0); Any help with this would be much appreciated. Thanks This is the Data.php that the error is contained <?php $db = new mysqli('localhost','user','pass,'testing'); if($db->connect_errno) { //echo $db->connect_error; die('<br>Oops! we are having some problems, this is currently being fixed.'); } $name = mysqli_real_escape_string($db,$_POST['name']); if($name==NULL) echo "Please enter a name!"; else { $age = mysqli_query($db,"SELECT age FROM rates.People2 WHERE name='$name'"); $age_num_rows = mysqli_num_rows($age); if($age_num_rows==0) echo "Name does not exists!"; else { $age = mysql_result($age, 0); echo "$name's age is $age"; } } ?>
×
×
  • 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.