0

I apologize for not knowing how else to do this. I went to add to my other question, and I could not figure out how to append this to it.

I am trying to apply your answer to the previous question in another place.

In this instance I have a bit more going on but thought I could do the same thing as above -with the adjustment of changing id for user_name, since the ids would not match table to table, but the user_name does. I know I am biting off a lot for my first project but I really like this coding stuff. Hope I am not pulling on too many shirt tails. Thanks for your help.

Heres the code. Its placing the same user_name in every row(like the previous question was)

<?php

$Var1 =$_POST['Var1'];

require("connection.php");

mysql_query("UPDATE table1 SET actor = '$Var1'");

$result = mysql_query("SELECT * FROM table2 WHERE subject ='$Var1'");

while($row = mysql_fetch_array($result))
  { $un = $row['user_name'];
     $a =$row['subject'];
     $a_val = $row['subject_val'];

    $sql=mysql_query("UPDATE table3 SET user_name='$un', subject='$', subject_val= $a_val WHERE user_name=".$row['user_name']);     

  }
 mysql_close($connection);
?> 
1
  • Please pay attention to SQL injections. $Var1 is not sanitized! Commented Feb 27, 2011 at 20:10

2 Answers 2

1

This is the last time I answer this kind of question. I'm also adding some optimization.

<?php
var expires = (isset($_POST['var1']) ? $_POST['var1'] : die("no VAR");

require_once("connection.php");

mysql_query("UPDATE table1 SET actor = '$var1'") or die("I cannot run , reason : ".mysql_error());

$result = mysql_query("SELECT * FROM table2 WHERE subject ='$var1'") or die("I cannot run , reason : ".mysql_error());

while($row = mysql_fetch_array($result)) {
    extract($row); // field name as variable , content as value , so be sure that the fields have the right name
    /*
          $user_name = $row['user_name'];
          $subject =$row['subject'];
          $subject_val = $row['subject_val'];
    */
        $sql="UPDATE table3 SET user_name='".$user_name."', subject='".$subject."', subject_val= ".$subject_val." WHERE user_name='".$user_name."'";
    mysql_query($sql) or die("I cannot run , reason : ".mysql_error());

  }
 mysql_close();
?> 
Sign up to request clarification or add additional context in comments.

Comments

0

Changed the key of third table to user_name - then

    $sql="UPDATE table3 SET user_name='".$user_name."', subject='".$subject."', subject_val= ".$subject_val." WHERE user_name='".$un."'";

worked!!

thanks for the help!!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.