Jump to content

Error on INSERT


bulrush

Recommended Posts

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

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

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

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

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.