Jump to content

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