Jump to content


Photo

need help


  • Please log in to reply
5 replies to this topic

#1 phpNoobee

phpNoobee
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 14 September 2006 - 07:31 PM

hello,

what is wrong with this 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 = '';
	}

it wont insert when i click a button to the db.

#2 karthikeyan_coder

karthikeyan_coder
  • Members
  • PipPipPip
  • Advanced Member
  • 201 posts

Posted 14 September 2006 - 07:34 PM

replace : "mysql_query($sql);" with "mysql_query($sql) or die(mysql_error());" and then let us know with the output...

www.karthi.us

#3 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 14 September 2006 - 07:42 PM

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.
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#4 phpNoobee

phpNoobee
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 14 September 2006 - 07:55 PM

And my SQL Table Schema:
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;

That is the code i am using and also the table in the db

#5 karthikeyan_coder

karthikeyan_coder
  • Members
  • PipPipPip
  • Advanced Member
  • 201 posts

Posted 14 September 2006 - 08:06 PM

what is the output?
www.karthi.us

#6 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 15 September 2006 - 12:33 PM

did you read my post above? from the code you posted, none of your variables are being set 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:
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
)

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.
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users