9 Replies - 12284 Views - Last Post: 23 August 2012 - 10:52 AM Rate Topic: -----

#1 ersaan   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 31-May 12

Parse error: syntax error, unexpected T_WHILE

Posted 23 August 2012 - 06:16 AM

I'm new to php and im trying to connect with Php to SQL- server and send some information from web to database but there is one problem appears to me T_WHILE i searched a lot web sites but i cannot find any solution . can u help me what can i do ..

<?php

$FName = $_POST['FName'];
$LName = $_POST['LName'];
$PHON = $_POST['PHON'];

$myServer = "localhost";
$myUser = "";
$myPass = "";
$myDB = "Project1";


//connection to the database
$dbhandle = mssql_connect($myServer, $myUser, $myPass)
  or die("Couldn't connect to SQL Server on $myServer"); 
  

//select a database to work with
$selected = mssql_select_db($myDB, $dbhandle)
  or die("Couldn't open database $myDB");
  
  $query="INSERT INTO dbo.Table1 (ID,FName,LName,PHON) VALUES ('NULL',".$FName."','".$LName."','".$PHON."')"
 //[color="#00FF00"]The problem is on line 24 i cannot fix it . Can u tell me how can i fix it ... : )  [/color]
 while($row = mssql_fetch_array($query))
	{
  echo "ID:" .$row['ID']."First Name:".$row['FName']."LastName:".$row['LName']."Phone:".$row[row['PHON']."
	};

mssql_close($dbhandle);
?>

Attached File(s)



Is This A Good Question/Topic? 0
  • +

Replies To: Parse error: syntax error, unexpected T_WHILE

#2 Slice   User is offline

  • sudo pacman -S moneyz


Reputation: 253
  • View blog
  • Posts: 762
  • Joined: 24-November 08

Re: Parse error: syntax error, unexpected T_WHILE

Posted 23 August 2012 - 06:18 AM

Line 22, your query, needs a closing semi-colon ";".
Was This Post Helpful? 2
  • +
  • -

#3 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4278
  • View blog
  • Posts: 13,573
  • Joined: 08-June 10

Re: Parse error: syntax error, unexpected T_WHILE

Posted 23 August 2012 - 06:19 AM

the standard while loop does not end with a ; which in turn is missing on the previous line.

PS. SQL NULL-values ain’t quoted.

This post has been edited by Dormilich: 23 August 2012 - 06:20 AM

Was This Post Helpful? 3
  • +
  • -

#4 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6259
  • View blog
  • Posts: 24,028
  • Joined: 23-August 08

Re: Parse error: syntax error, unexpected T_WHILE

Posted 23 August 2012 - 06:21 AM

Hint for solving syntax errors: The line number for the error is often the line AFTER the line where the actual error is. So look back a line when you get the error and take a close look at it.
Was This Post Helpful? 2
  • +
  • -

#5 ersaan   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 31-May 12

Re: Parse error: syntax error, unexpected T_WHILE

Posted 23 August 2012 - 07:08 AM

View PostDormilich, on 23 August 2012 - 06:19 AM, said:

the standard while loop does not end with a ; which in turn is missing on the previous line.

PS. SQL NULL-values ainít quoted.



Thnx , Dormilich but now appears another parse error ...
Parse error: syntax error, unexpected $end in C:\AppServ\www\2\update.php on line 30 ... i'm looking for the solution but i cannot find where do u think i'm making a mistake ?? :) i purschade ur answer.
Was This Post Helpful? 0
  • +
  • -

#6 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6259
  • View blog
  • Posts: 24,028
  • Joined: 23-August 08

Re: Parse error: syntax error, unexpected T_WHILE

Posted 23 August 2012 - 07:22 AM

Post your current code.

Another hint: Unexpected $end means the script ended ... unexpectedly. That means you are likely missing a closing }
Was This Post Helpful? 0
  • +
  • -

#7 ersaan   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 31-May 12

Re: Parse error: syntax error, unexpected T_WHILE

Posted 23 August 2012 - 07:24 AM

View PostJackOfAllTrades, on 23 August 2012 - 07:22 AM, said:

Post your current code.

Another hint: Unexpected $end means the script ended ... unexpectedly. That means you are likely missing a closing }


<?php

$FName = $_POST['FName'];
$LName = $_POST['LName'];
$PHON = $_POST['PHON'];

$myServer = "localhost";
$myUser = "";
$myPass = "";
$myDB = "Project1";


//connection to the database
$dbhandle = mssql_connect($myServer, $myUser, $myPass)
  or die("Couldn't connect to SQL Server on $myServer"); 
  

//select a database to work with
$selected = mssql_select_db($myDB, $dbhandle)
  or die("Couldn't open database $myDB");
  
  $query="INSERT INTO dbo.Table1 (ID,FName,LName,PHON) VALUES (NULL,".$FName.",".$LName.",".$PHON.")";
  
 while($row = mssql_fetch_array($query))
	{
  echo "ID:" .$row['ID']."First Name:".$row['FName']."LastName:".$row['LName']."Phone:".$row['PHON']."
	};

mssql_close($dbhandle);

?>

Was This Post Helpful? 0
  • +
  • -

#8 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3837
  • View blog
  • Posts: 13,998
  • Joined: 08-August 08

Re: Parse error: syntax error, unexpected T_WHILE

Posted 23 August 2012 - 07:27 AM

Have you studied Dormilich's excellent tutorial on PDO? There's no reason to learn mysql_* functions and then learn to protect them from SQL injections, only to need to learn prepared statements when mysql_* goes away in the near future.
Was This Post Helpful? 0
  • +
  • -

#9 ersaan   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 31-May 12

Re: Parse error: syntax error, unexpected T_WHILE

Posted 23 August 2012 - 07:33 AM

Dormilich i found where i made mistake for Error PArse $end but now it apperar another problem with } ,
here
while($row = mssql_fetch_array($query))
	{
  echo "ID:".$row['ID']."First Name:".$row['FName']."LastName:".$row['LName']."Phone:".$row['PHON'].
	}


Parse error: syntax error, unexpected ';' in C:\AppServ\www\2\update.php on line 27
Was This Post Helpful? 0
  • +
  • -

#10 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4278
  • View blog
  • Posts: 13,573
  • Joined: 08-June 10

Re: Parse error: syntax error, unexpected T_WHILE

Posted 23 August 2012 - 10:52 AM

whatís the last dot on that line supposed to do?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1