Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: alert

  1. #1
    New to the CF scene
    Join Date
    Apr 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    alert

    Hello everyone! I have a small problem here and I would like you to tell me your suggestions. I have created a login form in my php page. The problem is that this form's action takes you to another page. However I want before the form is submitted to check if the username and password exists in my database. To do so I have included an alert javascript message inside php code AND placed everything onSubmit. Can you please help me? If username and password are correct a new page is displayed else (I must use the alert or a fail page). This is how it looks like with the alert but it doesn't work.

    <form name="form1" method="post" action="/loganswer.php" onSubmit="<?php if ($ena!==$user and $dyo!==$pass) {
    echo "<script language=javascript>alert('Please enter a valid username.')</script>";}?>">

  • #2
    Regular Coder devinemke's Avatar
    Join Date
    Dec 2004
    Location
    NYC
    Posts
    443
    Thanks
    0
    Thanked 12 Times in 11 Posts
    you are getting confused between client-side and server-side programming. JS runs on the client. PHP runs on the server. PHP does not know anything about what has been entered into your form until the data is sent to the server. thus, there is no way that PHP can determine if the username exists in the database without first receiving the form data. the traditional requirement is here is that the form be submitted to the server so PHP can access the form data. there are other ways that the client and server can communicate without user intervention, namely AJAX. your question suggests that you are rather new to PHP and as such i would suggest that you not try and tackle AJAX until you have a better understanding of more traditional client/server programming.

  • #3
    New to the CF scene
    Join Date
    Apr 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    me again

    Thank you devinemke for your reply but i really don't know what to do now.
    Please take a look of this and tell me if i can echo a form in another page when submit is pressed. Will this work? Sorry for bothering with stupid questions!


    <?php
    $ena= $_POST[textfield]; //username from home page
    $dyo = $_POST[textfield2]; //password >> >>
    $conn = mysql_connect("localhost", "root", "12365875") or die(mysql_error());
    mysql_select_db("e-kiosk",$conn) or die(mysql_error());
    $sql = "SELECT username,password FROM customers";
    $result = mysql_query($sql,$conn) or die(mysql_error());
    $user = $row['username']; //username from database
    $pass = $row['password']; //password >> >>
    if ($ena!==$user and $dyo!==$pass) {

    }

    ?>


    Can i load a whole php page from php code if the condition above is executed? Can this happen with if (isset($_POST['submit'] and how?

  • #4
    PFM
    PFM is offline
    New Coder
    Join Date
    Mar 2006
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts
    look 2 threads down .. ive replied...

  • #5
    PFM
    PFM is offline
    New Coder
    Join Date
    Mar 2006
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •