By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,637 Members | 2,825 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,637 IT Pros & Developers. It's quick & easy.

update mysql database with lots of varabiles in the query

tolkienarda
100+
P: 316
i need to update a database table using variables in unusual places here are the update statements
Expand|Select|Wrap|Line Numbers
  1. mysql_query("UPDATE 'grades' SET '$class' = '$grade' WHERE student='$student'");
  2. mysql_query("UPDATE 'assignments' SET '$class' = '$grade' WHERE student='$student'");
  3. mysql_query("UPDATE 'comments' SET '$class' = '$grade' WHERE student='$student'");
  4.  
now i was just showed by ron how to recive post stuff and that is where the variables come from so i am not even sure if i am getting the variables from the other page. i did try to display all of those variables but with my php skills the echo options might have their own problems so here is the rest of the code

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  5. <title>Untitled Document</title>
  6. <?
  7.  
  8. session_start(); // Use session variable on this page. This function must put on the top of page.
  9. if(!session_is_registered("teacher")){ // if session variable "username" does not exist.
  10. header("location:login.php"); // Re-direct to index.php
  11. }
  12.  
  13. ?>
  14. <?
  15. // Connect database.
  16. $host="localhost"; // Host name.
  17. $db_user="rcadmin"; // MySQL username.
  18. $db_password="nsds2004"; // MySQL password.
  19. $database="RCA"; // Database name.
  20. $RCA = mysql_pconnect($host, $db_user, $db_password) or trigger_error(mysql_error(),E_USER_ERROR);
  21.  mysql_select_db($database, $RCA);
  22.  $login=$_POST('login');
  23.  $class=$_POST('job_select');
  24.  $grade=$_POST('job_select');
  25.  $assignment=$_POST('job_select');
  26.  $comments=$_POST('job_select');
  27. //this section updates the database
  28. $grade = "grade";
  29. $assignments = "assignments";
  30. $comments = "comments";
  31. $student = "student";
  32. $class = "class";
  33. if (isset($_POST['grade']))
  34.   $grade = strip_tags($_POST['grade']);
  35. if (isset($_POST['assigments']))
  36.   $assignments = strip_tags($_POST['assignments']);
  37. if (isset($_POST['comments']))
  38.   $comments = strip_tags($_POST['comments']);
  39. if (isset($_POST['student']))
  40.   $student = strip_tags($_POST['student']);
  41. if (isset($_POST['classs']))
  42.   $class = strip_tags($_POST['classs']);
  43.  
  44.  
  45. mysql_query("UPDATE 'grades' SET $class = '$grade' WHERE student='$student'");
  46. mysql_query("UPDATE assignments SET '$class' = '$grade' WHERE student='$student'");
  47. mysql_query("UPDATE comments SET $class = '$grade' WHERE student='$student'");
  48. ?>
  49.  </head>
  50.  
  51. <body>
  52. <?
  53.     echo $grade, "<br />";
  54.     echo $assignments , "<br />";
  55.     echo $comments , "<br />";
  56.     echo $student , "<br />";
  57.     echo $class , "<br />";
  58.  
  59. ?>
  60. </body>
  61. </html>
  62.  
Jan 17 '07 #1
Share this Question
Share on Google+
1 Reply


tolkienarda
100+
P: 316
never mind i am stupid
Jan 18 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.