Jump to content

What is wrong with this code!!


georgebates

Recommended Posts

Hi There,

 

I've written this same sort of code many times and I've never had any problems and now It just throws me the error "Unable to insert record into database". Please help me!!

 

Heres the code

<?php
$hostUrl = '*****';
$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'];
$price=$_POST['price'];
$thumb_url=$_POST['thumb_url'];	
$big_url=$_POST['big_url'];

if (($_POST['submitted'])) {
// 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
}

?>

 

Link to comment
Share on other sites

So, check the actual error and/or check the query. I always advise against building the query directly inside the mysql_query() command. Build the query as a string variable so you can echo it to the page if needed:

 

$query = "INSERT into art_glass (name, price, thumb_url, big_url)
          VALUES ('$name', '$price', '$thumb_url', '$big_url')"

mysql_query ($query, $connectID)  or die ("Query:<br />$query<br />Error:<br />".mysql_error());

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.