NathanS Posted August 17, 2007 Share Posted August 17, 2007 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'); ?> Quote Link to comment Share on other sites More sharing options...
Aeglos Posted August 17, 2007 Share Posted August 17, 2007 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. Quote Link to comment Share on other sites More sharing options...
NathanS Posted August 17, 2007 Author Share Posted August 17, 2007 Thanks for that. Stupid mistake of mine. Thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.