Jump to content


Photo

why wont my MySQL INSEERT INTO variable work?


  • Please log in to reply
1 reply to this topic

#1 ICEcoffee

ICEcoffee
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 21 April 2006 - 04:24 PM

Hi all

I can't get this INSERT command to work using a variable?

I want to take the value from querying 1 table and INSERT that data into another table.




<?php
echo "race variables";
mysql_select_db($database_FF1, $FF1);
$raceq = ('SELECT RaceID FROM races WHERE CurrentRace = 1');
$raceresult = mysql_query($raceq) or die(mysql_error());
$row = mysql_fetch_array($raceresult);


// mysql_select_db($database_FF1, $FF1);
$leaderq = "INSERT INTO ff1_leaderboard (RaceID, TeamID) VALUES ($row['RaceID'],'9')";
mysql_query($leaderq) or die(mysql_error());


?>

Thanks for any help

#2 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 21 April 2006 - 05:01 PM

$leaderq = "INSERT INTO ff1_leaderboard (RaceID, TeamID) VALUES ($row['RaceID'],'9')";


needs to be


$leaderq = "INSERT INTO ff1_leaderboard (RaceID, TeamID) VALUES ('$row[RaceID]','9')";



variables ahve to be wrapped with ' either side

Regards
Liam
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users