Jump to content

[SOLVED] PHP MSSQL Problem


NathanS

Recommended Posts

Hi there,

 

Got a problem which for the life of me i can't figure out. I need to pull through a number entered in a free text field in one page (below), and include that number in a script in the next page (also below).

 

Posted my code below, any help as to why this wouldn't be working would be great!

 

Thanks!

 

 

(Just to clarify, the script works fine if you define policynumber manually, only doesn't work when using $_POST['polno'])

 

 

Page 1

<form name="form" method="post" action="conn.php">
<input type="text" size="15" name="polno" />
<input type="submit" value="submit">
</form>

 

Page 2

<?php
//Let's determine the server variables and set 'em here.
$myServer = "192.168.1.175";
$myUser = "sa";
$myPass = "passwordhere";
$myDB = "Transactor_Version62";

$polno = "$_POST['polno']";

//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");

//declare the SQL statement that will query the database
$query = "SELECT * ";
$query .= "FROM customer_policy_details ";
$query .= "WHERE policynumber = '$polno'";
$query .= "AND live = 1";


//execute the SQL query and return records
$result = mssql_query($query);

$numRows = mssql_num_rows($result);

while($row = mssql_fetch_array($result))
{
$row1 = "$row[0]";
$row2 = "$row[1]";
$row3 = "$row[2]";
$row4 = "$row[3]";
$row5 = "$row[4]";
$row6 = "$row[5]";
}

echo "The below data has now been <b>fetched</b> from the MSSQL server and is now being <b>written</b> to the MySQL database";
echo "<BR>";
echo "<BR>";
echo "$row1";
echo "<BR>";
echo "$row2";
echo "<BR>";
echo "$row3";
echo "<BR>";
echo "$row4";
echo "<BR>";
echo "$row5";
echo "<BR>";
echo "$row6";
echo "<BR>";


//close the connection
mssql_close($dbhandle);

//and let's start the MySQL connection to write to ;] 

$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'passwordhere';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');

$dbname = 'topcards';
mysql_select_db($dbname);

$sql = "INSERT INTO topcards (row1, row2, row3, row4, row5, row6) VALUES ('$row1', '$row2', '$row3', '$row4', '$row5', '$row6')";

mysql_query($sql) or die('Error, insert query failed');

?>


Link to comment
https://forums.phpfreaks.com/topic/65388-solved-php-mssql-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.