我有一个小问题
我想创建一个脚本,在表中创建一个新的行,如果有一个新的用户和行,更改“点”列为零(0)。
这是我现在的代码:
<?php
header('Content-Type: text/html; charset=Windows-1250');
$firstName = $_POST['firstname'];
$servername = "db.mysql-01.gsp-europe.net";
$username = "xxxxxxxxxx";
$password = "xxxxxxxxxxx";
$dbname = "xxxxxxxxxxx";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// sql to create table
$sql = "UPDATE `member_profile` SET points = points + 1 WHERE user_id = '$firstName'";
if ($conn->query($sql) === TRUE) {
echo "Thingz created successfully";
} else {
echo "Error doing sum thingz: " . $conn->error;
}
$conn->close();
?>
字符串
我需要在立方体:当出现新的user_id($firstName)时,使用此用户名创建新行,并将“points”列从“null”更改为Zero(0)。
谢谢你的时间,我很感激
1条答案
按热度按时间qybjjes11#
如果我理解得很好,你要检查用户是否存在。如果用户是新的,创建新的线与用户0点,如果存在increse点与1。
字符串
记住,我给了你一个想法,代码容易被SQL注入