bulrush Posted May 6, 2010 Share Posted May 6, 2010 I'm getting an error when I try to execute an insert like this: INSERT INTO hproduct (Pnumber, Description, Price, height, depth, width) VALUES ('VZFF-3418-NN??N?', '', 148, '34\', '', '18\' ); Are my question marks in the first field a problem? The first field (Pnumber) is varchar(20). Price is a float SQL type. If not, what is the problem? Thanks. Link to comment https://forums.phpfreaks.com/topic/200926-error-on-insert/ Share on other sites More sharing options...
Maq Posted May 6, 2010 Share Posted May 6, 2010 I'm getting an error when I try to execute an insert like this: and that would be...? Link to comment https://forums.phpfreaks.com/topic/200926-error-on-insert/#findComment-1054251 Share on other sites More sharing options...
siric Posted May 6, 2010 Share Posted May 6, 2010 If you intend to add the slash \ after the 34 and 18, you need to escape them. So your query should be INSERT INTO storedata (id, NAME, city, state, phone, zip_code) VALUES ('VZFF-3418-NN??N?', '', 148, '34\\', '', '18\\' ); The first slash lets php know the the next character should be accepted literally and not as a control character. Link to comment https://forums.phpfreaks.com/topic/200926-error-on-insert/#findComment-1054254 Share on other sites More sharing options...
Maq Posted May 6, 2010 Share Posted May 6, 2010 You can use mysql_real_escape_string. Link to comment https://forums.phpfreaks.com/topic/200926-error-on-insert/#findComment-1054272 Share on other sites More sharing options...
bulrush Posted May 7, 2010 Author Share Posted May 7, 2010 The mysql_error() is not returning an error. Here is my php code: if (!$result=mysqli_query($dbc,$query)) { $msg=mysql_error(); //There was an error. echo '<p class="error">ERROR: '.$msg.'<br/>'.$query.'</p>'; die(); } else { echo '<br><font color="blue">Saved model '.$modelvar.' '.$descvar.'</font></br>'; } So I removed the backslashes with str_replace, and I'm still getting an unknown error on INSERT. Here is what the INSERT statement looks like: ERROR: INSERT INTO hproduct (grid, pnumber, description, price, height, depth, width, createuser, createdate) VALUES (9, 'VZFF-3418-NN??N?', '', 148, '34', '', '18', 'chuckr', NOW()); Anyone know what the problem is? The field with "148" is a float field. Am I required to enter decimals if the user does not enter any? Should the question marks in "VZFF-3418-NN??N?" be escaped? Thanks. Link to comment https://forums.phpfreaks.com/topic/200926-error-on-insert/#findComment-1054645 Share on other sites More sharing options...
bulrush Posted May 7, 2010 Author Share Posted May 7, 2010 My table is created like this: CREATE TABLE `hproduct` ( `pid` bigint(20) NOT NULL auto_increment, `grid` bigint(20) NOT NULL default '0', `description` varchar(40) default NULL, `height` varchar(10) default NULL, `depth` varchar(10) default NULL, `width` varchar(10) default NULL, `pnumber` varchar(20) NOT NULL default '', `price` float NOT NULL default '0', PRIMARY KEY (`pid`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=74 ; Link to comment https://forums.phpfreaks.com/topic/200926-error-on-insert/#findComment-1054651 Share on other sites More sharing options...
bulrush Posted May 7, 2010 Author Share Posted May 7, 2010 I should probably mention that we rent a server, so I cannot mess with the php.ini settings. Link to comment https://forums.phpfreaks.com/topic/200926-error-on-insert/#findComment-1054670 Share on other sites More sharing options...
bulrush Posted May 7, 2010 Author Share Posted May 7, 2010 Never mind. I'm an idiot. I hadn't added the fields "createuser" and "createdate" to the table yet. Now it works. Those were new fields. Link to comment https://forums.phpfreaks.com/topic/200926-error-on-insert/#findComment-1054673 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.