Jump to content

Mysql Database Not Inserting

Hopalonghacksaw

So I am having a problem with PHP and inserting into A database. 

 

So here is the Code I have that is supposed to insert into a database 

	public static function createJob($user_id,$value,$files,$local,$shipping,$print,$weld,$cnc,$solder,$laser,$timeframe,$zipcode,$material, $material2,$desc,$start,$end)
    {
        $database = DatabaseFactory::getFactory()->getConnection();

        $sql = "INSERT INTO jobs (createid,3dprint,weld,cnc,solder,laser,files,pay,material,local,zipcode,timeframe,material2,description,startstage,endstage) 
							VALUES(:user_id,:print,:weld,:cnc,:solder,:laser,:files,:pay,:material,:local,:zipcode,:timeframe,:material2,:desc,:start,:end";
        $query = $database->prepare($sql);

        // Insert Data into Rows
        $result = $query->execute(array(
		':user_id' => $user_id,
		':print' =>$print,
		':weld' => $weld,
		':cnc' => $cnc,
		':solder' => $solder,
		':laser' => $laser,
		':files' => $files,
		':pay' => $value,
		':material' =>$material,
		':local' => $local,
		':zipcode' => $zipcode,
		':timeframe' => $timeframe,
		':material2' => $material2,
		':desc' => $desc,
		':start' => $start,
		':end' => $end
		)); 
		//check if function executed properly
		return $result;
    }

So I call This Function and Get Zero Errors. I have Error Reporting On with the Report all Errors set to 1 and I have checked the php logs and mysql logs with no problems. I have checked and the data is being processed and passed through.  I Also get no result when I run the function It Just Doesnt Work for Some Reason Here is the table that I am trying to insert into. 

CREATE TABLE IF NOT EXISTS `jobs` (
  `job_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'auto incrementing user_id of each user, unique index',
  `active` tinyint(1) NOT NULL DEFAULT '0',
  `createid` int(11) NOT NULL,
  `doid` int(11) DEFAULT NULL,
  `3dprint` tinyint(1) NOT NULL DEFAULT '0',
  `weld` tinyint(1) NOT NULL DEFAULT '0',
  `cnc` tinyint(1) NOT NULL DEFAULT '0',
  `solder` tinyint(1) NOT NULL DEFAULT '0',
  `description` varchar(5000) COLLATE utf8_unicode_ci NOT NULL,
  `files` varchar(25) COLLATE utf8_unicode_ci NOT NULL,
  `pay` decimal(8,2) DEFAULT NULL,
  `reviewed` tinyint(1) NOT NULL DEFAULT '0',
  `material` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
  `local` tinyint(1) NOT NULL DEFAULT '0',
  `zipcode` int(6) NOT NULL,
  `timeframe` int(2) NOT NULL DEFAULT '2',
  `shipping` decimal(10,0) NOT NULL DEFAULT '0',
  `material2` varchar(500) COLLATE utf8_unicode_ci NOT NULL,
  `laser` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'New Tool',
  `Cdate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `dodate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `Message` varchar(5000) COLLATE utf8_unicode_ci NOT NULL,
  `startstage` int(5) NOT NULL COMMENT 'What Stage did it start at',
  `endstage` int(5) NOT NULL DEFAULT '1' COMMENT 'What stage will it end at',
  PRIMARY KEY (`job_id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Tasks Table';

Any Help Would Be Appreciated.

Link to comment
Share on other sites

Link to post
Share on other sites

 $sql = "INSERT INTO jobs " .
 "(createid,3dprint,weld,cnc,solder,laser,files,pay,material,local,".
 "zipcode,timeframe,material2,description,startstage,endstage)".
 " VALUES (:user_id,:print,:weld,:cnc,:solder,:laser,:files,:pay,:material,:local,".
 ":zipcode,:timeframe,:material2,:desc,:start,:end)";

I think you're missing a ) at the end, to close the one after VALUES

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

So I just Tried That and I Still Got No change. I really have no clue what was going on. 

Link to comment
Share on other sites

Link to post
Share on other sites

Thanks So much I figured It out. In the row messages I did not set a value and there was no default so that is why it did not insert. I also had a header redirect so it could not display errors. 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×