
laflair13
Members-
Posts
86 -
Joined
-
Last visited
Everything posted by laflair13
-
I understand it is going to happen eventually, but I dont understand why everyone is acting like it is going to be very soon. Like I said, I was just curious for my own knowledge.
-
This is for my own knowledge. I was looking into switching my site from mysql to mysqli because other say it is being depreciated with php 7. Well my question is, why is there such a sudden urge for it? I am on hostgator and they dont see in the near future when they (if they do) switch to the new php 7. They are still on php 5.5 Just curious on why everyone keeps saying that we all should switch to MySQLi or PDO like right now. Would like other thoughts and opinons on this. Thanks
-
Having fields show if only checkbox is checked
laflair13 replied to laflair13's topic in PHP Coding Help
You mean something like this? <div style="display:<?= ($offer === 1) ? 'block' : 'none'; ?>"></div> What about using an islet like ($isChecked && isset($model) && !empty($model)) with a corresponding checkbox. I did a search but do not understand how I can have a checkbox with the same name as the textfield. (like below) <input type="text" name="model" value="" class="form-control" /> <input type="checkbox" name="model"> -
Having fields show if only checkbox is checked
laflair13 replied to laflair13's topic in PHP Coding Help
I tried your suggestion and it didn't work. I think it is because what the user sees is not a form, the variable of the box is echoed on the frontend if the box is checked -
Having fields show if only checkbox is checked
laflair13 replied to laflair13's topic in PHP Coding Help
The end user wouldn't see the checkboxes, they would only see the variable if the checkbox is checked in the admin side. -
Having fields show if only checkbox is checked
laflair13 replied to laflair13's topic in PHP Coding Help
Must have explained it wrong. Right now I have it to where if the fields are blank they will not display on front end. I am trying to have the fields not display even though there is info, but the box is not checked. I just want it displayed if the box is checked. So to simplify what I need: Checkbox checked = Show on frontend Checkbox NOT Checked = Don't show Field empty = Don't show ( Don't think I would need this if the checkbox is determining if displayed or not ) Heres an image example that might help you understand better. (This is the fields in the admin when I add an item) The code below has it to where the info will not show on user side because it is empty. <?php if (isset($manufacture) && !empty($manufacture)) : ?> <li class="element element-text"> <strong>Manufacture: </strong> <?php echo $manufacture;?> </li> <?php endif; ?> <?php if (isset($model) && !empty($model)) : ?> <li class="element element-text"> <strong>Model #: </strong> <?php echo $model;?> </li> <?php endif; ?> -
There wouldn't be an error or syntax message, it would be on the frontside of the site. You should see something like this Warning: include_once(dologin.php): failed to open stream: No such file or directory in /home4/username/public_html/domain.com/page.php on line 4
-
Also keep in mind when you add a / (backslash) to the file path, it will show it coming from the root directory. Take away the backslash and see if that helps. And like ginerjm asked, the error will show you what line in your code is giving the error. Double check that the file path is correct. I would use a direct file path (http://domain.com/admin/dologin.php) to make sure it is uploaded.
-
First off, I hope I explain this right. I am wanting to show fields if only the checkbox next to it is checked. I have it set up that the fields will not show if the variable is empty, but I would like for it not to show unless the checkbox is checked if there is a variable. Here is an image of what is in the admin Here is the code I have for the variable to be shown on the site <?php if (isset($manufacture) && !empty($manufacture)) : ?> <li class="element element-text"> <strong>Manufacture: </strong> <?php echo $manufacture;?> </li> <?php endif; ?> <?php if (isset($model) && !empty($model)) : ?> <li class="element element-text"> <strong>Model #: </strong> <?php echo $model;?> </li> <?php endif; ?> And here is the code I am using when I put the item in the admin section <div class="form-group"> <label class="col-md-3">Manufacture</label> <div class="col-md-8"> <input type="text" name="manufacture" value="" class="form-control" /> </div> <!-- /.col --> <input type="checkbox" name="manufactureCheck"><span style="float:right; font-size: 10px; margin-top: 4px">Check to show</span> </div> <!-- /.form-group --> <div class="form-group"> <label class="col-md-3">Model</label> <div class="col-md-8"> <input type="text" name="model" value="" class="form-control" /> </div> <!-- /.col --> <input type="checkbox" name="modelCheck"> </div> <!-- /.form-group --> Also, I know I will have to add if the box is checked to the database. Could I just use one row named "Checked"? As for the code to make it show, couldn't I use something like this? <?php if ( isset($manufacture) && !empty($manufacture) ​&& !isset($manufactureCheck) ​&& !empty($manufactureCheck)) : ?> <li class="element element-text"> <strong>Manufacture: </strong> <?php echo $manufacture;?> </li> <?php endif; ?> Sorry if I didn't explain this good enough, I am very new to php.
-
"No such file or directory" means that the file is NOT uploaded to the server. I would put the direct url into the address bar to see if it shows up. Without knowing your directory, I am guessing by your code that the file dologin.php is not uploaded to the server or is in the wrong directory.
-
Admin check login just redirects back to login page
laflair13 replied to laflair13's topic in PHP Coding Help
Ok, I added this to the dashboard.php and I got the message "Welcome to the member's area", which tells me that I am able to login. <?PHP session_start(); if (!isset($_SESSION['members']) || $_SESSION['members'] != "1") { echo "Welcome to the member's area, " . $_SESSION['username'] . "!"; } else { echo "Please log in first to see this page."; } ?> BUT, I just realized that I was had by a simple mistake. With the code was working and logging me in, but I had the header location going right back to the index.php file. VERY BAD rookie mistake that I totally missed. <?PHP session_start(); if (!isset($_SESSION['members']) || $_SESSION['members'] != "1") { header ("Location: index.php"); } ?> -
Admin check login just redirects back to login page
laflair13 replied to laflair13's topic in PHP Coding Help
Appreciate it -
Admin check login just redirects back to login page
laflair13 replied to laflair13's topic in PHP Coding Help
I did say what happened here -
Admin check login just redirects back to login page
laflair13 replied to laflair13's topic in PHP Coding Help
Thats what I have been doing. It works when I have the initial code in there that uses "username" but when I change it to "email" it stops working. I know how to do trial and error, I just don't understand why it would stop working because I changed the variable. -
Admin check login just redirects back to login page
laflair13 replied to laflair13's topic in PHP Coding Help
I apologize if I am not explaining it right. When I login, it is just redirecting back to the login page. All I did was changed the variable from "username" to "email" For example, I changed this <?php include "class.database.php"; class Users extends Database { public function login($username, $password) { $stmt = $this->mysqli->prepare("SELECT username, password FROM members WHERE username = ? AND password = ? LIMIT 1"); $stmt->bind_param('ss', $username, $password); $stmt->execute(); $stmt->bind_result($username, $password); $stmt->store_result(); if($stmt->num_rows == 1) { while($stmt->fetch()) { $_SESSION['username'] == $username; header("Location: dashboard.php"); if ( !isset($_SESSION) ) session_start(); } } else { return false; } $stmt->close(); $stmt->free_result(); } } $users = new users(); ?> to this <?php include "class.database.php"; class Users extends Database { public function login($email, $password) { $stmt = $this->mysqli->prepare("SELECT email, password FROM members WHERE email = ? AND password = ? LIMIT 1"); $stmt->bind_param('ss', $email, $password); $stmt->execute(); $stmt->bind_result($email, $password); $stmt->store_result(); if($stmt->num_rows == 1) { while($stmt->fetch()) { $_SESSION['email'] == $email; header("Location: dashboard.php"); if ( !isset($_SESSION) ) session_start(); } } else { return false; } $stmt->close(); $stmt->free_result(); } } $users = new users(); ?> and on the login page , I changed this <?php session_start(); include "includes/class.users.php"; if(isset($_POST['login'])) { $username = $_POST['username']; $password = $_POST['password']; $users->login($username, $password); } ?> <form method="POST" action="" name="login"> <div id="wrappermiddle"> <h2>Login</h2> <div id="username_input"> <div id="username_inputleft"></div> <div id="username_inputmiddle"> <input name="username" type="text" id="myusername" placeholder="Email Address"> <img id="url_user" src="./images/mailicon.png" alt=""> </div><!--ends username_inputmiddle--> <div id="username_inputright"></div> </div><!--ends username_input--> <div id="password_input"> <div id="password_inputleft"></div> <div id="password_inputmiddle"> <input name="password" type="password" id="mypassword" placeholder="Password"> <img id="url_password" src="./images/passicon.png" alt=""> </div><!--ends password_inputmiddle--> <div id="password_inputright"></div> </div><!--ends password_input--> <div id="submit"> <input type="image" src="./images/submit.png" name="login" value="Login"> </form> to this <?php session_start(); include "includes/class.users.php"; if(isset($_POST['login'])) { $email = $_POST['email']; $password = $_POST['password']; $users->login($email, $password); } ?> <form method="POST" action="" name="login"> <div id="wrappermiddle"> <h2>Login</h2> <div id="username_input"> <div id="username_inputleft"></div> <div id="username_inputmiddle"> <input name="email" type="text" id="myusername" placeholder="Enter Email"> <img id="url_user" src="./images/mailicon.png" alt=""> </div><!--ends username_inputmiddle--> <div id="username_inputright"></div> </div><!--ends username_input--> <div id="password_input"> <div id="password_inputleft"></div> <div id="password_inputmiddle"> <input name="password" type="password" id="mypassword" placeholder="Password"> <img id="url_password" src="./images/passicon.png" alt=""> </div><!--ends password_inputmiddle--> <div id="password_inputright"></div> </div><!--ends password_input--> <div id="submit"> <input type="image" src="./images/submit.png" name="login" value="Login"> </form> -
Admin check login just redirects back to login page
laflair13 replied to laflair13's topic in PHP Coding Help
Sorry to keep posting but I broke it trying to change "username" to "email". I want to have them put in their emails and not their usernames. I don't see where I could have went wrong. index.php <?php session_start(); include "includes/class.users.php"; if(isset($_POST['login'])) { $email = $_POST['email']; $password = $_POST['password']; $users->login($email, $password); } ?> <form method="POST" action="" name="login"> <div id="wrappermiddle"> <h2>Login</h2> <div id="username_input"> <div id="username_inputleft"></div> <div id="username_inputmiddle"> <input name="email" type="text" id="myusername" placeholder="Enter Email"> <img id="url_user" src="./images/mailicon.png" alt=""> </div><!--ends username_inputmiddle--> <div id="username_inputright"></div> </div><!--ends username_input--> <div id="password_input"> <div id="password_inputleft"></div> <div id="password_inputmiddle"> <input name="password" type="password" id="mypassword" placeholder="Password"> <img id="url_password" src="./images/passicon.png" alt=""> </div><!--ends password_inputmiddle--> <div id="password_inputright"></div> </div><!--ends password_input--> <div id="submit"> <input type="image" src="./images/submit.png" name="login" value="Login"> </form> class.users.php <?php include "class.database.php"; class Users extends Database { public function login($email, $password) { $stmt = $this->mysqli->prepare("SELECT email, password FROM members WHERE email = ? AND password = ? LIMIT 1"); $stmt->bind_param('ss', $email, $password); $stmt->execute(); $stmt->bind_result($email, $password); $stmt->store_result(); if($stmt->num_rows == 1) { while($stmt->fetch()) { $_SESSION['email'] == $email; header("Location: dashboard.php"); if ( !isset($_SESSION) ) session_start(); } } else { return false; } $stmt->close(); $stmt->free_result(); } } $users = new users(); ?> -
Admin check login just redirects back to login page
laflair13 replied to laflair13's topic in PHP Coding Help
I haven't created it yet, I am searching for tutorials on how to do it. Just thought it might be a simple added line of code that someone might have known off the top of their heads. -
Admin check login just redirects back to login page
laflair13 replied to laflair13's topic in PHP Coding Help
Forgive me if I don't explain it right. I am very new to php/mysql and this is my first real attempt at it. Basically if a user logs in they either go to the admin.php or superadmin.php. I have them set up as roles ( 1 & 2 ) in the databases. role 1 would go to admin.php role 2 would go to superadmin.php I think something like this could work. The only difference in the 2 user roles is the superadmin can edit the user info but the admin cannot, so if I can hide that tab in the menu that would be great. <?php if(loggedin()==true){ $user_id=$_SESSION['user_id']; $log=$con->prepare("SELECT username,user_level FROM users WHERE user_id='$user_id'"); $log->execute; $log->bind_result($username, $user_level,$user_id); $log->store_result; if($log->fetch()) //fetching the contents of the row { if($user_level=='a'){?> <a href = 'index.php'>Home</a> <a href = 'profile.php'>Profile</a> <a href = 'admin.php'>Admin</a> <a href = 'index.php'>Log Out</a> <?php }if($user_level=='m'){?> <a href = 'index.php'>Home</a> <a href = 'profile.php'>Profile</a> <a href = 'index.php'>Log Out</a> <?php } }?> Now to find out how to handle sessions so someone who had the direct url cannot go to the page, it will redirect them to the login page. Finding some good tutorials so far, going to try them and see what happens. -
Admin check login just redirects back to login page
laflair13 replied to laflair13's topic in PHP Coding Help
THANK YOU That worked like a charm, I guess the tutorial was wrong. Now I need to figure out the 2nd part of it. Getting the user to reach different sections based on their role. I have my database set up that a user can be a superuser (role 1) or a regular user (role 2). How can I set it that based on what type of user they are, they get sent to 2 different urls? -
Admin check login just redirects back to login page
laflair13 replied to laflair13's topic in PHP Coding Help
Yea, guess that would help. index.php <?php session_start(); include "includes/class.users.php"; if(isset($_POST['login'])) { $username = $_POST['username']; $password = $_POST['password']; $users->login($username, $password); } ?> <form method="POST" action="" name="login"> <div id="wrappermiddle"> <h2>Login</h2> <div id="username_input"> <div id="username_inputleft"></div> <div id="username_inputmiddle"> <input name="myemail" type="text" id="myusername" placeholder="Email Address"> <img id="url_user" src="./images/mailicon.png" alt=""> </div><!--ends username_inputmiddle--> <div id="username_inputright"></div> </div><!--ends username_input--> <div id="password_input"> <div id="password_inputleft"></div> <div id="password_inputmiddle"> <input name="mypassword" type="password" id="mypassword" placeholder="Password"> <img id="url_password" src="./images/passicon.png" alt=""> </div><!--ends password_inputmiddle--> <div id="password_inputright"></div> </div><!--ends password_input--> <div id="submit"> <input type="image" src="./images/submit.png" name="login" value="Login"> </form> class.database.php <?php class Database { public function __construct() { $host = 'localhost'; $user = 'admin'; $pass = 'password'; $name = 'database'; $this->mysqli = new mysqli($this->host, $this->user, $this->pass, $this->name); } } ?> class.users.php <?php include "class.database.php"; class Users extends Database { public function login($myemail, $mypassword) { $stmt = $this->mysqli->prepare("SELECT email, password FROM members WHERE email = ? AND password = ? LIMIT 1"); $stmt->bind_param('ss', $myemail, $mypassword); $stmt->execute(); $stmt->bind_result($myemail, $mypassword); $stmt->store_result(); if($stmt->num_rows == 1) { while($stmt->fetch()) { $_SESSION['email'] == $myemail; header("Location: dashboard.php"); } } else { return false; } $stmt->close(); $stmt->free_result(); } } $users = new users(); ?> -
Admin check login just redirects back to login page
laflair13 replied to laflair13's topic in PHP Coding Help
I followed the tutorial but I am getting Warning: mysqli::mysqli(): (28000/1045): Access denied for user 'root'@'localhost' (using password: NO) in FILE PATH/includes/db_connect.php on line 9 I know it is all correct -
Admin check login just redirects back to login page
laflair13 replied to laflair13's topic in PHP Coding Help
Appreciate your time and help, I have searched and searched for a mysqli tutorial and I cannot find anything good. Everything I am finding is about registering a member and not about the login. I am about to try this one and see if I can get it working. https://www.2freehosting.com/forum/topic455-guide-php-mysqli-oop-simple-login-script.html -
Admin check login just redirects back to login page
laflair13 replied to laflair13's topic in PHP Coding Help
I edited the checklogin but now it is giving me a "Wrong username or password" I found a thread with the exact issue I was having but for some reason its not reading the db info. <?php ob_start(); $host="localhost"; // Host name $username="db-username"; // Mysql username $password="db-password"; // Mysql password $db_name="db-name"; // Database name $tbl_name="members"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Define $myusername and $mypassword $myusername=$_POST['email']; $mypassword=$_POST['password']; // To protect MySQL injection (more detail about MySQL injection) $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM members WHERE email='$myusername' and password='$mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" session_register("email"); session_register("password"); header("location:login_success.php"); } else { echo "Wrong Username or Password"; } ob_end_flush(); ?> -
Hey All, I am new to php and I am trying to learn how to set up my admin where it checks to see if the user is logged in before they can access the rest of the admin page. Right now I have it working but the user can access the pages if they know the url. I tried following a tutorial I found online but all it is doing is redirecting me back to the login page. It does the checklogin.php and it goes to the dashboard.php but redirects me as soon as I get there. Can you please look at my code and let me know if I am missing something simple? Any help would be very much appreciated. My form <form name="form1" method="post" action="checklogin.php"> <div id="wrappermiddle"> <h2>Login</h2> <div id="username_input"> <div id="username_inputleft"></div> <div id="username_inputmiddle"> <input name="myemail" type="text" id="myusername" placeholder="Email Address"> <img id="url_user" src="./images/mailicon.png" alt=""> </div><!--ends username_inputmiddle--> <div id="username_inputright"></div> </div><!--ends username_input--> <div id="password_input"> <div id="password_inputleft"></div> <div id="password_inputmiddle"> <input name="mypassword" type="password" id="mypassword" placeholder="Password"> <img id="url_password" src="./images/passicon.png" alt=""> </div><!--ends password_inputmiddle--> <div id="password_inputright"></div> </div><!--ends password_input--> <div id="submit"> <input type="image" src="./images/submit.png" name="Submit" value="Login"> </form> checklogin.php <?php $host="localhost"; // Host name $username="db-username"; // Mysql username $password="db-password"; // Mysql password $db_name="db-name"; // Database name $tbl_name="members"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // username and password sent from form $myemail = ""; $mypassword = ""; $errorMessage = ""; $num_rows = 0; $myemail=$_POST['myemail']; $mypassword=$_POST['mypassword']; // To protect MySQL injection (more detail about MySQL injection) $myemail = stripslashes($myemail); $mypassword = stripslashes($mypassword); $myemail = mysql_real_escape_string($myemail); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM $tbl_name WHERE myemail='$email' and password='$mypassword'"; $result=mysql_query($sql); if ($result) { } else { $errorMessage = "Error logging on"; } // Mysql_num_row is counting table row $num_rows = mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if ($num_rows > 0) { $errorMessage= "logged on "; } else { $errorMessage= "Invalid Logon"; } // Register $myusername, $mypassword and redirect to file "login_success.php" if ($num_rows > 0) { session_start(); $_SESSION['members'] = "1"; header ("Location: dashboard.php"); } ?> Here is what I have at the top of dashboard.php <?PHP session_start(); if (!(isset($_SESSION['checklogin']) && $_SESSION['checklogin'] != '')) { header ("Location: index.php"); } ?> Also, so I don't have to ask again, I have my database set up that a user can be a superuser (role 1) or a regular user (role 2). How can I set it that based on what type of user they are, they get sent to 2 different urls? I have learned so much from this site along with other forums but this one I haven't been able to figure out. Like I mentioned, I seen and followed a few tutorials but I couldn't get them working with my code I already had. So I figured this would be easier than having to redo my entire login page. Thanks Again.
-
Having a form insert the data in the database.
laflair13 replied to laflair13's topic in PHP Coding Help
<!-- basic fancybox setup --> <script type="text/javascript"> $(document) .ready(function () { $(".modalbox").fancybox(); $("#contact").submit(function () { return false; }); $("#send").on("click", function () { { // if both validate we attempt to send the e-mail // first we hide the submit btn so the user doesnt click twice $("#send").replaceWith("<em>Your request has been sent...</em>"); $.ajax({ type: "POST", url: "AJAX_Quote.php", data: JSON.stringify({fname: $("#fname").val(),lname: $("#lname").val(),email: $("#email").val(),eid: $("#Form_ID").val(),company: $("#company").val(),telephone: $("#telephone").val(),comments: $("#comments").val()}), dataType: 'json', success: setTimeout(function () { parent.$.fancybox.close(); }, 2000) }); } }); }); </script>