I am new to PHP and appreciate all the help I receive.
OK so I now understand that simply resubmitting a form does not over write any previous data on the database what was ending before resubmitting the for.
I was wondering how I would set it so that the database updates the data that needs updating with the new data.
My form works 100% fine other then a few things I would like to iron out and this is one of them. I have looked around google and everything but I can't make sense of anything that I find as all answers are different and there is not a set answer to my question.
if(isset($_POST["signupbtn"])) {
if ($log_username) {
/// getting data from submitted form into local variables
$x = preg_replace('#[^a-z 0-9]#i', '', $_POST['xbox']);
$p = preg_replace('#[^a-z 0-9]#i', '', $_POST['psn']);
$s = preg_replace('#[^a-z 0-9]#i', '', $_POST['steam']);
$ip = preg_replace('#[^0-9.]#', '', getenv('REMOTE_ADDR'));
// DUPLICATE DATA CHECKS FOR GAMER PROFILES
$sqli = "SELECT username FROM player WHERE xbox='$x' LIMIT 1";
$query = mysqli_query($db_conx, $sqli);
$x_check = mysqli_num_rows($query);
// -------------------------------------------
if ($x_check > 0){
echo "Xbox Gamer-Tag already linked to a user on this website";
exit();
} else if (is_numeric($x[0])) {
echo 'Xbox Gamer-Tag cannot begin with a number';
exit();
}
$sqli = "SELECT username FROM player WHERE psn='$p' LIMIT 1";
$query = mysqli_query($db_conx, $sqli);
$p_check = mysqli_num_rows($query);
// -------------------------------------------
if ($p_check > 0){
echo "PSN User already linked to a user on this website";
exit();
} else if (is_numeric($p[0])) {
echo 'PSN User cannot begin with a number';
exit();
}
$sqli = "SELECT username FROM player WHERE steam='$s' LIMIT 1";
$query = mysqli_query($db_conx, $sqli);
$s_check = mysqli_num_rows($query);
// FORM DATA ERROR HANDLING
if ($s_check > 0){
echo "Steam account already linked to a user on this website";
exit();
} else if (is_numeric($s[0])) {
echo 'Steam account cannot begin with a number';
exit();
} else { $sqli = "INSERT INTO player (id, username, xbox, psn, steam, ip, created, lastupdated, notecheck)
VALUES ('$id','$log_username','$x','$p','$s','$ip',NOW(),NOW(),NOW())";
$query = mysqli_query($db_conx, $sqli);
echo "Gamer Profiles Updated";
}
exit();
if (!file_exists("p_player/$log_username")) {
mkdir("p_player/$log_username", 0755);
}
}
}
As you can see that is my current php what is working fine except the fact that I can't update information that has been submitted.
Thank you for reading this and I hope someone is able to provide me with the knowledge that is need to preform this task.
Thanks once again for your time it has taken for you to read this post.
$s_checkis not empty? When$p_checkis not empty? At a different time?WHERE column='data'and if it's not equal to it, update. Correct? You could also use a query inside a conditional statement to check whether the data going in is the same as an existing one.DELETE, updating it will just overwrite what's presently in there, IF it needs to be replaced. You could also make use of theREPLACE INTOfunction.