I’m new to programming and PHP. I’d like to use onclick from HTML to log in to PHP.
This is my code:
<script type="text/javascript">
function Log(){
<!-- This is Log in script -->
<?php
$Logged = 0
$pass = $_GET["pass"];
$uid = $_GET["uid"];
$click = $_GET["con"]
if($pass=123 && $uid=xxx| && $click=1){
$Logged=1
break
} else {
$Logged=0
}
?>
}
</script>
And there HTML button:
<input type="button" onclick="$Logged++" value="Log in"
style="color: #000000; background-color: #7200E3;
width: 80px; height: 40px; border-style: solid;
border-color: #00E372; border-width: 0.1cm"
/>
Please help me 🙂
You are throwing two different things in one jar here.
Since this seams like you want to create a simple Log-In Script, why don’t you use a normal Hyperlink to your PHP-site which offers a form to log in. There are hundreds of tutorials out there which show you the way.
Also, what you “created” is not save to use, since you’re using PHP to write a JavaScript function. The JavaScript-code and your password (as you simply add it to the JS-function in clear text) can be read by simply displaying the sites source-code.
Also, using something like
onclick="$Logged++"to increase a PHP-Variable does not work. Again, PHP runs on the server and not in your Browser.If you seriously want to start with PHP (and create secure and save pages) you should conceder reading a whole book for the startup. A great collection can be found here.