0

Hey
I created this application, where a user needs to enter a code (which he has bought from me, offline), after filling up the form, he is redirected to a form.
The form checks the mysql database where a coloumn "barcode" has been where all the codes already inserted, if the code matches with a a record, that row is edited else an error is shown.
The problem is, when I try to edit a record with a valid code, it gives me the same error, please help.

The code is :

<?php

include 'connect/connect.php';

if(isset($_POST['sub'])) {
    $bcode = $_SESSION['barcode_v'];
    $iname = $_POST['u_name_f'].' '.$_POST['u_name_l'];
    $name = stripcslashes(strip_tags($iname));
    $email = $_POST['email'];
    $dob =  stripcslashes(strip_tags($_POST['y']."-".$_POST['m']."-".$_POST['d']));
    $insti = stripcslashes(strip_tags($_POST['insti']));
    $phone = $_POST['phone'];
    $course = $_POST['course'];
    $school = $_POST['school'];
    $address = $_POST['address'];

        $sql2 = "SELECT * FROM appthing WHERE barcode='$bcode'";
        $query2 = mysql_query($sql2);
        $row2 = mysql_fetch_array($query2);
        if (!$row2[0])  {
        echo '<div style="background-color:white; color-black;">';
        echo 'Invalid Code '.$bcode.' '.$row2['barcode'];
        echo '</div>';
        } else {

            if (!preg_match('/[^A-Za-z]+/', $name)) {
                if (($_POST['y'] > 1950 && $_POST['y'] < 2005) && ($_POST['m'] > 0 && $_POST['m'] < 13) && ($_POST['d'] > 0 && $_POST['d'] < 32)) {
                    if (!preg_match('/[^0-9]+/', $phone) && strlen($phone) == 10) {
                        $query = "UPDATE appthing SET name=$name, email=$email, dob=$dob, insti=$insti, phone=$phone, school=$school, course=$course, address=$adress WHERE barcode=$bcode";
                        mysql_query($query) or die(mysql_error());

                        $to = $email;
            $subject = "Tafconnect.com";
            $message = "Hello! $name,<br />Registration Details  <br /> Barcode : $bcode <br /> Contact : $phone <br /> DOB : $dob<br /><br />Thank you for registering your application";
            $from = "admin@tafconnect.com";
            $headers = "From:" . $from;
            mail($to,$subject,$message,$headers);

                        echo '<div style="background-color:white; color-black;">';
                        echo $name.', you have been registered! Please check back after 5th August for your interview schedule. Also check your mail for the registered details. Redirecting in 10 seconds';
                        echo '</div>';
                        echo '<meta http-equiv="refresh" content="10;URL=index.php">';
                    } else {
                        echo 'Invalid Phone Number';
                    }
                } else {
                    echo 'Invalid DOB';
                }
            } else {
                echo 'Invalid Name';
            }

        } 
    }

?>
2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by phorce
0

Hey, you could try this:

Hey, you could try this:



    <?php

    include 'connect/connect.php';

    if(isset($_POST['sub'])) {
        $bcode = $_SESSION['barcode_v'];
        $iname = $_POST['u_name_f'].' '.$_POST['u_name_l'];
        $name = stripcslashes(strip_tags($iname));
        $email = $_POST['email'];
        $dob =  stripcslashes(strip_tags($_POST['y']."-".$_POST['m']."-".$_POST['d']));
        $insti = stripcslashes(strip_tags($_POST['insti']));
        $phone = $_POST['phone'];
        $course = $_POST['course'];
        $school = $_POST['school'];
        $address = $_POST['address'];

            $sql2 = "SELECT * FROM appthing WHERE barcode='$bcode'";
            $query2 = mysql_query($sql2);
            if(mysql_affected_rows() != 1)
            {
            echo '<div style="background-color:white; color-black;">';
            echo 'Invalid Code '.$bcode.' '.$row2['barcode'];
            echo '</div>';
            } else {

                if (!preg_match('/[^A-Za-z]+/', $name)) {
                    if (($_POST['y'] > 1950 && $_POST['y'] < 2005) && ($_POST['m'] > 0 && $_POST['m'] < 13) && ($_POST['d'] > 0 && $_POST['d'] < 32)) {
                        if (!preg_match('/[^0-9]+/', $phone) && strlen($phone) == 10) {
                            $query = "UPDATE appthing SET name=$name, email=$email, dob=$dob, insti=$insti, phone=$phone, school=$school, course=$course, address=$adress WHERE barcode=$bcode";
                            mysql_query($query) or die(mysql_error());

                            $to = $email;
                $subject = "Tafconnect.com";
                $message = "Hello! $name,<br />Registration Details  <br /> Barcode : $bcode <br /> Contact : $phone <br /> DOB : $dob<br /><br />Thank you for registering your application";
                $from = "admin@tafconnect.com";
                $headers = "From:" . $from;
                mail($to,$subject,$message,$headers);

                            echo '<div style="background-color:white; color-black;">';
                            echo $name.', you have been registered! Please check back after 5th August for your interview schedule. Also check your mail for the registered details. Redirecting in 10 seconds';
                            echo '</div>';
                            echo '<meta http-equiv="refresh" content="10;URL=index.php">';
                        } else {
                            echo 'Invalid Phone Number';
                        }
                    } else {
                        echo 'Invalid DOB';
                    }
                } else {
                    echo 'Invalid Name';
                }

            } 
        }

    ?>

Haven't tested it, don't have access to your table but it might work! What error does it give? It might be that the variable (barcode) might not be solved. I noticed you don't have session_start() st the top of the page.

Please just try inserting this after you have set the $bcode (So anywhere after it):

<?php

  var_dump($barcode);

 ?>

If this value is NULL then it's not set.

Hope this helps :)

Edited by phorce

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.