Created
May 31, 2016 08:25
-
-
Save s-melnikov/f8718a199d219f635869f283c0958776 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$params = []; | |
if ($_POST["firstname"]) { | |
$params["firstname"] = $_POST["firstname"]; | |
} | |
if ($_POST["lastname"]) { | |
$params["lastname"] = $_POST["lastname"]; | |
} | |
if ($_POST["nickname"]) { | |
$params["nickname"] = $_POST["nickname"]; | |
} | |
if ($_POST["password"]) { | |
$params["password"] = $_POST["password"]; | |
} | |
function create_update_query($params) { | |
$cols = ""; | |
$values = ""; | |
foreach ($params as $key => $val) { | |
$cols .= ($cols ? "," : "") . "`$key`"; | |
$values .= ($values ? "," : "") . "'$val'"; | |
} | |
return "UPDATE ($cols) VALUES ($values)"; | |
} | |
?> | |
<pre><?php echo create_update_query($params)?></pre> | |
<form method="post"> | |
<input type="text" name="firstname" placeholder="First Name"> <br><br> | |
<input type="text" name="lastname" placeholder="Last Name"> <br><br> | |
<input type="text" name="nickname" placeholder="Nickname"> <br><br> | |
<input type="text" name="password" placeholder="Password"> <br><br> | |
<button>Submit</button> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment