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
Share on other sites

At first glance, try removing the double quotes around

 

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

 

like so:

 

$polno = $_POST['polno'];

 

Remember $_POST is a variable, no need to encase it in double quotes when passing it's value around.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.