phpNoobee Posted September 14, 2006 Share Posted September 14, 2006 hello,what is wrong with this code:[code] function db_insert() { $title = mysql_real_escape_string($title); $desc = mysql_real_escape_string($desc); $url = mysql_real_escape_string($url); $maxBid = mysql_real_escape_string($maxBid); $sql = "INSERT INTO view_bids(col_id, parent, date_scrapped, item_number, title, description, url, max_bid, currency) VALUES (0, '', '', 0, '$title', '$description', '$url', '$max_bid', '$mkg')"; mysql_query($sql); $title = ''; $description = ''; $url = ''; $max_bid = ''; $currency = ''; }[/code]it wont insert when i click a button to the db. Quote Link to comment Share on other sites More sharing options...
karthikeyan_coder Posted September 14, 2006 Share Posted September 14, 2006 replace : "mysql_query($sql);" with "mysql_query($sql) or die(mysql_error());" and then let us know with the output... Quote Link to comment Share on other sites More sharing options...
obsidian Posted September 14, 2006 Share Posted September 14, 2006 you're not inserting anything. you're calling a function and applying the mysql_real_escape_string() to variables that have not been instantiated within the function. you have to either pass the variables INTO the function to be parsed, or you have to reference global variables via the global keyword (not recommended) or the $_POST, $_GET, $_REQUEST or some other global variable. Quote Link to comment Share on other sites More sharing options...
phpNoobee Posted September 14, 2006 Author Share Posted September 14, 2006 And my SQL Table Schema:[code]CREATE TABLE `view_bids` ( `col_id` varchar(0) NOT NULL, `parent` varchar(0) NOT NULL, `date_scrapped` varchar(0) NOT NULL, `item_number` varchar(0) NOT NULL, `title` varchar(0) NOT NULL, `description` varchar(0) NOT NULL, `url` varchar(0) NOT NULL, `max_bid` varchar(0) NOT NULL, `currency` varchar(0) NOT NULL) ENGINE=MyISAM DEFAULT CHARSET=latin1;[/code]That is the code i am using and also the table in the db Quote Link to comment Share on other sites More sharing options...
karthikeyan_coder Posted September 14, 2006 Share Posted September 14, 2006 what is the output? Quote Link to comment Share on other sites More sharing options...
obsidian Posted September 15, 2006 Share Posted September 15, 2006 did you read my post above? from the code you posted, [b]none of your variables are being set[/b] since you're within a function. also, as your table is set up with your id column as a varchar, so you have no unique key to reference, and as you do get your inserts to work, you're going to have every record with '0' as your id. one more thing about your table structure: your date column would be much better served as a DATE datatype. you may want to consider something along these lines for a more usable table structure:[code]CREATE TABLE `view_bids` ( `col_id` int(11) AUTO_INCREMENT PRIMARY ID, `parent` int(11) NOT NULL, `date_scrapped` DATE NOT NULL, `item_number` varchar(10) NOT NULL, `title` varchar(20) NOT NULL, `description` varchar(200) NOT NULL, `url` varchar(50) NOT NULL, `max_bid` float(6,2) NOT NULL, `currency` varchar(10) NOT NULL)[/code]as i was writing that, i realized that your create table is defining all your fields as a varchar with a length of 0! it's no wonder you can't insert anything. you have your fields limited to no characters. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.