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
Inserting variable data into a SQL Server table
Moderator: General Moderators
Re: Inserting variable data into a SQL Server table
You need to loop through the insert statement.
Re: Inserting variable data into a SQL Server table
Hi
Do you mean loop through within the SQL statement?
Thanks
Do you mean loop through within the SQL statement?
Thanks
Re: Inserting variable data into a SQL Server table
Well you want to insert $stuCode into the table right?
So What you need to do is to include the insert statement in the while loop so you insert the values that is generated.
So What you need to do is to include the insert statement in the while loop so you insert the values that is generated.
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Re: Inserting variable data into a SQL Server table
Move your insert code into your while loop code.