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
https://forums.phpfreaks.com/topic/196082-what-is-wrong-with-this-code/
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());

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.