php

[php]

Jotorres Login Form <?php function Update(){ // Grab User submitted information $UserName = $_POST["UserName"]; $Password = $_POST["Password"];

// Connect to the database
$con = mysql_connect(“localhost”,“root”);
// Make sure we connected succesfully
if(! $con)
{
die(‘Connection Failed’.mysql_error());
}

// Select the database to use
mysql_select_db(“first”,$con);

$result = mysql_query(“SELECT UserName,Password FROM login WHERE UserName=@UserName AND Password=@Password”);

$row = mysql_fetch_array($result);

if($row[“UserName”]==$UserName && $row[“Password”]==$Password){
echo “You are a validated user.”;}
else{
echo “Sorry, your credentials are not valid, Please try again.”;}

}
?>

            <td><input type="submit" value="Submit" onClick="Update" />
        </tr>
    </table>
[/php] This is my code.No any errors.But it doesn't work
UserName
Password

[php]

Jotorres Login Form <?php function Update(){ // Grab User submitted information $UserName = $_POST["UserName"]; $Password = $_POST["Password"];

// Connect to the database
$con = mysql_connect(“localhost”,“root”);
// Make sure we connected succesfully
if(! $con)
{
die(‘Connection Failed’.mysql_error());
}

// Select the database to use
mysql_select_db(“first”,$con);

$result = mysql_query(“SELECT UserName,Password FROM login WHERE UserName=@UserName AND Password=@Password”);

$row = mysql_fetch_array($result);

if($row[“UserName”]==$UserName && $row[“Password”]==$Password){
echo “You are a validated user.”;}
else{
echo “Sorry, your credentials are not valid, Please try again.”;}

}
?>

            <td><input type="submit" value="Submit" onClick="Update" />
        </tr>
    </table>
[/php] please put code in code tags push the php or # tags

now i will ask what is it doing

UserName
Password

So much wrong here, but here’s a couple things:

[ul][li]@-sign is used for error suppression and is rarely needed. You can’t use it instead of $ in your sql query. I also recommend escaping your user input.
[/li]
[li]mysql-extension is deprecated from 5.5.0. I recommend just learning to use PDO.[/li]
[li]It’s a good idea to encrypt your passwords[/li]
[li]You can’t call your Update-function directly from html [/li]
[li]There’s no point checking for usename/password php-side when you already do it mysql side. Just check if number of rows returned is more than 0. [/li][/ul]

I think he mixed up the languages. But to fix it, lot of it needs to be re-organized.
[php]

<?php mysql_connect("localhost","root", ''); mysql_select_db("first"); if(isset($_POST['submit'])) { $UserName = mysql_real_escape_string($_POST["UserName"]); $Password = mysql_real_escape_string($_POST["Password"]); $result = mysql_query("SELECT UserName,Password FROM login WHERE UserName='$UserName' AND Password='$Password'") or die(mysql_error()); if(mysql_num_rows($result) != 0) { $msg = "You are a validated user."; } else { $msg = "Sorry, your credentials are not valid, Please try again."; } } ?> Jotorres Login Form <?=$msg?>
UserName
Password
[/php]That should work.

It looks like he was trying to make a javascript but got it confused with a php script.

Sponsor our Newsletter | Privacy Policy | Terms of Service