Darkmatter5 Posted October 21, 2008 Share Posted October 21, 2008 This code produces an "unexpected T_VARIABLE" error at line 98. I have annotated line 98 in the code. What does that mean and how do I fix it? <?php include 'library/dbconfig.php'; include 'library/opendb.php'; if(isset($_POST['fullname'])) { $query="SELECT client_id, first_name, last_name, company_name FROM $dbname.clients"; $result=mysql_query($query) or die($query . '<br >'.mysql_error()); while($row=mysql_fetch_array($result)) { if(!isset($row['company_name'])) { //echo "$row[last_name], $row[first_name] ($row[client_id])<br>"; line 98-> UPDATE $dbname.clients SET full_name="$row[last_name], $row[first_name] ($row[client_id])"; } elseif(isset($row['company_name']) && ($row['last_name']!="")) { //echo "$row[company_name]: $row[last_name], $row[first_name] ($row[client_id])<br>"; UPDATE $dbname.clients SET full_name="$row[company_name]: $row[last_name], $row[first_name] ($row[client_id])"; } else { //echo "$row[company_name] ($row[client_id])<br>"; UPDATE $dbname.clients SET full_name="$row[company_name] ($row[client_id])"; } } echo "Function successfully run, constructed full_name field in the clients table."; } include 'library/closedb.php'; ?> Notice There are commented out echos. If I uncomment those echos and comment out the update code, the output is exactly what I need, so why do the update lines not work? Quote Link to comment https://forums.phpfreaks.com/topic/129476-what-is-unexpected-t_variable/ Share on other sites More sharing options...
trq Posted October 21, 2008 Share Posted October 21, 2008 You have a bunch of UPDATE statements that aren't within quotes. Quote Link to comment https://forums.phpfreaks.com/topic/129476-what-is-unexpected-t_variable/#findComment-671240 Share on other sites More sharing options...
Maq Posted October 21, 2008 Share Posted October 21, 2008 Usually this means a syntax error like missing semi colon or what thorpe said, unclosed quotes, or not using quotes, w/e. Quote Link to comment https://forums.phpfreaks.com/topic/129476-what-is-unexpected-t_variable/#findComment-671338 Share on other sites More sharing options...
btherl Posted October 22, 2008 Share Posted October 22, 2008 Here's an example of how to fix it (for the first error only): if(isset($_POST['fullname'])) { $query="SELECT client_id, first_name, last_name, company_name FROM $dbname.clients"; $result=mysql_query($query) or die($query . '<br >'.mysql_error()); while($row=mysql_fetch_array($result)) { if(!isset($row['company_name'])) { //echo "$row[last_name], $row[first_name] ($row[client_id])<br>"; line 98-> $query="UPDATE $dbname.clients SET full_name='{$row['last_name']}, {$row['first_name']} ({$row['client_id']})'"; $update_result = mysql_query($query) or die($query . '<br >'.mysql_error()); It's important that you use a different result variable inside the loop, otherwise you will overwrite the $result being used in the while(). The query also may not be correct yet, all I've fixed is the PHP syntax. Quote Link to comment https://forums.phpfreaks.com/topic/129476-what-is-unexpected-t_variable/#findComment-671400 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.