ICEcoffee Posted April 21, 2006 Share Posted April 21, 2006 Hi allI 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 Link to comment https://forums.phpfreaks.com/topic/8052-why-wont-my-mysql-inseert-into-variable-work/ Share on other sites More sharing options...
shocker-z Posted April 21, 2006 Share Posted April 21, 2006 $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 sideRegardsLiam Link to comment https://forums.phpfreaks.com/topic/8052-why-wont-my-mysql-inseert-into-variable-work/#findComment-29379 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.