toxictoad Posted November 11, 2008 Share Posted November 11, 2008 HI all, I've gone through an online tutorial to develop a php/html page to enter data into my db and I've tried to adapt it to my database but I've ran into problems. My database just has the one table db name: phatjoin_mymovies table name: mymovies Fields: title | genre | year | stars | country | link | director | plot | image | trailer | rating the tutorial suggests using 2 php pages and this is what I have form.php <html> <head> <title>update database</title> </head> <body> <form method="post" action="update.php"> Title: <input type="text" name="title" size="70" /><br /> Genre: <input type="text" name="genre" size="30" /><br /> Year: <input type="text" name="year" size="20" /><br /> Stars: <input type="text" name="stars" size="20" /><br /> Country: <input type="text" name="country" size="30" /><br /> Link: <input type="text" name="link" size="60" /><br /> Director: <input type="text" name="director" size="40" /><br /> Plot: <input type="text" name="plot" size="80" /><br /> Image: <input type="text" name="image" size="30" /><br /> Trailer: <input type="text" name="trailer" size="30" /><br /> Rating: <input type="text" name="rating" size="30" /><br /> <input type="submit" value="Update Database" /><br /> </body> </html> update.php <?php $title = $_POST['title']; $genre = $_POST['genre']; $year = $_POST['year']; $stars = $_POST['stars']; $country = $_POST['country']; $link = $_POST['link']; $director = $_POST['director']; $plot = $_POST['plot']; $image = $_POST['image']; $trailer = $_POST['trailer']; $rating = $_POST['rating']; mysql_connect ("localhost", "USERNAME", "PASSWORD") or die ('error: ' .mysql_error()); mysql_select_db ("phatjoin_mymovies"); $query="INSERT INTO mymovies (filmID, title, genre, year, stars, country, link, director, plot, image, trailer, rating) VALUES ('NULL','".$title."', '"$genre."', '"$year."', '"$stars."', '"$country."', '"$link."', '"$director."', '"$plot."', '"$image."', '"$trailer."', '"rating."')"; mysql_query($query) or die ('Error updating database'); echo "Database Updated" ; ?> When I enter all the data into the form and hit submit I get directed to the update.php form and it's blank? Any ideas where I've gone wrong? Thanks Link to comment https://forums.phpfreaks.com/topic/132318-solved-adding-information-into-database-from-html-form/ Share on other sites More sharing options...
flyhoney Posted November 11, 2008 Share Posted November 11, 2008 Add this at the top of your code to get PHP error reporting: error_reporting(E_ALL); ini_set("display_errors", 1); Link to comment https://forums.phpfreaks.com/topic/132318-solved-adding-information-into-database-from-html-form/#findComment-687910 Share on other sites More sharing options...
rhodesa Posted November 11, 2008 Share Posted November 11, 2008 definitely turn on error reporting...but one thing I did notice is that NULL in your SQL statement shouldn't have single quotes around it. $query="INSERT INTO mymovies (filmID, title, genre, year, stars, country, link, director, plot, image, trailer, rating) VALUES ('NULL','".$title."', '"$genre."', '"$year."', '"$stars."', '"$country."', '"$link."', '"$director."', '"$plot."', '"$image."', '"$trailer."', '"rating."')"; Link to comment https://forums.phpfreaks.com/topic/132318-solved-adding-information-into-database-from-html-form/#findComment-687912 Share on other sites More sharing options...
bobbinsbro Posted November 11, 2008 Share Posted November 11, 2008 this: $query="INSERT INTO mymovies (filmID, title, genre, year, stars, country, link, director, plot, image, trailer, rating) VALUES ('NULL','".$title."', '"$genre."', '"$year."', '"$stars."', '"$country."', '"$link."', '"$director."', '"$plot."', '"$image."', '"$trailer."', '"rating."')"; should be this: $query="INSERT INTO mymovies (title, genre, year, stars, country, link, director, plot, image, trailer, rating) VALUES ('".$title."', '".$genre."', '".$year."', '".$stars."', '".$country."', '".$link."', '".$director."', '".$plot."', '".$image."', '".$trailer."', '".$rating."')"; you were missing a ***t load of periods (.) to successfully concatenate variables to the sql string, and $rating was missing the dollar sign. i also assume that filmID auto-increments, since you try to set it to null, which is either a waste of space or an error, so i got rid of that too. Link to comment https://forums.phpfreaks.com/topic/132318-solved-adding-information-into-database-from-html-form/#findComment-687916 Share on other sites More sharing options...
toxictoad Posted November 11, 2008 Author Share Posted November 11, 2008 this: $query="INSERT INTO mymovies (filmID, title, genre, year, stars, country, link, director, plot, image, trailer, rating) VALUES ('NULL','".$title."', '"$genre."', '"$year."', '"$stars."', '"$country."', '"$link."', '"$director."', '"$plot."', '"$image."', '"$trailer."', '"rating."')"; should be this: $query="INSERT INTO mymovies (title, genre, year, stars, country, link, director, plot, image, trailer, rating) VALUES ('".$title."', '".$genre."', '".$year."', '".$stars."', '".$country."', '".$link."', '".$director."', '".$plot."', '".$image."', '".$trailer."', '".$rating."')"; you were missing a ***t load of periods (.) to successfully concatenate variables to the sql string, and $rating was missing the dollar sign. i also assume that filmID auto-increments, since you try to set it to null, which is either a waste of space or an error, so i got rid of that too. Thank you works great, I'll have to be a lot more careful in coding (guess it comes with exerience) Link to comment https://forums.phpfreaks.com/topic/132318-solved-adding-information-into-database-from-html-form/#findComment-687922 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.