How to use the right join for update query?

i have done the query for the select but i do not know how to use the right join for the query update. i have this code right now, but it is wrong.

    $sql = "UPDATE person SET ExamineeID = '$_POST[ExamineeID]', FirstName = '$_POST[FirstName]', MiddleName = '$_POST[MiddleName]', LastName = '$_POST[LastName]', Age = '$_POST[Age]', HomeAddress = '$_POST[HomeAddress]', ContactNumber = '$_POST[ContactNumber]', LastSchoolAttended = '$_POST[LastSchoolAttended]', Strand = '$_POST[Strand]', SchoolAddress = '$_POST[SchoolAddress]', Adviser = '$_POST[Adviser]', Honor1 = '$_POST[Honor1]', Honor2 = '$_POST[Honor2]', Honor3 = '$_POST[Honor3]', Honor4 = '$_POST[Honor4]', Father = '$_POST[Father]', EducationalFather = '$_POST[EducationalFather]', Mother = '$_POST[Mother]', EducationalMother = '$_POST[EducationalMother]', Guardian = '$_POST[Guardian]', Occupation = '$_POST[Occupation]', Score = '$_POST[Score]' , Rank = '$_POST[Rank]', ExamTime = '$_POST[ExamTime]' WHERE ExamineeID = $_POST[ExamineeID]'";` 

i do not know how to insert the right join and the right syntax but i just post the code here. i want to connect the personal and the score. the start of the score is, score.Score, to score.ExamTime.

prepared statements!

The data design is bad, look at database normalization.

Why do you need a join for an update to begin with?

i am just a beginner though so i am not that familiar with the normalization. also, i need an update right join because of my other table which is the score, it is not updating at all. i have my recent code and try this, but the id is still not updating:
"UPDATE personal SET ExamineeID = '$_POST[ExamineeID]', FROM personal RIGHT JOIN score ON personal.ExamineeID = score.ExamineeID WHERE ExamineeID = $_POST[ExamineeID]'";

I think you might have more luck with this question if you describe your problem more fully. It’s tricky to understand what you’re trying to do from one SQL statement.

I have a problem with updating the tables. But I need to use the Right Join because I have two tables to connect. My first table is the personal, and the next table is the score. I’ve done the right join for the select query but I do not know how to use it for the Update Query.

Based on the query, I don’t see why you need the join at all or what you expect to update. Think about the logic you are using,

join personal and score on examinee id
and update the examinee id where the examinee id is the examinee id

Not only are there errors in the syntax for the query itself, but your where clause is also ambiguous.

I just copied the tutorial from youtube though because I dont have knowledge with the php :frowning: I tried not using join but it kept on saying that the data is not updating so that I came up with the Idea that I need to use join too, same for my select query.

Do you understand what I am saying though?

Think of it like this,

Update member Set username = ’ cthlnlmd’ WHERE username = ’ cthlnlmd’

Do you see an issue with that?

it doesn’t update anything though, i mean that what i see on your example :fearful:

So what are you trying to update and to what?

I need it for admin page so they can edit some typographical errors in it. I fetched the data on my database and store them on the inputs, so yea, so they can edit

Okay, so what fields can they update? To allow the update you need to reference the primary key for the record. But, most likely this should be a single record that gets updated and should not span tables.

I have a plan to included all of it though, including the score because I thought of the admin that they can access everything XD

They don’t need to access everything from the same place. If you look at OOP and the MVC, you are declaring the models. A model is a specific record from a table, not everything related to anything that record relates to.

So, maybe I will include all except for the scores because it is their basic information.

Sponsor our Newsletter | Privacy Policy | Terms of Service