Inserting the actual string $variable into the db
Moderator: General Moderators
-
fariquzeli
- Forum Contributor
- Posts: 144
- Joined: Mon Jun 24, 2002 9:16 am
- Location: Chicago
- Contact:
Inserting the actual string $variable into the db
I have some php that is supposed to add in numbers into a db that were added into a form field on a previous page. The problem is that the form is entering the actual variable names as strings into the db
ex. The field's name is $1_spring, rather than entering the number 7 that was put into that field, it puts in $1_spring. here is the code:
їcode]$sql2="INSERT INTO curriculum SET
polishing_philosophy = '$polishing_philosophy',
teaching_year = '$teaching_year',
teaching_year_semester = '$teaching_year_semester',
polishing_procedure = '$polishing_procedure',
ergonomics_taught= '$ergonomics_taught',
seperate_course = '$seperate_course',
hours_received = '$hours_received',
teaching_importance = '$teaching_importance',
prepared_module = '$prepared_module',
1_fall = '$1_fall',
2_fall = '$2_fall',
3_fall = '$3_fall',
4_fall = '$4_fall',
1_fall2 = '$1_fall2',
2_fall2 = '$2_fall2',
3_fall2 = '$3_fall2',
4_fall2 = '$4_fall2',
1_spring = '$1_spring',
2_spring = '$2_spring',
3_spring = '$3_spring',
4_spring = '$4_spring',
1_spring2 = '$1_spring2',
2_spring2 = '$2_spring2',
3_spring2 = '$3_spring2',
4_spring2 = '$4_spring2',
1_summer = '$1_summer',
2_summer = '$2_summer',
3_summer = '$3_summer',
4_summer = '$4_summer',
1_summer2 = '$1_summer2',
2_summer2 = '$2_summer2',
3_summer2 = '$3_summer2',
4_summer2 = '$4_summer2',
teaching_year2 = '$teaching_year2',
teaching_year_semester2 = '$teaching_year_semester2',
hours_ergonomics_module = '$hours_ergonomics_module'";ї/code]
all of the fields with the odd numbers for names are inputting the $string into the db rather than the number, all the normally named fields are entering info fine.
ex. The field's name is $1_spring, rather than entering the number 7 that was put into that field, it puts in $1_spring. here is the code:
їcode]$sql2="INSERT INTO curriculum SET
polishing_philosophy = '$polishing_philosophy',
teaching_year = '$teaching_year',
teaching_year_semester = '$teaching_year_semester',
polishing_procedure = '$polishing_procedure',
ergonomics_taught= '$ergonomics_taught',
seperate_course = '$seperate_course',
hours_received = '$hours_received',
teaching_importance = '$teaching_importance',
prepared_module = '$prepared_module',
1_fall = '$1_fall',
2_fall = '$2_fall',
3_fall = '$3_fall',
4_fall = '$4_fall',
1_fall2 = '$1_fall2',
2_fall2 = '$2_fall2',
3_fall2 = '$3_fall2',
4_fall2 = '$4_fall2',
1_spring = '$1_spring',
2_spring = '$2_spring',
3_spring = '$3_spring',
4_spring = '$4_spring',
1_spring2 = '$1_spring2',
2_spring2 = '$2_spring2',
3_spring2 = '$3_spring2',
4_spring2 = '$4_spring2',
1_summer = '$1_summer',
2_summer = '$2_summer',
3_summer = '$3_summer',
4_summer = '$4_summer',
1_summer2 = '$1_summer2',
2_summer2 = '$2_summer2',
3_summer2 = '$3_summer2',
4_summer2 = '$4_summer2',
teaching_year2 = '$teaching_year2',
teaching_year_semester2 = '$teaching_year_semester2',
hours_ergonomics_module = '$hours_ergonomics_module'";ї/code]
all of the fields with the odd numbers for names are inputting the $string into the db rather than the number, all the normally named fields are entering info fine.
-
chris12295
- Forum Contributor
- Posts: 113
- Joined: Sun Jun 09, 2002 10:28 pm
- Location: USA
- Contact:
-
fariquzeli
- Forum Contributor
- Posts: 144
- Joined: Mon Jun 24, 2002 9:16 am
- Location: Chicago
- Contact:
-
chris12295
- Forum Contributor
- Posts: 113
- Joined: Sun Jun 09, 2002 10:28 pm
- Location: USA
- Contact:
in MYSQL the syntax for inserting that seems to work for me is
I have never tried it your way, just give my syntax a try and tell me if that works.
Code: Select all
$sql2 = "INSERT into table (field1, filed2, field3) VALUES('$value1', '$value2', '$value3')";-
fariquzeli
- Forum Contributor
- Posts: 144
- Joined: Mon Jun 24, 2002 9:16 am
- Location: Chicago
- Contact:
- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
ok the way you're doing it is:
$statement = "thing 'thing'";
so if i were to do:
echo $statement;
it would produce: thing 'thing'
and i assume you're trying to do like mysql_query($sql2);
and in PHP a variable will only be treated as a variable in a string if it is enclosed in double quotes.
so try:
it SHOULD work
$statement = "thing 'thing'";
so if i were to do:
echo $statement;
it would produce: thing 'thing'
and i assume you're trying to do like mysql_query($sql2);
and in PHP a variable will only be treated as a variable in a string if it is enclosed in double quotes.
so try:
Code: Select all
$sql2=""INSERT INTO curriculum SET
polishing_philosophy = '$polishing_philosophy',
teaching_year = '$teaching_year',
teaching_year_semester = '$teaching_year_semester',
polishing_procedure = '$polishing_procedure',
ergonomics_taught= '$ergonomics_taught',
seperate_course = '$seperate_course',
hours_received = '$hours_received',
teaching_importance = '$teaching_importance',
prepared_module = '$prepared_module',
1_fall = '$1_fall',
2_fall = '$2_fall',
3_fall = '$3_fall',
4_fall = '$4_fall',
1_fall2 = '$1_fall2',
2_fall2 = '$2_fall2',
3_fall2 = '$3_fall2',
4_fall2 = '$4_fall2',
1_spring = '$1_spring',
2_spring = '$2_spring',
3_spring = '$3_spring',
4_spring = '$4_spring',
1_spring2 = '$1_spring2',
2_spring2 = '$2_spring2',
3_spring2 = '$3_spring2',
4_spring2 = '$4_spring2',
1_summer = '$1_summer',
2_summer = '$2_summer',
3_summer = '$3_summer',
4_summer = '$4_summer',
1_summer2 = '$1_summer2',
2_summer2 = '$2_summer2',
3_summer2 = '$3_summer2',
4_summer2 = '$4_summer2',
teaching_year2 = '$teaching_year2',
teaching_year_semester2 = '$teaching_year_semester2',
hours_ergonomics_module = '$hours_ergonomics_module'"";-
chris12295
- Forum Contributor
- Posts: 113
- Joined: Sun Jun 09, 2002 10:28 pm
- Location: USA
- Contact:
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
-
fariquzeli
- Forum Contributor
- Posts: 144
- Joined: Mon Jun 24, 2002 9:16 am
- Location: Chicago
- Contact:
-
chris12295
- Forum Contributor
- Posts: 113
- Joined: Sun Jun 09, 2002 10:28 pm
- Location: USA
- Contact:
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
-
fariquzeli
- Forum Contributor
- Posts: 144
- Joined: Mon Jun 24, 2002 9:16 am
- Location: Chicago
- Contact:
-
fariquzeli
- Forum Contributor
- Posts: 144
- Joined: Mon Jun 24, 2002 9:16 am
- Location: Chicago
- Contact: