PHP事务没有回滚

时间:2017-05-10 17:13:25

标签: php mysql

我正在使用php事务插入我的数据库中的两个表(雇主和地址)。当我将信息插入表单时,除了没有信息插入地址表之外,所有内容都按预期发生。我不明白为什么会这样。如果有一个错误阻止信息被插入表中,如果它没有回滚并由于这个if语句而抛出某种错误:

select one.value_one, coalesce(two.value_two, one.value_two)

我的表格html是:

if(!$conn->commit()){

  // rollback if commit fails
  $conn->rollback();

  echo "failure";
  echo mysqli_error($conn);
}

我的php代码是:

<form id="register" action='DB/employerRegistration.php' method='post'>
          <legend>Register</legend>
          <label for="name">Personal Details*</label>
          <input type='text' name='name' id="name" maxlength="100" placeholder="Full Name"/>
          <input type='text' name='email' maxlength="100" placeholder="Email Address"/>
          <input type='text' name='companyName' maxlength="100" placeholder="Company Name"/>
          <label for="companyAddress">Company Address*</label>
          <input type='text' name='addressLine1' id="companyAddress" maxlength="100" placeholder="Adress Line 1"/>
          <input type='text' name='addressLine2' maxlength="100" placeholder="Adress Line 2"/>
          <input type='text' name='addressLine3' maxlength="100" placeholder="Adress Line 3"/>
          <input type='text' name='town' maxlength="100" placeholder="Town/City"/>
          <input type='text' name="county" maxlength="100" placeholder="County"/>
          <input type='text' name='postcode' maxlength="100" placeholder="Postcode"/>
          <label for="password">Password*</label>
          <input type='password' name='password' id="password" maxlength="100" placeholder="Password"/>
          <input type='password' name='confirmPassword' id="confirmPassword" maxlength="100" placeholder="Confirm Password"/>
          <input type='submit' name='Submit' value='Submit' />
        </form>

0 个答案:

没有答案