My head is wrecked at my first attempt at posting to a mysql database.
When i click submit I just get an error message from the "Database.php" script.
I'd be greatful if some one could review my code and see if you and spot any amature mistakes.
All the database names password and usernames are correct so I suspect something wrong in the php code.
Here is my code.
Code:<html> <head><title>DATABASE SUBMIT FORM</title></head> <body> <form method="post" action="Database.php"> Title: <input type="text" name="title" size="30"><br> Description: <input type="text" name="description" size="30"><br> Date: <input type="text" name="date" size="30" value=""><br> Url: <input type="text" name="url" size="35" value="http://www.mywebsitename.com"><br> Photographer: <input type="text" name="photographer" size="30"><br> <input type="Submit" value="Submit to Database"> </form> </body> </html>
I was havng trouble creating a table with phpMyadmin but found this script that done the job for me.Code:<?php $title = $_POST['title']; $description = $_POST['description']; $date = $_POST['date']; $url = $_POST['url']; $photographer = $_POST['photographer']; mysql_connect("www.mysite.com", "u*******1", "5******d") or die(mysql_error()); mysql_select_db ("database name"); $query = "INSERT INTO K4 (title, description, date, url, photographer) VALUES ('NULL','".title."', '".description."', '".date."', '".url."', '".photographer."')"; mysql_query($query) or die ('Error updatng the database'); echo " Database Updated With: ".title. " ".description." ".date." ".url." ".photographer.""; ?>
Code:<?php // Connects to your Database mysql_connect("www.mysite.com", "u*****1", "5*****d") or die(mysql_error()); mysql_select_db("database name") or die(mysql_error()); mysql_query("CREATE TABLE K4 ( ID int NOT NULL AUTO_INCREMENT, PRIMARY KEY(ID), title VARCHAR(30), description VARCHAR(30), date VARCHAR(30), url VARCHAR(30), Photographer VARCHAR(30) )"); Print "Your table has been created"; ?>



Reply With Quote


Bookmarks