SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2010
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    doubt -mysqli+php function

    hi

    i have this: function insert ()

    the function insert data in the table users and sent an email.

    I need to terminate a previous state before create another one, correct?
    so, i need to store the activation link in another table, the activationLinks table.

    i can make something like this? i think the code below doesn't work.


    Code MySQL:
        ($sql = $db -> prepare("INSERT INTO users, activationLinks (username, email, password) (link) VALUES (?, ?, ?) (?)"));

    basically the question, is that i need store data in two different tables, but in the same function.
    thanks

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,067
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    You can only INSERT in to one table at a time, so if you need to insert in to two tables you need two queries (or rather: if you need to insert in to n distinct tables you need n queries)

    PHP Code:
    ($sql $db -> prepare("INSERT INTO users (username, email, password) VALUES (?, ?, ?)"));
    (
    $sql2 $db -> prepare("INSERT INTO activationLinks (link) VALUES (?)")); 
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  3. #3
    SitePoint Enthusiast
    Join Date
    Sep 2010
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks.

    And i need two ? or it is possible join this?
    Code MySQL:
    			$sql -> bind_param('sss', $name, $email, $hash);
     
    			$sql -> execute();

    and
    Code MySQL:
    $sq -> bind_param('s', $linkHash);
     
    			$sq -> execute();

  4. #4
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,067
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    No you can't join it. You really need two
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  5. #5
    SitePoint Enthusiast
    Join Date
    Sep 2010
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks ScallioXTX !


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
  •