Jump to content

Basic Question - How do I insert into two tables, one after the other?


ramone_johnny

Recommended Posts

Sorry guys, I'm relatively new at PHP, and as I've never done this before, I need to ask.

 

How do I correctly format the syntax below in order to insert to 2 separate tables, one after the other?

$r=query_wrapper("SELECT * FROM tblmembers WHERE mem_email = ?",$mem_email);
$rstDBEdit=mysql_fetch_assoc($r);

if($rstDBEdit)
redirect("/message.php?message=already_a_member");

$a["mem_name"] = $mem_name;
$a["mem_password"] = $mem_password;
$a["mem_email"] = $mem_email;

....

query_wrapper("INSERT INTO tblmembers SET ?%",$a);

$mem_ID = mysql_insert_id();

----------------------------------------------------

$r=query_wrapper("SELECT * FROM tblshare_adverts");
$rstDBEdit=mysql_fetch_assoc($r);

$a["share_available"] = $share_available;
$a["share_header"] = $share_header;
$a["share_description"] = $share_description;

....

query_wrapper("INSERT INTO tblshare_adverts SET ?%",$a);

$share_ID = mysql_insert_id();
Link to comment
Share on other sites

Okay well whats your issue because you've not really specified one? And query_wrapper is doing a fair amount of work so we'd need to see it to ensure its correctly formatting the query.

Link to comment
Share on other sites

Sorry, here's the query_wrapper stuff.

//
// sql_placehloder() + mysql_query().
//
function query_wrapper()
{
    global $linkScript;

    $args = func_get_args();
    $tmpl = array_shift($args);

    if(is_resource($tmpl))
    {
        $link=$tmpl;
        $tmpl = array_shift($args);
    }
    else
        $link=$linkScript;

    $query = sql_placeholder_ex($tmpl, $args, $error);
    if ($query === false) {
        $error = "Placeholder substitution error. Diagnostics: \"$error\"";
        if (function_exists("debug_backtrace")) {
            $bt = debug_backtrace();
            $error .= " in ".@$bt[0]['file']." on line ".@$bt[0]['line'];
        }
        trigger_error($error, E_USER_ERROR);
        return false;
    }
    $r = mysql_query($query,$link);
    if (!$r) {
        echo "<hr>$query<hr>";
        $error = "Mysql_query error: ".mysql_error();
        if (function_exists("debug_backtrace")) {
            $bt = debug_backtrace();
            $error .= " in ".@$bt[0]['file']." on line ".@$bt[0]['line'];
        }
        trigger_error($error, E_USER_ERROR);
    }
    return $r;
}
?>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.