Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Nov 2009
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    MySQL Error while trying to insert into database

    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.

    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 | &copy;  Copyright George Bates 2009 | All Rights Reserved</p>
    </body>
    </html>
    <?php
    // close the connection
    mysql_close($connectID);
    ?>

  • #2
    Regular Coder seco's Avatar
    Join Date
    Nov 2008
    Location
    Oregon
    Posts
    687
    Thanks
    6
    Thanked 79 Times in 77 Posts
    remove the ( ) from

    and rename $namen to price

    PHP Code:
        $name=($_POST['name']);
        
    $namen=($_POST['price']);
        
    $thumb_url=($_POST['thumb_url']);    
        
    $big_url=($_POST['big_url']); 

  • Users who have thanked seco for this post:

    georgebates (03-21-2010)

  • #3
    New to the CF scene
    Join Date
    Nov 2009
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks for that. Sorry but what do you mean "remove the ( ) from". Where from?

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Remove the parentheses around the post values. Also I suggest you do some research on mysql injection.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #5
    New to the CF scene
    Join Date
    Nov 2009
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    i just did that, changed it to

    PHP Code:
            $name=$_POST['name'];
        
    $price=$_POST['price'];
        
    $thumb_url=$_POST['thumb_url'];    
        
    $big_url=$_POST['big_url']; 
    yet it still comes up with same error!

  • #6
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Change this
    PHP Code:
    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"
    to this
    PHP Code:
    $sql "INSERT into art_glass (name, price, thumb_url, big_url) VALUES ('$name', '$price', '$thumb_url', '$big_url')";
    $result mysql_query ($sql$connectID)
      or die (
    "Mysql Error:".mysql_error()."<br>SQL:".$sql
    Copy and paste the results here. This should give you a better idea of why its failing.
    ||||If you are getting paid to do a job, don't ask for help on it!||||


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •