Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP Funtion and Form

    Hi all,

    Hope someone can help with this, having to learn some more of what I think are the complicated bits of php before getting my head around the basics so please excuse anything that I ask that may sound stupid.

    I am trying to create a form that posts to a database, one of the fields that posts to the database is a drop down which is pulled from a table, my code is as follows and for the life of me I can get it to work, hope someone can help.

    My function is called "drop" and is saved as drop.php in the route directory of my web server.


    <?php
    function drop($selectName,$curValue,$intID,$strName,$tableName,$strOrderField,$strMethod)

    {

    // create connection
    $connection = mssql_connect("localhost","sa","password");

    // test connection
    if (!$connection)
    die "Couldn't make a connection!";


    // select database
    $db = mssql_select_db("nai", $connection);


    // test selection
    if (!$db)
    die "Couldn't select database!";

    $txt = "<select name='$selectName'>\n";
    $txt .= "<option value='-1'>Please select</option>\n";

    $strQuery = "select $intID, $strName from $tableName order by $strOrderField";
    $rsrcResult = mssql_query($strQuery, $connection);

    while($arrayRow = mssql_fetch_assoc($rsrcResult)) {
    $intIdField = $arrayRow["$intID"];
    $strNameField = $arrayRow["$strName"];

    $sel = ( $intIdField == $curValue ) ? " selected='selected' " : "";
    $txt .= "<option $sel value=\"$intIdField\">$strNameField</option>\n";
    }

    $txt .= "</select>\n\n";

    return $txt;
    }

    ?>

    I am just trying to run a basic test to see if it works by running the following php file called test.php which is also stored in the route directory

    <p>Location:<br>
    <?php echo drop("intLocation", "", IssueTypeID, IssueTypeDesc, IssueType, IssueTypeID); ?></p>

    I get the following error

    function drop($selectName, $curValue, $intID, $strName, $tableName, $strOrderField, $strMethod="asc") { // create connection $connection = mssql_connect("localhost","sa","password"); // test connection if (!$connection) die "Couldn't make a connection!"; // select database $db = mssql_select_db("nai", $connection); // test selection if (!$db) die "Couldn't select database!"; $txt = "\n"; $txt .= "Please select\n"; $strQuery = "select $intID, $strName from $tableName order by $strOrderField, $strMethod"; $rsrcResult = mssql_query($strQuery, $connection); while($arrayRow = mssql_fetch_assoc($rsrcResult)) { $intIdField = $arrayRow["$intID"]; $strNameField = $arrayRow["$strName"]; $sel = ( $intIdField == $curValue ) ? " selected='selected' " : ""; $txt .= "$strNameField\n"; } $txt .= "\n\n"; return $txt; }

    Just seems to be showing all my code as a text string, am I just calling it all wrong or not naming my files correctly, read lots of tutorials and I cant seem to see what I am doing wrong, also if someone knows how I then use the then select value from the drop down to $_POST in my form it would be much appreciated.

    Thanks tress

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Your code is not running on a server with PHP installed correctly. Is your PHP file on your local hard drive? Did you install PHP on your machine? Did you upload your PHP file to somewhere on the innernet? Does that somewhere have PHP installed?

  • #3
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes I do have PHP running, the latest version from the php web site, I can run basic scripts and the info file to make sure everything is installed correctly . Its running on Windows Server 2003 and is connecting to a SQL Server 2003 database, both SQL Server and IIS and PHP are all installed on the same box, and all testing is done on that box and run locally.

    Hope that is of help

    Thanks tress

  • #4
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    For whatever reason your server doesn't know this is a PHP script. The file extension must be PHP and you must use proper PHP tags. Something is not in place.

    However you have the other basic script working on your server is what must be done with this script as well.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •