PHP新特性。如果這個問題很荒謬,請原諒我。無論如何,我有一些PHP將數據發送到數據庫。下面是它的一些:如何觸發這兩個?
else {
$sql = "INSERT INTO users (username, firstname, lastname, password)
VALUES ('$username', '$firstname', '$lastname', '$pass')";
$sql = "CREATE TABLE $username (
day VARCHAR(10) NOT NULL,
P1 VARCHAR(10) NOT NULL,
P1_WORK VARCHAR(30) NOT NULL,
P2 VARCHAR(10) NOT NULL,
P2_WORK VARCHAR(30) NOT NULL,
P3 VARCHAR(10) NOT NULL,
P3_WORK VARCHAR(30) NOT NULL,
P4 VARCHAR(10) NOT NULL,
P4_WORK VARCHAR(30) NOT NULL,
P5 VARCHAR(10) NOT NULL,
P5_WORK VARCHAR(30) NOT NULL,
P6 VARCHAR(10) NOT NULL,
P6_WORK VARCHAR(30) NOT NULL
)";
if (mysqli_query($con, $sql)) {
echo "okay";
} else {
echo "error";
}
}
當我運行此,我僅實現第二$sql=
將開展,因爲我在同一個實例定義$sql
兩次。我怎樣才能做到這一點,所以這些事件都是一舉觸發的?謝謝!
編輯:全碼
<?php
echo error_reporting(E_ALL);
$username = strval($_GET['enteredUserName']);
$pass = strval($_GET['enteredPassword']);
$firstname = strval($_GET['enteredFirstName']);
$lastname = strval($_GET['enteredLastName']);
$con = mysqli_connect('localhost','XXXX','XXXX','XXXX');
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
} else {
$sql="SELECT * FROM users WHERE username = '".$username."'";
$result = mysqli_query($con,$sql);
if ($result->num_rows > 0) {
echo "pop";
} else {
$sql = "INSERT INTO users (username, firstname, lastname, password)
VALUES ('$username', '$firstname', '$lastname', '$pass') ";
$sql = "CREATE TABLE $username (
day VARCHAR(10) NOT NULL,
P1 VARCHAR(10) NOT NULL,
P1_WORK VARCHAR(30) NOT NULL,
P2 VARCHAR(10) NOT NULL,
P2_WORK VARCHAR(30) NOT NULL,
P3 VARCHAR(10) NOT NULL,
P3_WORK VARCHAR(30) NOT NULL,
P4 VARCHAR(10) NOT NULL,
P4_WORK VARCHAR(30) NOT NULL,
P5 VARCHAR(10) NOT NULL,
P5_WORK VARCHAR(30) NOT NULL,
P6 VARCHAR(10) NOT NULL,
P6_WORK VARCHAR(30) NOT NULL
)";
if (mysqli_query($con, $sql)) {
echo "okay";
} else {
echo "error";
}
}
mysqli_close($con);
}
?>
'mysqli_query($ con,$ sql1); mysqli_query($ con,$ sql2)' –
U對兩個不同的查詢使用相同的變量。使用不同的變量 –
我不知道我完全理解這將被插入。如果(mysqli_query($ con,$ sql)&& mysqli_query($ con,$ sql2))''我會將我的完整代碼添加到問題@u_mulder – Caspar