I just created this code to imput data into my userdatabase. Why isn't it working. It just skips past the mysql_query, not entering the data into my database and then refreshes the page to index.html because of the header command. Why isn't it inserting my data? $name, $password, are gotten from an imput form and work perfectly with other parts of my code. $today = (date("m"). "/" . date("d") . "/" . date("Y")); mysql_select_db("userdatabase"); //input data mysql_query("INSERT INTO usertable (name, pwd, datejoined) VALUES ('$name', '$password', '$today')"); header("Location: http://www.example.com/index.html"); Thanks in advance! ~imozeb
You might want to see if there is a MySQL error getting spit out by temporarily removing the header() line. Most likely, it's the column name "name" which is a reserved word in MySQL. It's like calling a table "table". So, use `name` (backtick quotes) instead of just name and MySQL will understand. In fact, it's good to get in the habit of using backticks on all your tables and column names when you do a query.
Okay, I put backticks on my column names in the insert into part and deleted the header to see if there was an error message and it still does not work! There was no error message by the way. Please help.
Make sure you have error reporting set to E_ALL and display_errors set to On. You should store the SQL query as a string and display it. Copy-and-paste that query and try it in mysql console or phpMyAdmin directly; eliminate PHP from being the culprit. Also, check the return value of mysql_query() as it may be telling you something.