HTMl to PHP to MySQL problem
Posted: Sun Sep 06, 2009 2:56 pm
Can someone please help. I am a PHP / MySQL newbie trying to develop a free ads site for my local community. After going round in circles for three weeks I decided to ask for help. First I created a MySQL database and defined a table with seven columns (seven variables). This works fine. Then I created an HTML form to collect values for six of these variables. This works fine. The HTML form posts (method post) the data to a PHP page (insert.php) which inserts the data into the table. This works fine. Then I created a PHP page to read all the ads. This works fine.
The fun started when I tried to make use of the seventh variable. This is not input by the user. Rather it is an integer created automatically called “whenadposted”. I have written a PHP version and a JavaScript version. Both codes work fine and print the correct values for “whenadposted” to the screen. What I can’t seem to do is send the value of this variable to the seventh column of the table. I don’t think it’s a syntax problem but a logic problem. I have tried calculating “whenadposted” using JavaScript in the HTML form, and posting it using input TYPE="hidden" but to do this I have to go out of JavaScript so HTML has no knowledge of the variable. Maybe I can export this value to HTML somehow?
I have also tried calculating “whenadposted” using PHP in the insert.php page, then sending it to the table with all the others.
$sql="INSERT INTO allads (FirstName, LastName , category, AdText, URL, emailtoapearinad, whenadposted)
VALUES
('$_POST[FirstName]','$_POST[LastName]','$_POST[category]','$_POST[AdText]','$_POST[URL]','$_POST[emailtoapearinad]','$_POST[whenadposted]')";
Either way, when I run the ReadAllAds.php page it returns zero for this variable.
Can someone please suggest where I may be going wrong.Thanks.
The fun started when I tried to make use of the seventh variable. This is not input by the user. Rather it is an integer created automatically called “whenadposted”. I have written a PHP version and a JavaScript version. Both codes work fine and print the correct values for “whenadposted” to the screen. What I can’t seem to do is send the value of this variable to the seventh column of the table. I don’t think it’s a syntax problem but a logic problem. I have tried calculating “whenadposted” using JavaScript in the HTML form, and posting it using input TYPE="hidden" but to do this I have to go out of JavaScript so HTML has no knowledge of the variable. Maybe I can export this value to HTML somehow?
I have also tried calculating “whenadposted” using PHP in the insert.php page, then sending it to the table with all the others.
$sql="INSERT INTO allads (FirstName, LastName , category, AdText, URL, emailtoapearinad, whenadposted)
VALUES
('$_POST[FirstName]','$_POST[LastName]','$_POST[category]','$_POST[AdText]','$_POST[URL]','$_POST[emailtoapearinad]','$_POST[whenadposted]')";
Either way, when I run the ReadAllAds.php page it returns zero for this variable.
Can someone please suggest where I may be going wrong.Thanks.