My code does not produce any error messages. I have 3 files: share.html where the user inputs data into a simple html form, insert.php which says Thank you, $Name then has the code that is supposed to insert the user's input into the database, favorites.php which uses a while loop to display the data from the database. After being thanked the user clicks a link going to favorites.php. The display works fine and will display data I input in PHPMyAdmin. Also I checked and if I put an invalid database name in insert.php it produces the string I wrote for or die. Also input from the form does appear on the insert.php page if I just use REQUEST but that's as far as it goes. Buteven though the correct database name produces no error the input from the html form is not inserted into the database and does not appear on the display page.
Make sure you are connecting to the database,then just before you call your sql to insert use an echo statement to display the sql and check it for syntax:-
$sql = 'insert into table1 values('.$no.','.$no.',"block","'.$value3.'", "'.$value4.'")';
echo "SQL ==>" STARTOFSQL<br>".$sql." ENDOFSQL<br>";
I always use single quotes around the outside and double quotes around each field string, so try this
$query='INSERT INTO Main VALUES ("", "'.$Namefield.'","'.$Classfield.'","'.$Whyfield."')';
I enclose each field around a pair of double quotes so if $Namefield has a value red it changes to "red" in the insert statement,
so each '". is a double quote, single quote, then fullstop
and ."' is a fullstop, single quote, double quote
years of unix coding makes understanding quotes essential
let me know if you understand, ta HPC
Is the database MySQL ?
×
1,460 views
Usually answered in minutes!
Greetings,
Thanks for your response. I think we may be closer to a solution but I still need help on how to get there. This is the error message produced after I added the code you provided:
Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/river/public_html/conraise/insert.php on line 17
and this is the line it is referring to:
16 $query="INSERT INTO Main VALUES
17 ('', '$Namefield','$Classfield','$Whyfield')";
18 echo "SQL ==>" STARTOFSQL
".$query." ENDOFSQL
";
19 mysql_query ($query);
For the life of me I do not see why or where it would be expecting a comma or seni colon there.
I tried it but it didn't make the code pass the info to the database. Thanks
×