Professional Web Applications Themes

Select one field - MySQL

I am having trouble with the syntax of select. (using php and mysql combined) The user keys in a number and I want to look for that field (only one field can have that value as its created automaticaly upon dataentry) Based upon the number the user keys in I want to retrieve another field from the same record This is not working. How do I do it? $scfchknum=$_POST['scfchknum']; (inlogging mysql) $upgcollect='SELECT scfpwd1 FROM scfmforening WHERE scfmnum = $scfchknum'; (logout mysql) $pwd1=mysql_query($upgcollect); mysql_close(); echo $pwd1; $scfchknum is the variable the user keyed in. scfmforening is the name of the table ...

  1. #1

    Default Select one field

    I am having trouble with the syntax of select. (using php and mysql
    combined) The user keys in a number and I want to look for that field (only
    one field can have that value as its created automaticaly upon dataentry)
    Based upon the number the user keys in I want to retrieve another field from
    the same record

    This is not working. How do I do it?

    $scfchknum=$_POST['scfchknum'];
    (inlogging mysql)
    $upgcollect='SELECT scfpwd1 FROM scfmforening WHERE scfmnum = $scfchknum';
    (logout mysql)
    $pwd1=mysql_query($upgcollect);
    mysql_close();
    echo $pwd1;

    $scfchknum is the variable the user keyed in.
    scfmforening is the name of the table
    scfmnum is the name of the field I want to search in
    scfpwd1 is name of the field I want to retreive from
    $upgcollect is the data before it is processed with query
    $pwd1 is the data after it is processed.


    Greatful for any help.
    Garry Jones
    Sweden



    Garry Guest

  2. #2

    Default Re: Select one field

    [ crossposted by me to comp.lang.php, followups set ]

    Garry Jones wrote (in comp.databases.mysql): 

    /*
    $pwd1 is a `resource`. The data in this resource can be fetched with
    mysql_fetch_*() or mysql_result().

    http://www.php.net/mysql_result
    http://www.php.net/mysql_fetch_row
    http://www.php.net/mysql_fetch_array
    http://www.php.net/mysql_fetch_assoc
    http://www.php.net/mysql_fetch_object
    */

    if (!$pwd1) {
    echo 'Query failed because: ', mysql_error();
    } else {
    if (($num_rows = mysql_num_rows($pwd1)) == 1) {
    echo mysql_result($pwd1, 0);
    } else {
    echo 'Number of rows returned: ', $num_rows;
    }
    }
     


    --
    File not found: (R)esume, (R)etry, (R)erun, (R)eturn, (R)eboot
    Pedro Guest

Similar Threads

  1. Select delimited characters within db field
    By etman in forum Coldfusion Database Access
    Replies: 4
    Last Post: October 8th, 03:52 PM
  2. Select answer Without field names
    By PL in forum MySQL
    Replies: 1
    Last Post: February 18th, 01:35 AM
  3. Select a list of items into an aliased field when doinga select
    By ehaemmerle in forum Coldfusion Database Access
    Replies: 3
    Last Post: March 18th, 10:49 PM
  4. Select from a text field!
    By Alex M. K. in forum Macromedia Dynamic HTML
    Replies: 0
    Last Post: November 20th, 05:19 PM
  5. Select from table where field = string
    By Michel in forum PHP Development
    Replies: 6
    Last Post: August 24th, 06:35 PM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139