Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 9 of 9
  1. #1
    Member mikaelsnavy's Avatar
    Join Date
    Jun 2005
    Location
    Oregon
    Posts
    48
    Member #
    10358
    Hello,
    I'm tring to insert this data into a mysql database. Here's my code:
    Code:
    <?php
    $username="un yes these are correct in my script";
    $password="pswd this one too";
    $database="db and this last one";
    mysql_connect("mysql11.powweb.com",$username,$password);
    @mysql_select_db($database) or die( "Unable to select database");
    
    $sql = "INSERT INTO `Purchases` (`BNAME`, `BADDRESS`, `BADDRESS2`, `BCITY`, `BSTATE`, `BZIP`, `EMAIL`, `PHONE`, `CC`, `EXPMNTH`, `EXPYR`, `CSC`, `SNAME`, `SADDRESS`, `SADDRESS2`, `SCITY`, `SSTATE`, `SZIP`, `TIME`, `APPROVED`) VALUES (\'$sessBNAME\', \'$sessBADDRESS\', \'$sessBADDRESS2\', \'$sessBCITY\', \'$sessBSTATE\', \'$sessBZIP\', \'$sessEMAIL\', \'$sessPHONE\', \'$sessCC\', \'$sessEXPMNTH\', \'$sessEXPYR\', \'$sessCSC\', \'$sessSNAME\', \'$sessSADDRESS\', \'$sessSADDRESS2\', \'$sessSCITY\', \'$sessSSTATE\', \'$sessSZIP\', \'$time\', \'$approved\')"
    mysql_query($sql)
    mysql_close();
    ?>
    The Problem is I need the session varibles to not be their names on the database, but what they represent. I'm having a bit of trouble with that. Every time I try to change the code to make that work, it comes up with an error. Could someone help me figure it out?
    Thanks,
    Mikael

  2.  

  3. #2
    WDF Staff Wired's Avatar
    Join Date
    Apr 2003
    Posts
    7,656
    Member #
    1234
    Liked
    137 times
    Remove the quotes around each var.
    The Rules
    Was another WDF member's post helpful? Click the like button below the post.

    Admin at houseofhelp.com

  4. #3
    Member mikaelsnavy's Avatar
    Join Date
    Jun 2005
    Location
    Oregon
    Posts
    48
    Member #
    10358
    if I do, I get a T_STRING error on line 310
    mysql_query($sql)

    Mikael

  5. #4
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Try a semi-colon at the end of that line.

  6. #5
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    Make sure you're not using any reserved words. For example TIME is likely reserved.

    Also, always use addslashes() when adding a string to a query to avoid SQL injection, and never use quotes for numeric values.
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  7. #6
    Member mikaelsnavy's Avatar
    Join Date
    Jun 2005
    Location
    Oregon
    Posts
    48
    Member #
    10358
    I stuck on the semi-colon,I used addslashes(), but don't what filburt1 means by reversed words. It's still doing the same thing. Thanks for everyone's help,
    Mikael

  8. #7
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Try echoing out $sql and then running that query using phpMyAdmin

  9. #8
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    Actually, for MySQL, it's better to use mysql_real_escape_string to avoid SQL injection. See [phpfunction]mysql_real_escape_string[/phpfunction] for examples and an explanation.

  10. #9
    Member mikaelsnavy's Avatar
    Join Date
    Jun 2005
    Location
    Oregon
    Posts
    48
    Member #
    10358
    I don't really know how, but I fixed it. The ; s where part of the problem and the other part I just went into phpmyadin and did the insert rows. In the names I stuck in the names of my variables amd pasted the code. All I know it works. If anyone wants to know how, here's the code:
    Code:
    <?php
    $username="usr";
    $password="pass";
    $database="dbase";
    mysql_connect("mysql11.powweb.com",$username,$password);
    @mysql_select_db($database) or die( "Unable to select database");
    
    $sql = "INSERT INTO `Purchase` ( `BNAME` , `BADDRESS` , `BADDRESS2` , `BCITY` , `BSTATE` , `BZIP` , `EMAIL` , `PHONE` , `CC` , `EXPMNTH` , `EXPYR` , `CSC` , `SNAME` , `SADDRESS` , `SADDRESS2` , `SCITY` , `SSTATE` , `SZIP` , `TIME` , `APPROVED` ) VALUES ('$sessBNAME', '$sessBADDRESS', '$sessBADDRESS2', '$sessBCITY', '$sessBSTATE', '$sessBZIP', '$sessEMAIL', '$sessPHONE', '$sessCC', '$sessEXPMNTH', '$sessEXPYR', '$sessCSC', '$sessSNAME', '$sessSADDRESS', '$sessSADDRESS2 ', '$sessSCITY', '$sessSSTATE', '$sessSZIP', '$time', '$approved' )";
    mysql_query($sql);
    mysql_close();
    ?>
    Thanks Everyone for your help,
    Mikael


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 03:04 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com