georgebates Posted March 21, 2010 Share Posted March 21, 2010 Hi There, I am trying to get this code working and have sat here for hours trying to figure out whats wrong. Every time I try to add to a mysql database with this is just returns the error "Unable to insert record into database". I can't figure out whats wrong with it. Here's the code. <?php /************************************************* * Micro Upload * * Version: 0.1 * Date: 2006-10-27 * * Usage: * Set the uploadLocation variable to the directory * where you want to store the uploaded files. * Use the version which is relevenat to your server OS. * ****************************************************/ //Windows way //$uploadLocation = "c:\\"; //Unix, Linux way $uploadLocation = "/var/www/html/galleryadmin/upload/"; ?> <?php $hostUrl = 'l*****'; $userName = '*****'; $password = '******'; // connect to database $connectID = mysql_connect($hostUrl, $userName, $password) or die ("Sorry, can't connect to database"); //select the database to read from mysql_select_db("majubagallery_-_data", $connectID) or die ("Unable to select database"); $name=($_POST['name']); $namen=($_POST['price']); $thumb_url=($_POST['thumb_url']); $big_url=($_POST['big_url']); if (($_POST['submitted']) && (!$_GET['modify_id'])) { // the user has submitted a new listing //write to database mysql_query ("INSERT into art_glass (name, price, thumb_url, big_url) VALUES ('$name', '$price', '$thumb_url', '$big_url')", $connectID) or die ("Unable to insert record into database"); if ($success) { print "Record Successfully Added"; header ('Location: microUpload.php'); } } else { // The user has loaded the page to enter a new listing // do nothing - just let the page load } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Edit links</title> <style type="text/css"> body {font-family:verdana, arial, sans-serif; font-size:80%} h2 {font-size:1.4em; } h3 {padding:10px 0 0 0; margin:0;} label {display:block; margin:8px 0 2px 0;} a {display:block; color:#066; margin:3px 0 10px;} a:hover {color:#000; text-decoration:none;} input[type="submit"] {display:block; margin-top:8px;} </style> </head> <body> <h2><img src="http://www.majubagallery.co.nz/images/header.jpg" alt="" width="790" height="228" /></h2> <h2>Add an Art Glass Piece</h2> <a href="main.php">Back</a> <form method="post" action="<?php $_SERVER['PHP_SELF'] ?>"> <!--topic_name--> <p>Name</p> <p> <input name="name" type="text" size="30" id="name" /> <!--topic_description--> </p> <p>Price</p> <p> <input name="price" /> <!--topic_url--> </p> <p> <a href="microUpload.php" target="_blank">Upload Photos </a></p> <p>Thumbnail Image Filename</p> <p> <input name="thumb_url" type="text" size="30" id="topic_url" /> </p> <p>Large Image Filename </p> <input name="big_url" type="text" size="30" id="pic_big" /> <p> <input type="submit" value="Submit" name="submitted" /> </p> </form> </form> <p>Administration and Content Management Script | © Copyright George Bates 2009 | All Rights Reserved</p> </body> </html> <?php // close the connection mysql_close($connectID); ?> Quote Link to comment Share on other sites More sharing options...
trq Posted March 21, 2010 Share Posted March 21, 2010 Try changing.... or die ("Unable to insert record into database"); to.... or die (mysql_error()); so you can at least get feedback on what the problem might actually be. You should then also probably investigate using trigger_error in place of or die as or die is a poor method of debugging. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.