Inserting variable data into a SQL Server table
Posted: Tue Sep 30, 2008 9:27 am
Hello
I'm trying to insert data from a variable in to a table in SQL Server 2005.
So far my query is this which runs ok but doesn't give me the desired results:
$dsn="Server_Test";
$username="Test";
$password="srvtest";
$sqlconn=odbc_connect($dsn,$username,$password);
global $sqlconn, $stuCode, $stuFnm1, $stuSurn, $stuCount, $sql1;
$sql="SELECT top (5) STUCODE, STUFNM1, STUSURN FROM WARN_VIEW";
$row=odbc_exec($sqlconn, $sql);
while($stuCount=odbc_fetch_row($row)) {
$stuCode=odbc_result($row,'STUCODE');
$stuFnm1=odbc_result($row,'STUFNM1');
$stuSurn=odbc_result($row,'STUSURN');
$stuCount++;
}
{
$sql1="INSERT INTO DIS_WARN(SDW_CODE) VALUES ('$stuCode')";
$row=odbc_exec($sqlconn,$sql1);
}
odbc_close($sqlconn);
The Insert into statement seems to work but will not loop through the records.
If I leave it in its current state I get 1 row inserted into the table.
How can I get it to insert all the data in to the table?
Thank you
I'm trying to insert data from a variable in to a table in SQL Server 2005.
So far my query is this which runs ok but doesn't give me the desired results:
$dsn="Server_Test";
$username="Test";
$password="srvtest";
$sqlconn=odbc_connect($dsn,$username,$password);
global $sqlconn, $stuCode, $stuFnm1, $stuSurn, $stuCount, $sql1;
$sql="SELECT top (5) STUCODE, STUFNM1, STUSURN FROM WARN_VIEW";
$row=odbc_exec($sqlconn, $sql);
while($stuCount=odbc_fetch_row($row)) {
$stuCode=odbc_result($row,'STUCODE');
$stuFnm1=odbc_result($row,'STUFNM1');
$stuSurn=odbc_result($row,'STUSURN');
$stuCount++;
}
{
$sql1="INSERT INTO DIS_WARN(SDW_CODE) VALUES ('$stuCode')";
$row=odbc_exec($sqlconn,$sql1);
}
odbc_close($sqlconn);
The Insert into statement seems to work but will not loop through the records.
If I leave it in its current state I get 1 row inserted into the table.
How can I get it to insert all the data in to the table?
Thank you