Page 1 of 1

Question about passing vars to a form

Posted: Fri Feb 10, 2006 4:59 pm
by a94060
I have made a form,that i would like to pass 4 vars to another form that will take the values and input them into a database. I had done this once sometime after reading a tutorial,but now it does not seem to be working.i hav also checked to make sure that the action page is getting the correct names from the forms.
in the form,i hav 4 variables,if u need me to post this,i can.
name,id,course,grade

this is my php page so far:

Code: Select all

//gets all the vars to us
  
  $name = $_REQUEST['name'];
  $id = $_REQUEST['id'];
  $course = $_REQUEST['course'];
  $grade = $_REQUEST['grade'];
  $sql = 'INSERT INTO `teacher` (`Name`, `Course_id`, `Course_name`, `Grade`) VALUES ('$name', '$id', '$course', '$grade')';
  include "../include/teachers.inc";//includes my db connections
  
  //puts everything into the DB
  
  
  $result = mysql_query ($sql) or die('Query failed: ' . mysql_error());
  $affect = mysql_affected_rows();*/
  
//when i tried to echo the vars,nothing came up,this is wat i tried

  print "$name";
  echo ($id);
  echo ($course);
  echo ($grade);
can any1 tell me what i am doin wrong?

Posted: Fri Feb 10, 2006 5:15 pm
by feyd
your $sql string has changed from a double quote string to a single quote string thus breaking the inline strings you were passing to MySQL.

Posted: Fri Feb 10, 2006 6:07 pm
by a94060
would you be able to repost that edited part for me? i dont seem to understand wat u mean. Jus repost the $sql part?

Posted: Fri Feb 10, 2006 6:27 pm
by LiveFree

Code: Select all

$sql = "INSERT INTO `teacher` (`Name`, `Course_id`, `Course_name`, `Grade`) VALUES ('$name', '$id', '$course', '$grade')";
You were gonna get a parse error because you didnt escape the ''s

Posted: Fri Feb 10, 2006 6:38 pm
by a94060
edit-i jus understood wat the guy said about the quotes:)



all rite man,thanks for the help on that. By the way,im going to be using this script in order to make a homework site for my skool. My plan is to hav one table to hold the teachers and 1 to hold all the assigenments. i will use the teachers thing to hold all the teachers so that i can generate a dynamic option box so pp lcana dd assigenments to the DB easily. Hopefully once i get this basic thing rollled out,i will probably post a question about making a dynamic option box.

Posted: Fri Feb 10, 2006 8:25 pm
by LiveFree
No Problem man

But my school's got powerschool and powergrade for that :D

Posted: Fri Feb 10, 2006 8:58 pm
by a94060
ok,well are those free? the key i nthis 1 is that students will help 1 another.