PDO Insert helpt

ok, bascly im building an app for my work for android that allows the user to download info about a job they have to go to, fill out details and submit it. but im having trouble getting the updated data back in the database.

here is my table

CREATE TABLE IF NOT EXISTS `job` (
  `jobDetailID` int(11) NOT NULL,
  `JobNo` int(11) NOT NULL,
  `Sequence` int(11) NOT NULL,
  `Initias` varchar(10) NOT NULL,
  `jobDate` date NOT NULL,
  `ClientName` varchar(255) NOT NULL,
  `jobLocation` varchar(255) NOT NULL,
  `jobAddress` varchar(255) NOT NULL,
  `jobSuburb` varchar(255) NOT NULL,
  `jobContact` varchar(255) NOT NULL,
  `jobPhone` varchar(10) NOT NULL,
  `jobMobile` varchar(10) NOT NULL,
  `jobDescription` varchar(255) NOT NULL,
  `trafficyn` tinyint(1) NOT NULL,
  `traffic` varchar(255) NOT NULL,
  `worklayoutyn` tinyint(1) NOT NULL,
  `worklayout` varchar(255) NOT NULL,
  `machyn` tinyint(1) NOT NULL,
  `mach` varchar(255) NOT NULL,
  `fireyn` tinyint(1) NOT NULL,
  `fire` varchar(255) NOT NULL,
  `weldyn` tinyint(1) NOT NULL,
  `weld` varchar(255) NOT NULL,
  `heightsyn` tinyint(1) NOT NULL,
  `heights` varchar(255) NOT NULL,
  `handelingyn` tinyint(1) NOT NULL,
  `hndleing` varchar(255) NOT NULL,
  `elecyn` tinyint(1) NOT NULL,
  `elec` varchar(255) NOT NULL,
  `plantyn` tinyint(1) NOT NULL,
  `plant` varchar(255) NOT NULL,
  `weatheryn` tinyint(1) NOT NULL,
  `weather` varchar(255) NOT NULL,
  `noiseyn` tinyint(1) NOT NULL,
  `noise` varchar(255) NOT NULL,
  `lightingyn` tinyint(1) NOT NULL,
  `lighting` varchar(255) NOT NULL,
  `scafoldyn` tinyint(1) NOT NULL,
  `saftyNetyn` tinyint(1) NOT NULL,
  `handrailyn` tinyint(1) NOT NULL,
  `harnessyn` tinyint(1) NOT NULL,
  `PermitNo` int(11) NOT NULL,
  `jobComplete` tinyint(1) NOT NULL,
  `startTime` decimal(10,0) NOT NULL,
  `endTime` decimal(10,0) NOT NULL,
  `travel` decimal(10,0) NOT NULL,
  `onSite` decimal(10,0) NOT NULL,
  `TotalTime` decimal(10,0) NOT NULL,
  `overTime` decimal(10,0) NOT NULL,
  `worksDescription` longtext NOT NULL,
  `SequenceClose` tinyint(1) NOT NULL,
  `taskOrder` int(11) NOT NULL,
  `clientOrderNo` varchar(255) NOT NULL,
  `appointmentTime` varchar(255) NOT NULL,
  PRIMARY KEY (`jobDetailID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

and here is my PHP

<?php

	//Temp String's
	$tag = 112234;
	$value = <<<EOD
	[\"112234\",\"104104\",\"0\",\"MR\",\"2012-07-09\",\"Service Stream\",\"some building\",\"1 Luck St\",\"Mowbray\",\"me\",\"0363262617\",\"0400557999\",\"Comma, FullStop. Bakcslash\\/ colan: semicolan; dblQoute\\\" Qoute\' openBracket( closeBracket) star* percent% d\",true,\"\",true,\"\",true,\"\",true,\"\",false,\"\",false,\"\",false,\"\",true,\"\",true,\"\",true,\"\",true,\"\",false,\"\",false,true,true,false,\"123456\",true,\"10\",\"11:30\",\".5\",\"1\",\"1.5\",\"0\",\"Works i completed\",true,\"0\",\"1612123456\",\"8am\"]
EOD;
	//$tag = $_POST['tag'];
	//$value = $_POST['value'];
	$value = str_replace('\"', '&&TEMPSTRING&&', $value);
	$value = str_replace('"', '\"', $value);
	$value = str_replace('&&TEMPSTRING&&', '"', $value);	
	$value = substr($value, 2, -1);
	$newValue = explode(",", $value);
	
	
	$host = 'localhost';
	$port = 3306;
	$database = 'JobDispatch';
	$username = 'root';
	$password = '';


	
	print_r($newValue);
	
	echo '<br />';
	
	$newValue[1] = intval($newValue[1]);
	$newValue[2] = intval($newValue[2]);
	$newValue[3] = intval($newValue[3]);
	$newValue[42] = intval($newValue[42]);
	$newValue[52] = intval($newValue[52]);
	
	$sqlString = implode(", ", $newValue);
	try {
		$dsn = "mysql:host=$host;port=$port;dbname=$database";
		$db = new PDO($dsn, $username, $password);
		
		$statement = $db->prepare("DELETE FROM job WHERE jobDetailID = ?");
		$statement->execute(array($tag));
		$statement = $db->prepare('INSERT INTO job VALUES (?)');
		$statement->execute(array($sqlString));
	} catch (PDOException $e) {
    echo 'Connection failed: ' . $e->getMessage();
	};
	echo $sqlString;
?>

eventual it will be called by the app but for now i just have to string the app submits saved to a veriable. i then manipulate the string bit so if fits the database a bit better. but for some reason when i try to insert the data it just doesn’t work and i cant figure out why. any ideas?

Your SQL statement is not correct I don’t know what you want in place of (?) but (?) will not get you any variables that I am aware of so your statement will error when queried.

[php]$statement = $db->prepare(‘INSERT INTO job VALUES (?)’);[/php]

Im only just learning pdo but I was sure the next line sets the ? As $sqlString and executed it. Anyway. the question mark should be $sqlString how would I go about doing that?

Sponsor our Newsletter | Privacy Policy | Terms of Service