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 11 of 11
  1. #1
    New to the CF scene
    Join Date
    Jul 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    $_Post variable not updating in table

    Hello - this should be an easy script, but for some reason the 'address' variable isn't getting input into the database where the hardcoded 'list' field is.
    I'm running MySQL 4.1.10 on a unix box.

    Thanks in advance.
    Code:
      <form action="reply.php" method="post">
    E-mail: 
          <input name="address" type="text" id="address" /> 
    <input name="Submit" type="submit" id="Submit" value="Submit" />
    </form></font>
    </p>
    PHP Code:
    <?
    include("/XX/XX/include/dbinfo.inc.php");
    $address$_POST['address'];

    mysql_connect(localhost,$username,$password);
    @
    mysql_select_db($database) or die( "Unable to select database");

    $query "INSERT INTO email (address, list) VALUES ('$address','registrar')";
    mysql_query($query);

    mysql_close();
    ?>
    Last edited by guelphdad; 07-14-2006 at 02:42 PM.

  • #2
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Hi,

    echo $_POST['address']; and see if you get the correct value. If not, try echoing $address before you assign it.

    Good luck;

  • #3
    New to the CF scene
    Join Date
    Jul 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It comes back fine with
    echo "address is $address";

    Thanks for the tip though :-)

  • #4
    Senior Coder TheShaner's Avatar
    Join Date
    Sep 2005
    Location
    Orlando, FL
    Posts
    1,126
    Thanks
    2
    Thanked 40 Times in 40 Posts
    Quote Originally Posted by cyborgoddess
    It comes back fine with
    echo "address is $address";

    Thanks for the tip though :-)
    So it displays the address that has been typed? If so, then try echoing your SQL and see what that looks like.

    Post back with what you see in your browser for: echo $query;

    -Shane

  • #5
    New to the CF scene
    Join Date
    Jul 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    <!-- email submit form -->
    <form action="echo.php" method="post">
    E-mail: 
    <input name="address" type="text" id="address" /> 
    <input name="Submit" type="submit" id="Submit" value="Submit" />
    </form>
    <!-- php-mysql script BE SURE TO CHANGE line 24 ('$list')to department name -->
    PHP Code:
    <?
    include("/XXX/XXX/include/dbinfo.inc.php");
    $address$_POST['address'];
    $list=$_POST['list'];

    mysql_connect(localhost,$username,$password);
    @
    mysql_select_db($database) or die( "Unable to select database");

    $query "INSERT INTO email VALUES ('','$email', 'registrar')";
    mysql_query($query);
    mysql_close();
    echo 
    $query 
    ?>
    now here is the interesting part:
    this is what it echos back:
    INSERT INTO email VALUES ('','', 'registrar')

    So it is recognizing the insert of the first field (auto-number) and recognizing the last field (list ="registrar" but the query isn't posting the variable which PHP recognizes (I think?)
    Last edited by guelphdad; 07-14-2006 at 02:43 PM.

  • #6
    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
    PHP Code:
    $query "INSERT INTO email VALUES ('','$email', 'registrar')"
    That's not going to work. PHP doesn't parse out $email as a variable, but as part of the string. You need to break the variable out from the quoted part of the string.

    PHP Code:
    $query "INSERT INTO email VALUES ('','" $email "', 'registrar')"

  • #7
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Quote Originally Posted by Fumigator
    PHP Code:
    $query "INSERT INTO email VALUES ('','$email', 'registrar')"
    That's not going to work. PHP doesn't parse out $email as a variable, but as part of the string. You need to break the variable out from the quoted part of the string.

    PHP Code:
    $query "INSERT INTO email VALUES ('','" $email "', 'registrar')"
    Actually, that is perfectly valid. PHP will interpolate the variables inbetween double quotes. Now, if they were to use single quotes, it would be treated as a literal, and you would be correct. Problem I see is, you're using $email, when in fact I don't see that variable defined, I see $address.

  • #8
    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
    Ack! As I was finishing up that post I had a gut feeling I was wrong The $email vs. $address thing looked funny to me too but I forged ahead with my wrongness all the same!

  • #9
    New to the CF scene
    Join Date
    Jul 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    opps -

    Good eyes everyone, - but I actually caught that when I posted it and went back and made the changes again and still no luck.

    I think the problem isn't with the code but with the includes :

    Code:
    [client 134.241.55.28] PHP Warning:  mysql_connect(): Access denied for user 
    'USER!'@'localhost' (using password: YES) in 
    /home/XXXX/htdocs/xxxx/Services/Registrar/index.php on line 38
    USER! isn't the user I set up inside my dbinfo.inc.php

    This is code is operating inside a crappy cms which has another set of includes which contain a different username and password.

    When I reset my username to equal the one in the CMS include, it tells me the I can not connect to the database.

    What I find odd is that I can post one part of the entry, but not the variable.

    Thanks for your help everyone.
    Last edited by guelphdad; 07-14-2006 at 02:44 PM.

  • #10
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,634
    Thanks
    4
    Thanked 148 Times in 139 Posts
    cyborgoddess, welcome to the coding forums. May I offer two items?

    1) use [ php] and [/php] tags around your php code or [ code] and [/code] tags around plain sql code. Leave the spaces out of course. These tags will help your code stand out more in the forums.

    2) Please, please, please sanitize your data before inputting it into your database. Read in the php manual about using mysql_real_escape_string. If you don't use that then you are opening yourself to sql injection attacks as well as cross browser scripting attacks. You'll thank me later. :-)

  • #11
    New to the CF scene
    Join Date
    Jul 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by guelphdad
    cyborgoddess, welcome to the coding forums. You'll thank me later. :-)
    I'll thank you now, although I'm reading the manual and am not sure I totally understand the proper usage. I'm sure there must be at least 1 thread somewhere here where the finer points are debated, I'm off to find it.


  •  

    Posting Permissions

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