Question about passing vars to a form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Question about passing vars to a form

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Post 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?
LiveFree
Forum Contributor
Posts: 258
Joined: Tue Dec 06, 2005 5:34 pm
Location: W-Town

Post 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
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Post 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.
LiveFree
Forum Contributor
Posts: 258
Joined: Tue Dec 06, 2005 5:34 pm
Location: W-Town

Post by LiveFree »

No Problem man

But my school's got powerschool and powergrade for that :D
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Post by a94060 »

ok,well are those free? the key i nthis 1 is that students will help 1 another.
Post Reply