如何让它更新两个表而不仅仅是`accounts`?

时间:2015-06-08 07:17:57

标签: php sql

我正在将它发送到两个表格,而不仅仅是accounts,我想让它进入accountsgroups

<?php

session_start();

if(isset($_POST["submit"])){


if (!(isset($_SESSION['sess_user']) || $_SESSION['sess_user'] == '')) {
header("location:index.php");
}

$dbcon = mysqli_connect('host.com', 'db', 'pass', 'db') or die(mysqli_error($dbcon));

$newname = mysqli_real_escape_string($dbcon, $_POST['newname']);
$newname2 = mysqli_real_escape_string($dbcon, $_POST['newname2']);
$username = mysqli_real_escape_string($dbcon, $_SESSION['sess_user']);

if ($newname <> $newname2) { echo "Your fraternity names do not match.";}

如何让它更新两个表而不仅仅是帐户?

else if ((mysqli_query($dbcon, "UPDATE `accounts` 
                  SET `groupname`='".$newname."', 
                      `founder` ='".$username."' 
                  WHERE `username` = '".$username."'")))

{ 

echo "Your fraternity has been created. You will now be logged out.";

echo "<META http-equiv='refresh' content='3;URL=logout.php'>";

}

else { mysqli_error($dbcon); }

mysqli_close($dbcon);
}
?>

1 个答案:

答案 0 :(得分:0)

试试这个,

$group = mysqli_query($dbconn,"select * from group where founder =".$username);
foreach($group as $row)
if(empty($row['founder']))
{
   echo "You arent in any fraternity. Would you like to <a href='begin'>join one</a>?";  
}else{
   echo "You are in.."
}