-
Posts
364 -
Joined
-
Last visited
-
Days Won
1
Everything posted by Love2c0de
-
Good morning, I have now changed the code so that I login depending on the id's matching instead of the usernames. There seems to be a problem with my code though. I can login fine but I don't think my query is working correctly. The query should only join the profiles table onto the users table when the id's are matched depending on a session variable which I grab when they login. I only have one test profile setup in my DB at the minute but when I login to another test account, it still shows the 'template' div etc, where as it should be going into another php file which is going to insert their id and username into the profiles table, then run the SELECT query again to get their data. I'll post my code, it might be easier to understand. Here is my profile.tpl which is a template which I print into my main document: <?php if(!isset($_SESSION['user_name'])) { header("Location: ?page=home"); die(); } require("core/queries/profile_info.php"); if($row == 1) { $reg_date = date("l jS F Y H:i", $reg_date); $time_pos = strrpos($reg_date," "); $tmpstr = substr($reg_date,$time_pos); $tmpstr = " @".$tmpstr." hrs"; $reg_date = substr_replace($reg_date,$tmpstr,$time_pos); $last_login = date("l jS F Y H:i", $last_login); $time_pos = strrpos($last_login," "); $tmpstr = substr($last_login,$time_pos); $tmpstr = " @".$tmpstr." hrs"; $last_login = substr_replace($last_login,$tmpstr,$time_pos); //main profile information div $profile = "<div id='profile_main_box'>"; $profile .= "<div id='primary_info'>"; $profile .= "<h1 class='profile_user_name'>{$user1}</h1>"; $profile .= "<p class='profile_txt'>Member since: {$reg_date}</p>"; $profile .= "<p class='profile_txt'>Last logged in on: {$last_login}</p>"; $profile .= "</div>"; $profile .= "<button class='edit'>Edit Profile</button>"; //start form $profile .= "<form method='post' id='updateprofileform' action='?page=profile'>"; $profile .= "<fieldset><legend>Update your profile</legend>"; $profile .= "<p class='profile_p'><label for='fname'>First Name:</label><input type='text' name='fname' id='fname' value='{$fname}' /></p>"; $profile .= "<p class='profile_p'><label for='lname'>Last Name:</label><input type='text' name='lname' id='lname' value='{$lname}' /></p>"; $profile .= "<p><label for='dob'>Date of Birth:</label><input type='text' name='dob' id='dob' value='{$dob}' /></p>"; $profile .= "<p><label for='location'>Location:</label><input type='text' name='location' id='location' value='{$place}' /></p>"; if($sex == "Male") { $profile .= "<p class='radio'><label for='gender'>Gender:</label><input type='radio' name='gender' id='gender' value='male' />Male"; $profile .= "<input type='radio' name='gender' id='gender' value='female' /></p>"; } else { $profile .= "<p class='radio'><label for='gender'>Gender:</label><input type='radio' name='gender' id='gender' value='male' />"; $profile .= "<input type='radio' name='gender' id='gender' value='female' />Female</p>"; } $profile .= "<p><label for='fb'><img src='images/facebook_icon.png' class='form_img' alt='fb' />Facebook:</label><input type='text' name='fb' id='fb' value='{$fb}' /></p>"; $profile .= "<p><label for='twitter'><img src='images/twitter_icon.png' class='form_img' alt='twitter' />Twitter:</label><input type='text' name='twitter' id='twitter' value='{$twitter}' /></p>"; $profile .= "<p><label for='skype'><img src='images/skype_icon.png' class='form_img' alt='skype' />Skype:</label><input type='text' name='skype' id='skype' value='{$skype}' /></p>"; $profile .= "</fieldset>"; $profile .= "<input type='submit' value='Save Profile' />"; $profile .= "</form>"; $profile .= "</div>"; } else { //if the query failed, the user has not created a profile yet, so insert his id and username into the profiles table //then, run the profile_info query again to return the users profile to use, then they can update from there... require("core/queries/setup_profile.php"); } print($profile); ?> So as you can see, I click my profile link and I go into another file called profile_info.php which is here: <?php $conn = new mysqli("localhost","root","","*****") or die("Error creating connection."); $stmt = $conn->prepare("SELECT * FROM users LEFT JOIN profiles ON users.id=profiles.p_id WHERE users.id=?") or die("Error: ".mysqli_error($conn)); $stmt->bind_param("i",$_SESSION['id']); $stmt->execute(); $stmt->bind_result($id1,$user1,$pass,$email,$reg_date,$last_login,$id2,$user2,$fname,$lname,$dob,$sex,$place,$skype,$fb,$twitter); $stmt->store_result(); $stmt->fetch(); $row = $stmt->num_rows; mysqli_close($conn); ?> So the query is searching for id's to match and joins some data when it finds it. I presumed if it didn't find it, it would not return any 'num_rows'. When we return to the profile_info.php script, the if statement is executing ALWAYS, even when there is no ID which can be possibly matched. My idea is using the else statement to insert an id and username into profiles, only if they haven't previously setup a profile. I'm not a fan of concatenating too many times so I might put the form into another file and use file_get_contents() or something but for the time being just need to get this sorted. Iit must be the query. Can anyone possibly help? Kind regards, L2c.
-
Thanks a lot, I'll start editing that now. Kind regards, L2c.
-
To be quite honest, I thought it was the correct way to do so, keep 'required' data if you like in my users table and anything trivial such as a profile which isn't necessary I wanted to keep in a separate table. I'm guessing that normally you would keep all this info within the same table? Kind regards, L2c.
-
Good evening all, I wanted to know something about users/profiles accounts. When a user registers should I be creating a default profile for them in my profiles table at the same that they register, maybe with null or empty fields? I hardcoded a dummy profile so I had something to work with and at the moment when they register, I only insert the data into the user table, and nothing into the profiles table. I am linking the two tables together via the username. With my dummy profile, I am at the point where I am now going to write the update query, but I figured if I don't create a default profile on registration, there will be no row to update as such. I thought if I insert the username into the profiles table at the same time as registering their details in my users table, when they come to 'editing' their profile and updating their profile, it will have a row to select. Is my train of thought correct or completely off mark? I hope I got my point across well enough. Kind regards, L2c.
-
Good evening, I am working on user profiles and wonder whether or not I should bother validating the facebook, twitter and skype fields? For example, checking the twitter name starts with the @ symbol etc. I want to know what some of you would do, I don't really want to display an error for a bad social media name but I'm not sure if it standard practice to do so. Simple question really but it will probably lead into more questions before the night is gone! Thanks for your help and advice. Kind regards, L2c.
-
Good morning, What browser is it happening in? I got it in IE here and the middle image has a border round it in IE - did you want that? Kind regards, L2c.
-
Can you post your form code? Kind regards, L2c.
-
Of course, had the topic continued I would told him about the dangers of putting data straight into a query but he didn't seem to reply so never got the chance. I believe he could be back when he has some unexpected results Regards, L2c.
-
Try changing your code to this and see if it helps you: $db_usr= $_POST["userid"]; $db_pswd= $_POST["password"]; $con=mysql_connect("localhost",$db_user,$db_pass, $db_name); if(! $con) { die('Connection Failed'.mysql_error()); } mysql_select_db("*****",$con); $sql=mysql_query("SELECT * FROM users WHERE userid={$db_usr} and password={$db_pswd}"); $rows = mysql_num_rows($sql); if($rows == 1) { echo "Welcome back, ".$db_usr; } else { echo "You did not enter a correct username/password."; } You would also set a session if you are looking to create a user login system. Sessions retain their value when navigating through different pages on your website. A standard variable will not work as once the script ends, the standard variables' value is lost. Regards, L2c.
-
This logic seems really off key to me. So, the values $_POST["userid"] and $_POST["password"] come from the form yes? Are they values which the user enters? With your mysql_connect() function, it takes only 3 parameter, but but you have specified 4 making me think you have got mixed up the with mysqli_ connect() extension which takes 4 - (host,user,password,db). mysql_connect() takes 3 - host, user, pass. You then connect to the database using mysql_select_db() - accepting 2 parameters the database name/variable and the link/connection variable. Having said that, you should really be using the mysqli_ extension as mysql standard declaration has been deprecated as of 5.5.0. Kind regards, L2c.
-
Oh, this seems to have fixed it: $stmt = $conn->prepare("SELECT * FROM users,profiles WHERE users.username AND profiles.username = ?") or die("Error: ".mysqli_error($conn)); Regards, L2c.
-
Good evening, I am trying to create a user profile system on my website. I have the ability to register and login fine. I've hard coded a dummy profile into the profiles table. The way in which I am going to retrieve the profile data is by matching the users username in both tables. At the moment my query is returning all of the members in the user table and all of the profile information in the other table - profiles. This is my query: $stmt = $conn->prepare("SELECT * FROM users LEFT JOIN profiles ON users.? = profiles.username") or die("Error: ".mysqli_error($conn)); Not sure if the way I am going about it is the correct way either so any advice and guidance is greatly received. Kind regards, L2c.
-
Thank you for your reply. Kind regards, L2c.
-
What is the best format when storing addresses into a table? Should I split the address into separate columns like: house_name_or_number street_name city_or_town county post_code Or should I just store it into one field as a full string? Kind regards, L2c.
-
Good evening Barand, I'm not searching for a matching postcode as such, I need to return some results based on the distance, ordered nearest to farthest. So I need to have some sort of file/database which is holding the addresses and post codes of all the CAB's nationally. I'm not quote sure about the last sentence and will be researching all of this shortly but is there a way to integrate a database of addresses and postcodes of CAB's into something like the Google Maps API? Thanks for your input, Kind regards, L2c.
-
Thank you very much, I've decided to go for the Google Maps API route and I'm currently just on the developers part about to read up on it. Kind regards, L2c.
-
Sorry I'm finding this difficult to explain. What I want is the user to enter their post code into an input, which will then display to them the nearest 5 citizens advice bureau addresses but ordered by distance from the users location. Let's say I'm in London and for example lets say there are 10 citizens advice bureaus in that city. I want my page to return the 5 nearest CAB's relevant to the users post code. Even if one of those 5 CAB's is not WITHIN London, it should display the 5 nearest ones. I need to determine what the distance is of each CAB depending on the users post code, then return to them 5 of the nearest CAB's Kind regards, L2c.
-
Good evening, I want to have a page where users can enter their postcode to find their nearest Citizens Advice Bureau. This is throughout England (excluding Ireland, Scotland and Wales). My questions are: How can I compare the post code entered by the user to the post code of the exisiting Citizens Advice Bureau's? I know in PHP we can use a string function which compares the similarity between 2 strings but this clearly isn't going to suffice and work properly as you could have a CAB in London with post code SW1X 3RT (for example) and the users post code could be CM2 7ZN. My initial thoughts are to store the addresses and post codes of all the CAB's in a table but how do I compare those values and be accurate? The website company I work for have a similar functionality where we display certain things depending on user's post code so it is a fully post code driven site and I know our developer was coding a longitude and latitude script to determine this. Is that the only way to be accurate or would there be an easier solution or even a better one? Kind regards, L2c.
-
Find the first table on your page,just inside the div with a class of 'header_inner' and apply the text-shadow property. Considering your code, you could do this: .header_inner table { text-shadow:1px 1px #ff02ff; } Kind regards, L2c.
-
First thing I see is change this: mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); To this: mysql_connect($host, $username, $password)or die("cannot connect"); mysql_select_db($db_name)or die("cannot select DB"); because you are saving those values into variables, there is no need to put them within quotes. Run a print_r($_POST) statement at the top of the php script and what does it return? Kind regards, L2c.
-
Welcome qqim, Sure, paste your code and we can take a look. Kind regards, L2c.
-
Can you format your code please? Kind regards, L2c.
-
Find the table you want to put rounded borders on, give it a class of let's say 'rounded_borders'. Then in your CSS file put this: .rounded_borders { -moz-border-radius: 10px; border-radius: 10px; } Just checked in FF, IE10, GC, Opera, Safari and works in every one. You may have some issues with earlier versions of IE undoubtedly so you may want to go and explore that a little now you have something to work with. Hope this helps you. Kind regards, L2c.
-
Just a long shot to be honest, but instead of floating your <div> elements left to get your desired result, you can set the #list_container to display any children <div>'s as inline-block elements. This means you will get exactly the same result as before but it could possibly sort your printing problem. I can't get to my printer right now (more like too lazy, it's in the other office) but give this code a try: CSS: #list_container { overflow:hidden; } #list_container > div { display: inline-block } #list_c1 { width:200px; } #list_c2 { width:200px; } #list_c3 { width:200px; } I hope this helps you. Good luck. Kind regards, L2c.
-
Setting up server in Aptana
Love2c0de replied to Love2c0de's topic in Editor Help (PhpStorm, VS Code, etc)
Update: Got it working!