Douglas28 Posted November 26, 2011 Share Posted November 26, 2011 I've written a simple Poll script which works fine on localhost, and it appears to work on my remote host without errors yet nothing seems to be updated in SQL Server. I'm starting to feel like I'm going crazy with this. My Stored Procedure: USE [FortissimoMedia] GO /****** Object: StoredProcedure [Douglas28].[insertVote] Script Date: 11/26/2011 20:10:06 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [Douglas28].[insertVote] ( @PollID int, @VoteAnswer varchar ) AS IF @VoteAnswer = 'Answer1' UPDATE tblPollVotes SET Answer1 = Answer1 + 1 WHERE PollID = @PollID ELSE IF @VoteAnswer = 'Answer2' UPDATE tblPollVotes SET Answer2 = Answer2 + 1 WHERE PollID = @PollID ELSE IF @VoteAnswer = 'Answer3' UPDATE tblPollVotes SET Answer3 = Answer3 + 1 WHERE PollID = @PollID ELSE IF @VoteAnswer = 'Answer4' UPDATE tblPollVotes SET Answer4 = Answer4 + 1 WHERE PollID = @PollID ELSE IF @VoteAnswer = 'Answer5' UPDATE tblPollVotes SET Answer5 = Answer5 + 1 WHERE PollID = @PollID Relevant PHP code: } elseif (isset($_GET["InsertVote"]) && $_GET["InsertVote"] == "True") { $con = mssql_connect(".\SQLExpress", "username", "password"); mssql_select_db("FortissimoMedia", $con); $stmt = mssql_init("InsertVote", $con); // Bind values mssql_bind($stmt, "@PollID", $_GET["PollID"], SQLINT1, false, false); mssql_bind($stmt, "@VoteAnswer", $_POST["Vote"], SQLVARCHAR, false, false, 8000); mssql_execute($stmt); echo "Thank you, your vote has successfully been added to the database. Click <a href='$_SERVER[sCRIPT_NAME]?ViewResults=True&PollID=$_POST[PollID]'>here</a> to view the results."; } $rs = odbc_exec($con, "SELECT * FROM tblPolls WHERE Active = 'Yes'"); while (odbc_fetch_row($rs)) { echo odbc_result($rs, "PollQuestion"); ?> <br /><br /> <form action="<?php $_SERVER["SCRIPT_NAME"] ?>?InsertVote=True&PollID=<?php echo odbc_result($rs, "PollID") ?>" method="post"> <input type="radio" name="Vote" value="Answer1" /> <?php echo odbc_result($rs, "PollAnswer1"); ?><br /> <input type="radio" name="Vote" value="Answer2" /> <?php echo odbc_result($rs, "PollAnswer2"); ?><br /> <input type="radio" name="Vote" value="Answer3" /> <?php echo odbc_result($rs, "PollAnswer3"); ?><br /> <input type="radio" name="Vote" value="Answer4" /> <?php echo odbc_result($rs, "PollAnswer4"); ?><br /> <input type="radio" name="Vote" value="Answer5" /> <?php echo odbc_result($rs, "PollAnswer5"); ?><br /> <input type="hidden" name="PollID" value="<?php echo odbc_result($rs, "PollID"); ?>" /> <p><input type="submit" value="Submit" /> <a href="<?php $_SERVER["SCRIPT_NAME"] ?>?ViewResults=True&PollID=<?php echo odbc_result($rs, "PollID") ?>">Results</a></p> </form> <?php } Hope someone can offer a suggestion. Thank you Douglas Quote Link to comment https://forums.phpfreaks.com/topic/251854-code-works-on-localhost-but-not-on-remote-host/ Share on other sites More sharing options...
sql-lover Posted February 5, 2012 Share Posted February 5, 2012 Hi Doug, Couple of questions or comments... 1st, why you are not using the MS-SQL driver for PHP? I can't see any sqlsrv_connect function there. My advice, try a simple PHP code to open a connection locally. Then change the server name and do the same but this time connecting remotely. It should work. If not, check your firewall, DNS settings or even if you are able to ping the remote server using its name. Quote Link to comment https://forums.phpfreaks.com/topic/251854-code-works-on-localhost-but-not-on-remote-host/#findComment-1314856 Share on other sites More sharing options...
givememore Posted February 9, 2012 Share Posted February 9, 2012 Hi Douglas, the same issue I had everytime I migrated a project from my test environment to productive machine... That's why I switched to sqlsrv-driver (which you have to use with SQL-Server 2005 or newer, afaik). Let me mention only one point in your script: You connect to MS-SQL Server with ".\SQLExpress" adressing the instance "SQLExpress" of the local computer (where PHP and the webserver are running). If you try to connect to a database on another machine you have to connect to "computername\instancename" or with its IP-Adress. Of course clientcabability has to be activated on SQLServer using the SQLControlPanel (mind the Clientprotocols are "active" AND "enabled"!) Burkhard Quote Link to comment https://forums.phpfreaks.com/topic/251854-code-works-on-localhost-but-not-on-remote-host/#findComment-1316138 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.