Jump to content

blackwolf23

Members
  • Posts

    17
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

blackwolf23's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I tried the following query but I still can't get the UserProfile table to update. $query = "UPDATE UserProfile set Age = '$Age', Dob = '$Dob', Height = '$Height' Weight = '$Weight' WHERE UserID IN (SELECT UserID from Users WHERE Username = '".$Username."')";
  2. Update an existing one but then how do I ensure the correct record in the Profile table is updated? Both tables are linked by the UserID column.
  3. Prints out the following: UPDATE UserProfile set Age = '33', Dob = '33', Height = '33' Weight = '33' UserID = 0 WHERE Users.UserID = UserProfile.UserID
  4. Its called within the main script. <?php require_once('Functions.php'); //Get the post variables $Firstname = $_POST['fname']; $Surname = $_POST['sname']; $Email= $_POST['email']; $Age = $_POST['age']; $Dob = $_POST['dob']; $Height = $_POST['height']; $Weight = $_POST['weight']; //Start the session session_start(); if(!isset($_SESSION['Valid_User'])) { header('Location:Login.php'); } if(isset($_SESSION['Valid_User'])) { echo 'Welcome, '.$_SESSION['Valid_User']. ' <br/>'; } //Update the user's details in the User table register2($_SESSION['Valid_User'],$Firstname,$Surname,$Email); //Update the User's details in the Profile table Update_profile2($Age,$Dob,$Height,$Weight,$userID);
  5. Hello, I'm having difficulty updating two tables that are related by a foreign key. I've written two functions that update the User's profile which is contained in the User and UserProfile tables. The first function works fine and updates the User's details in the User table but the second functiion gives me the error 'Invalid query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Weight = '33' UserID = 0 WHERE Users.UserID = UserProfile.UserID' at line 1 Whole query: UPDATE UserProfile set Age = '33', Dob = '33', Height = '33' Weight = '33' UserID = 0 WHERE Users.UserID = UserProfile.UserID I know it is to do with how I am passing the ".$_SESSION['userID']." to the Update statement but I am not certain on exactly how to do this. Here is my code for both functions: function register2($Username,$Firstname,$Surname,$Email) { $conn = connect(); $query = "UPDATE Users set Firstname = '$Firstname', Surname = '$Surname', Email = '$Email' WHERE Username ='$Username'"; $verify = mysql_query($query); $userID = @mysql_insert_id(); $_SESSION['userID'] = $userID; } function Update_profile2($Age,$Dob,$Height,$Weight,$userID) { $conn = connect(); mysql_insert_id(); $query = "UPDATE UserProfile set Age = '$Age', Dob = '$Dob', Height = '$Height' Weight = '$Weight' UserID = ".$_SESSION['userID']." WHERE Users.UserID = UserProfile.UserID"; $verify = mysql_query($query); }
  6. Silly me,I commented out echo "<<br>Firstname: $Firstname<br>Surname: $Surname<br>Email: $Email<br>Password: $Password<br> <br>Age: $Age<br>";
  7. I did some error checking and fixed a mistake where Profile.Age should be UserProfile.Age which removed the error message from appearing but my View_Profile function displays nothing when I test it by going to the View Profile page. This query works and allows me to display the user's profile $query = "SELECT * FROM Users WHERE Username = '".$Username."'"; but I need to display the User's profile from both the users able and the UserProfile table. $query ="SELECT Users.Firstname,Users.Surname,Users.Email,UserProfile.Age FROM Users,UserProfile WHERE Username = '".$Username."' AND Users.UserID = UserProfile.UserID"; $result = mysql_query($query); $num = mysql_numrows($result); I'm guessing my query is wrong so I will try and work it out.
  8. Hello, I'm having some difficulty formulating query that will allow me to retrieve the details of a specific user in the database. The user's information is stored in one table called Users and another called UserProfile. Both tables are linked by the UserID field. My current query returns a Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource and my knowledge of Mysql is not great(Still learnng) Here is my code: function view_profile($Username) { $conn = connect(); $query ="SELECT Users.Firstname,Users.Surname,Users.Email,Profile.Age FROM Users,UserProfile WHERE Username = '".$Username."' AND Users.UserID = UserProfile.UserID"; $result = mysql_query($query); $num = mysql_numrows($result); mysql_close(); echo "<b><center>Your profile</center></b><br>"; $i=0; while ($i < $num) { $Firstname =mysql_result($result,$i,"Firstname"); $Surname=mysql_result($result,$i,"Surname"); $Email=mysql_result($result,$i,"Email"); $Age=mysql_result($result,$i,"Age"); //echo "<<br>Firstname: $Firstname<br>Surname: $Surname<br>Email: $Email<br>Password: $Password<br> <br>Age: $Age<br>"; $i++; } }
  9. Ok,I might test that to. Thankyou for your help.
  10. Another person suggested I try the following which fixed the problem. $row = mysql_fetch_assoc($result); $to = $row['Email'];
  11. Mail has 3 required parameters from what I have read and I can only get this code to work if I enter an email address in the $To variable. I'm guessing something is wrong with this line $to = '$row->Email';
  12. Thanks for solving my problem but for some reason I still have not recieved an email yet.
  13. Hello, I'm having trouble querying my database for the email address of a specific user and using that email address in the php mail function to send the user their new password. The below code keeps generating the error 'Call to undefined function mysqli_fetch_object() in Functions.php on line 138' WHich I can't seem to figure out why(I am still new to php). function email_passwd($Username,$test) { //Get the email address of the user from the db $conn = connect(); $query = "SELECT Email FROM Users WHERE Username = '".$Username."'"; $result = mysql_query($query); $row = mysqli_fetch_object($query); //Email the user $to = '$row->Email'; $subject = 'Password Reset'; $message = "Your password has been reset to $test"; mail($to, $subject, $message); }
  14. Thankyou for your quick reply which solved my problem.
  15. Hello, I'm having trouble formulating the Sql query I require for inserting additional information about a user into my website. The the user first registers by filling out a form and the form information is inserted into the User table. The user is then redirected to a page called UserProfile where they enter some more information and this should be inserted into the UserProfile table. I'm having trouble figuring out how to write the Insert query in a way that will link the UserProfile information with the User stored in the User table. Here is my current query: mysql_insert_id(); $query = "INSERT into UserProfile (Age,Dob,Height,Weight) values ('".$Age."','".$DOB."', '".$Height."', '".$Weight."')"; WHERE User.UserID = UserProfile.UserID"; $verify = mysql_query($query); This query results in no information being stored in the UserProfile table.The structure of the two tables look like this: User ----------- UserID (PK)(Auto_increment) Firstname Surname Address Email UserProfile ------------- ProfileID(PK) (Auto_Increment) UserID Age Dob Height Weight
×
×
  • 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.