Jump to content

Recommended Posts

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

  • 2 months later...

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.

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

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.