Unknown column

Discussion in 'PHP' started by irdogg, Aug 12, 2012.

  1. #1
    the error

    Unknown column 'sites' in 'field list
    Code (markup):
    sql

    -- Table structure for table `domain`
    --
    
    CREATE TABLE IF NOT EXISTS `domain` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `domain` varchar(250) NOT NULL,
      UNIQUE KEY `id` (`id`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;
    
    --
    -- Dumping data for table `domain`
    --
    
    INSERT INTO `domain` (`id`, `domain`) VALUES
    (3, 'd0main1.c0m'),
    (2, 'bing.com'),
    (4, 'google.com');
    Code (markup):
    php code

    if($_GET['page']=='update'){
    $url = mysql_fetch_array(mysql_query("SELECT * FROM links order by rand() LIMIT 0 ,1"));
    $submiturl = $url['link'];
    $title = $url['title'] ? $url['title'] : "Awesome Video";
    $sitedata = mysql_query("SELECT * FROM domain");
    $flag=0;
    while ($domain = mysql_fetch_array($sitedata))
    	{
    		$sites = explode(",", $domain['sites']);
    		$pos = strpos ($submiturl, $domain['domain']);
    		if ($pos != FALSE) {
    			$count = count($sites);
    			for ($i=0;$i<$count;$i++)
    				{
    				$sitename = $sites[$i];
    				if($sitename == "daily" && $domain['count1'] < 100) {
    					submit($title, $submiturl, '', $sitename);	
    					mysql_query("update domain set count1=count1+1 where domain='$domain[domain]'");
    					$flag=1;
    				}
    				else if($sitename == "ontape" && $domain['count2'] < 100) {
    					submit($title, $submiturl, '', $sitename);	
    					mysql_query("update domain set count2=count2+1 where domain='$domain[domain]'");
    					$flag=1;
    				}
    Code (markup):
    hope that's enough :) im not sure if to change domains to sites
     
    Solved! View solution.
    irdogg, Aug 12, 2012 IP
  2. #2
    I think you need to add a field called `sites` to the `domain` table. looking at the code I would suspect it to be of the type TEXT. not 100% sure though.
     
    plussy, Aug 13, 2012 IP
  3. Shiplu

    Shiplu Peon

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    "Unknown column 'sites' in 'field list" This is certainly an SQL error. Not PHP.

    Where do this error get thrown?
    What is the SQL statement ?

    Your PHP code does to reference `sites` column. So the error is not from here. What it references is `$domain['sites']` which does not exist. It should cause an "Undefined index" notice. Not the sql error above. Also I see you are referring `$domain['domain']`. So it seems your table should have a `sites` column. Get the original database dump for this website and check the `domain` table. It should be there.
     
    Shiplu, Aug 13, 2012 IP
  4. irdogg

    irdogg Well-Known Member

    Messages:
    358
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    135
    #4

    thank you both :)
     
    irdogg, Aug 13, 2012 IP