www.webdeveloper.com
Results 1 to 8 of 8

Thread: confusion about string vs variable

  1. #1
    Join Date
    Oct 2011
    Location
    Hamilton, Ontario
    Posts
    81

    confusion about string vs variable

    So I'm not entirely sure how this all works and I've spent hours upon hours trying to research and figure this out, but now i'm just stuck.. here is a generic version of my code:
    PHP Code:
    <?php

    $response_which
    =$_POST['response'];
    $seek=$_POST['seeking'];
    $serverName "dbname";
    $username "dbusername";
    $password "password";
    $database "database";
    #DO NOT EDIT BELOW THIS LINE
    $connectionInfo = array( "UID"=>$username"PWD"=>$password"Database"=>$database);
    $conn sqlsrv_connect$serverName$connectionInfo);

    mysql_query($conn,"INSERT INTO feedback '$seek'");

    $response mysql_query($conn,"SELECT response FROM feedback");
    $response++;

    if(
    $response_which=='yes'){
        
    mysql_query($conn,"UPDATE Persons SET yes='$response'");
    }
    else {
        
    mysql_query($conn,"UPDATE Persons SET no='$response'");
    }
    echo 
    "<b>$response</b><br><b>$seeking</b>";
    ?>
    and here is the html that calls it:
    Code:
    <!DOCTYPE html>
    <html>
        <head>
            <title>test</title>
        </head>
        <body>
            <form action='feedback.php' method='post'>
                What were you looking for in coming to this site?<input type='text' name='seeking'/>
                Did you find what you were looking for?
                    <input type='radio' name='response' value='yes'>YES</input>
                    <input type='radio' name='response' value='no'>NO</input>
                    <input type='radio' name='response' value='sortof'>SORT OF</input>
                    <input type='submit' value='Submit'/>
            </form>
        </body>
    </html>
    I imagine there a bunch of errors in this I am clueless about and I know javascript really well, but I am brand new to PHP so any help would be appreciated.. all I'm getting when I run this is the following:

    Warning: mysql_query() expects parameter 1 to be string, resource given in E:\kunden\homepages\4\d466152678\www\feedback.php on line 13 (same message repeated for lines 15 and 19

    is w3schools leading me wrong in the mysql_query($variable, "string"); syntax or is there just something else I am doing wrong?

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,313
    You just have your arguments transposed. The MySQL connection is the 2nd arg:
    PHP Code:
    mysql_query("INSERT INTO feedback '$seek'"$conn); 
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Oct 2011
    Location
    Hamilton, Ontario
    Posts
    81
    okay.. well i did that, but now it's throwing me this:

    Warning: mysql_query(): supplied resource is not a valid MySQL-Link resource in E:\filepath\feedback.php on line 13, 15 and 19
    Last edited by thewebiphyer; 05-07-2013 at 05:06 PM.

  4. #4
    Join Date
    Mar 2009
    Posts
    452
    double check server name user name and password, also try connecting using same values from a different source/program

  5. #5
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,313
    Take a close look at this:
    Code:
    $conn = sqlsrv_connect( $serverName, $connectionInfo);
    
    mysql_query($conn,"INSERT INTO feedback '$seek'");
    In other words, you don't use a sqlsrv function to connect to a mysql database, or conversely you don't use a mysql function to query a sqlsrv database.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  6. #6
    Join Date
    Oct 2011
    Location
    Hamilton, Ontario
    Posts
    81
    Quote Originally Posted by NogDog View Post
    Take a close look at this:
    Code:
    $conn = sqlsrv_connect( $serverName, $connectionInfo);
    
    mysql_query($conn,"INSERT INTO feedback '$seek'");
    In other words, you don't use a sqlsrv function to connect to a mysql database, or conversely you don't use a mysql function to query a sqlsrv database.
    so would i go sqlsrv_query($serverName, $connectionInfo); instead? sorry i'm just really new to php

  7. #7
    Join Date
    Oct 2011
    Location
    Hamilton, Ontario
    Posts
    81
    *edit* yea I just switched it to sqlsrv_query(); and it's not throwing anymore errors, but now I cannot log into my database.. I'll just have to contact my host tech support on this one i think

  8. #8
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,313
    Quote Originally Posted by thewebiphyer View Post
    so would i go sqlsrv_query($serverName, $connectionInfo); instead? sorry i'm just really new to php
    If you are, in fact, using SQL SERVER (instead of MySQL) as your DBMS, then yes -- along with any other DB functions you may be using.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles