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();

Well when I run this, I get an error that indicates that its pulling those a$ values the second time round. My best guess was that I might need to change the second query to use something like b$, but that would be a complete guess.

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;
}
?>

You defined the query_wrapper() function without any arguments but when you call it you inserted two.

 

Can you explain that?

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.