Jump to content

MySql Update problem


blackwolf23

Recommended Posts

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);


  

}

Link to comment
https://forums.phpfreaks.com/topic/54537-mysql-update-problem/
Share on other sites

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);

Link to comment
https://forums.phpfreaks.com/topic/54537-mysql-update-problem/#findComment-269764
Share on other sites

What does this produce?

 

<?php

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";

  die($query);
  $verify = mysql_query($query);

}

Link to comment
https://forums.phpfreaks.com/topic/54537-mysql-update-problem/#findComment-269767
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.