camille Posted February 4, 2022 Share Posted February 4, 2022 Quote if(isset($_POST[‘register’])) { $uname = clean($_POST['username']); $pword = clean($_POST['password']); $studno = clean($_POST['studentno']); $fname = clean($_POST['firstname']); $lname = clean($_POST['lastname']); $section = clean($_POST['section']); $status = clean($_POST['status']); $query = "SELECT username FROM students WHERE username = '$uname' && date_joined= NOW()"; $result = mysqli_query($con,$query); if(mysqli_num_rows($result) == 0) { $query = "SELECT studentno FROM students WHERE studentno = '$studno'"; $result = mysqli_query($con,$query); if(mysqli_num_rows($result) == 0) { $query = "INSERT INTO students (username, password, studentno, firstname, lastname, section, status, date_joined) VALUES ('$uname', '$pword', '$studno', '$fname', '$lname', '$section', '$status ',NOW())"; if(mysqli_query($con, $query)) { $_SESSION['prompt'] = "Account registered. You can now log in."; header("location:index.php"); exit; } else { die("Error with the query"); } } else { $_SESSION['errprompt'] = "That student number already exists."; } } else { $_SESSION['errprompt'] = "Username already exists."; } } ?> $query = "SELECT username FROM students WHERE username = '$uname' && date_joined= NOW()"; // how to pud date statement, I'm making attendance system and only this date will be save , it will promp "you are already have attendance", If I change the date then it will be save again. Quote Link to comment https://forums.phpfreaks.com/topic/314500-how-can-i-put-a-condition-with-this-studentno-and-date-at-the-same/ Share on other sites More sharing options...
Phi11W Posted February 4, 2022 Share Posted February 4, 2022 I'm guessing your problem is with this query: 6 hours ago, camille said: $query = "SELECT username FROM students WHERE username = '$uname' && date_joined= NOW()"; You can't "invent" SQL syntax. You have to use what your DBMS supplies to you. The keyword to group two conditions logically and require both to be TRUE is "AND". Whilst the "&&" operator does the same thing in PHP, C# and other languages, MySQL only understands "AND". This bit might cause you problems as well: 6 hours ago, camille said: date_joined= NOW() IIRC, the MySQL Now() function returns the time as well as the date. If you're only storing the date, then the two will never match, as in: '2017-05-28' != '2017-05-28 00:00:00' You'll probably have to do some truncation on the returned value (say, using the DATE() function). Also, read up about Prepared Statements, to protect yourself against SQL Injection Attacks. Obligatory XKCD Reference - Little Bobby Tables. Regards, Phill W. Quote Link to comment https://forums.phpfreaks.com/topic/314500-how-can-i-put-a-condition-with-this-studentno-and-date-at-the-same/#findComment-1593826 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.