Professional Web Applications Themes

INSERT INTO using PHP - MySQL

I have been working on PHP script, and was working through some problems over at the PHP group. However, I believe my problem now boils down to a MySQL problem. The script takes PHP variables and reads them into a MySQL database. Here is tthe relevant part of the script: $query='INSERT INTO review_registration() VALUES($FName, $LName, $Company, $Title, $Address, $Apt, $City, $State, $Zip, $Phone, $Fax, $Email, $Var1l, $Var2, $Var3, $Var4, $Var5)' The error message is: Query failed: Unknown column '$FName' in 'field list' The table exists, and the varibles are correct. If I put quotation marks around each variable inside VALUES, ...

  1. #1

    Default INSERT INTO using PHP

    I have been working on PHP script, and was working through some
    problems over at the PHP group. However, I believe my problem now boils
    down to a MySQL problem. The script takes PHP variables and reads them
    into a MySQL database. Here is tthe relevant part of the script:

    $query='INSERT INTO review_registration() VALUES($FName, $LName,
    $Company, $Title, $Address, $Apt, $City, $State, $Zip, $Phone, $Fax,
    $Email, $Var1l, $Var2, $Var3, $Var4, $Var5)'

    The error message is:

    Query failed: Unknown column '$FName' in 'field list'

    The table exists, and the varibles are correct. If I put quotation
    marks around each variable inside VALUES, it will actually write the
    variable name into the database. $FName for instance, instead of the
    data that $FName references. However, this demonstrates that the
    database connection is being made, the table is being found, and data
    can be written to it. I am running MySQL 4.0.1.

    The thing that sticks out at me is that $FName is not a column name,
    but I don't know why the system thinks that it is. I tried defining the
    columns in review_registration() but I got the same error message. Any
    help will be greatly appreciated.

    Jerim79 Guest

  2. Moderated Post

    Default Re: INSERT INTO using PHP

    Removed by Administrator
    Peter Guest
    Moderated Post

  3. #3

    Default Re: INSERT INTO using PHP


    Jerim79 wrote: 

    Try this:

    $query="INSERT INTO `review_registration` VALUES('$FName', '$LName',
    '$Company', '$Title', '$Address', '$Apt', '$City', '$State', '$Zip',
    '$Phone', '$Fax',
    '$Email', '$Var1l', '$Var2', '$Var3', '$Var4', '$Var5');";

    strawberry Guest

  4. #4

    Default Re: INSERT INTO using PHP

    com says... 

    The PHP Pr will not attempt to p strings encapsulated in single
    quotes.

    Use double-quotes instead, or escape+concatenate the variables.

    $query="INSERT INTO review_registration() VALUES($FName, $LName,
    $Company, $Title, $Address, $Apt, $City, $State, $Zip, $Phone, $Fax,
    $Email, $Var1l, $Var2, $Var3, $Var4, $Var5)";

    or

    $query='INSERT INTO review_registration() VALUES('.$FName.', '.$LName.',
    '.$Company.', '.$Title.', '.$Address.', '.$Apt.', '.$City.', '.$State.',
    '.$Zip.', '.$Phone.', '.$Fax.', '.$Email.', '.$Var1l.', '.$Var2.', '.
    $Var3.', '.$Var4.', '.$Var5.')';

    Geoff M

    Geoff Guest

  5. #5

    Default Re: INSERT INTO using PHP

    Jerim79 wrote: 

    The error is a PHP error.
    Expand your error message:

    <?php
    // ...
    $res = mysql_query($query);
    if (!$res) {
    # die('Query failed: ' . mysql_error()); // simple version
    die('Query failed: ' . mysql_error() .
    ' The SQL statement was: ' . $query); // expanded version
    }


    --
    I (almost) never check the dodgeit address.
    If you *really* need to mail me, use the address in the Reply-To
    header with a message in *plain* *text* *without* *attachments*.
    Pedro Guest

  6. #6

    Default Re: INSERT INTO using PHP


    Pedro Graca wrote: 
    >
    > The error is a PHP error.
    > Expand your error message:
    >
    > <?php
    > // ...
    > $res = mysql_query($query);
    > if (!$res) {
    > # die('Query failed: ' . mysql_error()); // simple version
    > die('Query failed: ' . mysql_error() .
    > ' The SQL statement was: ' . $query); // expanded version
    > }
    >
    >
    > --
    > I (almost) never check the dodgeit address.
    > If you *really* need to mail me, use the address in the Reply-To
    > header with a message in *plain* *text* *without* *attachments*.[/ref]

    It is working now. The double quotes was the fix. Thanks for all the
    help. (I still have the p the phone numbers to get them to enter
    right.)

    Jerim79 Guest

Similar Threads

  1. Question Insert from ASP to SQL using recordset data as values in insert statement
    By JasonM in forum Microsoft SQL / MS SQL Server
    Replies: 0
    Last Post: June 13th, 05:54 PM
  2. What's faster - loop for insert or insert...select.
    By mr. modus in forum Coldfusion Database Access
    Replies: 2
    Last Post: December 10th, 01:57 AM
  3. Multiple Insert or Looping Insert
    By payado in forum Dreamweaver AppDev
    Replies: 1
    Last Post: May 25th, 09:33 PM
  4. Replies: 0
    Last Post: July 23rd, 11:30 PM
  5. Replies: 3
    Last Post: September 30th, 09:24 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