php html submit,html - PHP form submiting - Stack Overflow

I have a form with four values, player1, player2, awayTeam, and homeTeam.

After checking if values are not empty it does not want to send results to database. I am not sure why it does not want to submit.

There are as well two random numbers which will be compared and based on if num1 > num2 record should be submitted.

$link = mysqli_connect("localhost","test", "passowrd", "test" );

if (mysqli_connect_error()) {

die ("DB has not been connected");

}

// create two random numbers

$Num1 = rand();

$Num2 = rand();

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

$playerOne = mysqli_real_escape_string ($link, $_POST['playerOne']);

$playerTwo = mysqli_real_escape_string ($link, $_POST['playerTwo']);

$awayTeam = mysqli_real_escape_string ($link, $_POST['awayTeam']);

$homeTeam = mysqli_real_escape_string ($link, $_POST['homeTeam']);

//check if player one is empty

if (empty($playerOne)) {

echo "Game Creator PSN required!" . "
";

}

//check if player two is empty

if (empty($playerTwo)) {

echo "Second Player PSN required!";

}

} else {

//compare two numbers

if ($Num1 > $Num2) {

$sql = "INSERT INTO randomizer (playerOne, playerTwo, awayteam, homeTeam) VALUES (' $playerOne', '$playerTwo', '$awayTeam', '$homeTeam')";

if ($link->query($sql) === true) {

echo "Record Added Sucessfully";

} else {

echo "There was a problem";

}

} else {

$sql = "INSERT INTO randomizer (playerOne, playerTwo, awayteam, homeTeam) VALUES (' $playerTwo', '$playerOne', '$awayTeam', '$homeTeam')";

if ($link->query($sql) === true) {

echo "Record Added Sucessfully";

} else {

echo "There was a problem";

}

}

}

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值