Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Closed Thread
Old 02-10-2008, 03:46 PM   #1 (permalink)
 
Super Techie

Join Date: Sep 2006

Location: Altoona, PA

Posts: 250

Mike9182 is on a distinguished road

Send a message via AIM to Mike9182
Default MYSQL Problem

What do I need to change in this code? It writes successfully to the database but instead of writing the data in the variable it writes the variable name. For example it writes $location in as the url.

Here is the code where the problem most likely is:
PHP Code:
$sql 'INSERT INTO `nuke_downloads_downloads` (`lid`, `cid`, `sid`, `title`, `url`, `description`, `date`, `name`, `email`, `hits`, `submitter`, `downloadratingsummary`, `totalvotes`, `totalcomments`, `filesize`, `version`, `homepage`) VALUES (\'\', \'2\', \'0\', \'$name[$reps]\', \'$location[$reps]\', \'BF2 Demo Recording\', \'$time\', \'\', \'\', \'0\', \'\', \'0.0000\', \'0\', \'0\', \'$size\', \'\', \'\');';
        
mysql_query($sql$con) ; 
Here is all the code:
PHP Code:
<?
//get date and time
$time date("Y-m-d H:i:s") ;

// Gather file information
$file = (scandir("/home/content/c/l/a/clan3rd/html/demos/demos/")) ;
$demo ".bf2demo" ;
$count ;

foreach (
$file as $fname)
{
    if (
strpos($fname,$demo) != FALSE)
        {
        
$count $count ;
        
$dname str_ireplace($demo,"",$fname) ;
        
$name[$count] = $dname ;
        
$location[$count] = "http://demos.1stmercenaries.com/" $fname ;
        
$exactfile[$count] = $fname ;
        }
}


$hostname='removed for security';
$username='removed for security';
$password='removed for security';
$con mysql_connect($hostname,$username$password) OR DIE ('Unable to connect to database! Please try         again later.') ;
mysql_select_db("Poison555_2"$con) ;

$result mysql_query("SELECT * FROM `nuke_downloads_downloads` ");
$result2 mysql_query("SELECT * FROM `nuke_downloads_downloads` ");

while(
$row mysql_fetch_array($result))
    {
    
$id $row['lid'];
    }

$existing mysql_fetch_array($result2) ;

$reps ;    
foreach (
$location as $row2)
    {
    echo 
$location[$reps] ;
    
$size filesize($exact_file[$reps]) ;
    
$search array_search($row2,$existing) ;
    echo 
$search ;
    if(
strlen($search) > 0)
        
$execute "no" ;
    else
        
$execute "yes" ;
    if(
$execute == "yes")
        {
        
$sql 'INSERT INTO `nuke_downloads_downloads` (`lid`, `cid`, `sid`, `title`, `url`, `description`, `date`, `name`, `email`, `hits`, `submitter`, `downloadratingsummary`, `totalvotes`, `totalcomments`, `filesize`, `version`, `homepage`) VALUES (\'\', \'2\', \'0\', \'$name[$reps]\', \'$location[$reps]\', \'BF2 Demo Recording\', \'$time\', \'\', \'\', \'0\', \'\', \'0.0000\', \'0\', \'0\', \'$size\', \'\', \'\');';
        
mysql_query($sql$con) ;
        
$id $id ;
        
// mysql_query(INSERT INTO `nuke_downloads_downloads` ( `lid` , `cid` , `sid` , `title` , `url` , `description` , `date` , `name` , `email` , `hits` , `submitter` , `downloadratingsummary` , `totalvotes` , `totalcomments` , `filesize` , `version` , `homepage` ) VALUES ('$id', '2', '0', '$name[$reps]', '$location[$reps]', 'BF2 Demo Recording', '$time', '', '', '0', '', '0.0000', '0', '0', '$size', '', ''))
        
}
        
$reps $reps ;
    }
mysql_close($con);
echo 
"Demo list refreshed" ;
  
?>

__________________

My Comp:
Antec 900
Gigabyte DS3
EVGA 8800GTS (G92)
Antec TruPower 650 watt psu
Core 2 Duo E6700 @ 3.3Ghz
G.Skill 4GB DDR2-800
2 x Seagate Barracuda 250GB HDD in RAID 0
1 x Seagate Barracuda 500GB HDD
ACER 19" 5ms monitor
ZALMAN CNPS9500 cpu fan/heatsink
Mike9182 is offline  
Old 02-11-2008, 02:04 AM   #2 (permalink)
CrazeD's Avatar
 
Wizard Techie

Join Date: Feb 2006

Location: Maine

Posts: 3,683

CrazeD will become famous soon enough

Send a message via AIM to CrazeD Send a message via MSN to CrazeD
Default Re: MYSQL Problem

First off, use double quotes on your query string.

Example:
PHP Code:
$sql "INSERT INTO blah blah blah..."
This will allow you to use the single quotes for the names, without escaping it.

Second, you're inserting the variable wrong. Do it like this:
PHP Code:
'".$variable."' 
or

PHP Code:
'{$variable}' 

__________________

Need website help? PM me!
CrazeD is offline  
Old 02-12-2008, 07:28 PM   #3 (permalink)
 
Super Techie

Join Date: Sep 2006

Location: Altoona, PA

Posts: 250

Mike9182 is on a distinguished road

Send a message via AIM to Mike9182
Default Re: MYSQL Problem

I've got the script working now.
__________________

My Comp:
Antec 900
Gigabyte DS3
EVGA 8800GTS (G92)
Antec TruPower 650 watt psu
Core 2 Duo E6700 @ 3.3Ghz
G.Skill 4GB DDR2-800
2 x Seagate Barracuda 250GB HDD in RAID 0
1 x Seagate Barracuda 500GB HDD
ACER 19" 5ms monitor
ZALMAN CNPS9500 cpu fan/heatsink
Mike9182 is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Restoring my forum from a MySQL backup, I need help! White_Wolf Web Site Hosting / ISP Q & A 2 01-24-2008 07:28 PM
Problem with 3D graphics mordi05 Windows Operating Systems and Software 6 12-10-2007 11:37 PM
Serious computer problem. HeeRoMaKi Hardware Troubleshooting 71 07-28-2007 11:42 PM
Media Library (I Presume) Problem. Nadegas Windows Operating Systems and Software 4 06-08-2007 08:27 AM
Chronic Rebooting Problem AND_YOU_ARE Hardware Troubleshooting 1 04-24-2007 06:04 PM