Jump to content

need help


phpNoobee

Recommended Posts

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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.