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 5 of 5
  1. #1
    Regular Coder
    Join Date
    May 2010
    Posts
    140
    Thanks
    7
    Thanked 0 Times in 0 Posts

    get variable from a seperate database

    I need to retrieve a unique id from a seperate database based on there username and password and insert it in this table:

    PHP Code:
    //Make variable for data to be inputed 
    $foo_name $_POST[foo_name'];
    $email_contact = $_POST['
    email_contact'];
    $category = $_POST['
    category'];
    $foo_site = $_POST['
    fo_site']; 
    $description = $_POST['
    description'];
    $foo_url = $_POST['
    foo_url'];
    $license = $_POST['
    license'];
    $price = $_POST['
    price'];
    $dated = date("d-M-Y");

    //make the connection to the database
    $connection = @mysql_connect($server, $dbusername, $dbpassword) or die(mysql_error());
    $db = @mysql_select_db($db_name,$connection)or die(mysql_error());

    //Then you choose the table to save info on 

    $sql = "INSERT INTO user_foo (foo_name, email_contact, category, foo_site, description, foo_url, license, price, dated) VALUES ('
    $foo_name', '$email_contact', '$category', '$foo_site', '$description', '$foo_url', '$license', '$priceCURDATE())"; 
    How can i modify this query for the other database.

  • #2
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,535
    Thanks
    45
    Thanked 259 Times in 256 Posts
    First, if thats a direct copy/paste, add the first apostrophe in the first var so it actually opens properly.

    Second, just create a second connection, assigned to a different variable, then use that variable in your mysql_query.

    http://php.net/manual/en/function.mysql-query.php

    The var im referring to is the second one, the link_identifier.

  • #3
    Regular Coder
    Join Date
    May 2010
    Posts
    140
    Thanks
    7
    Thanked 0 Times in 0 Posts
    PHP Code:
    $foo_name $_POST['foo_name']; 
    That was a mistake do to copy and paste and highlighting over the correct variable and writing in foo in its place. Its correct on the actual code.

    Add a second conn like this

    PHP Code:
    $connection = @mysql_connect($server$dbusername$dbpassword) or die(mysql_error());
    $db = @mysql_select_db($db_name,$connection)or die(mysql_error());
    $db1 = @mysql_select_db($db_name,$connection)or die(mysql_error());
    $result = @mysql_query("SELECT username, memberid, FROM authorize"$db1); 
    Instead of username and password, i am just using there username. I basically want to match up there post which as a unique id to there assigned memberid in another database.


    Using this code, it works, but in the memberid column, it puts in 0 and not the memberid from the other database
    PHP Code:
    //make the connection to the database
    $connection = @mysql_connect($server$dbusername$dbpassword) or die(mysql_error());
    $db = @mysql_select_db($db_name,$connection)or die(mysql_error());
    $db1 = @mysql_select_db($db_name,$connection)or die(mysql_error());
    $result = @mysql_query("SELECT username, memberid, FROM authorize"$db1);


    //Then you choose the table to save info on 

    $sql "INSERT INTO user_foo (foo_name, email_contact, category, foo_site, description, 

    foo_url, license, price, memberid, dated) VALUES ('$foo_name', '$email_contact', '$category', 

    '$foo_site', '$description', '$foo_url', '$license', '$price', '$memberid', CURDATE())"

    Last edited by twobyfour; 06-26-2010 at 06:33 PM.

  • #4
    Regular Coder
    Join Date
    May 2010
    Posts
    140
    Thanks
    7
    Thanked 0 Times in 0 Posts
    i am getting this error

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''923249916', dated) VALUES ('xxxxxxxxxxx', 'xxxxxxxxxx', '1', 'xxxxxxxxx', 'xxxx' at line 1

    using this code

    PHP Code:
    $db = @mysql_select_db($db_name,$connection)or die(mysql_error());
    $db1 = @mysql_select_db($db_name,$connection)or die(mysql_error());
    $result = @mysql_query("SELECT username, memberid FROM authorize WHERE username = '".$_SESSION['username']."' AND memberid = '".$_SESSION['memberid']."'"$db1);


    //Then you choose the table to save info on 

    $sql "INSERT INTO user_foo (foo_name, email_contact, category, foo_site, description, foo_url, license, price, '".$_SESSION['memberid']."', dated) VALUES('$foo_name', '$email_contact', '$category', '$foo_site', '$description', '$foo_url', '$license', '$price', '$memberid', CURDATE())"
    I need the memberid (923249916) to be inserted into '$memberid'

  • #5
    Regular Coder
    Join Date
    May 2010
    Posts
    140
    Thanks
    7
    Thanked 0 Times in 0 Posts
    i fixed it, it works now

    added this line after the second conn query
    PHP Code:
    $memberid $_SESSION['memberid']; 
    //Then you choose the table to save info on

    PHP Code:
    $sql "INSERT INTO user_foo (foo_name, email_contact, category, download_site, description, foo_url, license, price, memberid, dated) VALUES ('$foo_name', '$email_contact', '$category', '$foo_site', '$description', '$site_url', '$license', '$price', '$memberid', CURDATE())"


  •  

    Posting Permissions

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