Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I am trying to add the form input to my xampp localhost myphpadmin database but it no matter how I change it, it doesn't want to work HELP me please.
I wanted a shorter form but the teacher wants all this information into one form and one database -_-
PHP
<?php
$title="STUDENT REGISTER";
include 'header.php';



if(isset($_POST['add']))
{
    $dbhost = 'localhost';
    $username1 = 'root';
    $password1 = '';
    $db = 'qlms-db';
    $conn = new mysqli ( $dbhost,$username1, $password1, $db );
    
    $stuid1 = $_GET['stuid'];
    $query1="SELECT * FROM student_info WHERE stuid= $stuid";
    $result1 = mysqli_query($conn, $query1);
    if(isset($_GET['$stuid']))
    {mysqli_fetch_row($result1)[1];}
    if($result1==0){
    $sFname=$_POST['sFname'];
    $sLname=$_POST['sLname'];
    $semail=$_POST['semail'];
    $sphone=$_POST['sphone'];
    $stuid=$_POST['stuid'];
    $stupass=$_POST['stupass'];
    $sbankname=$_POST['sbankname'];
    $saccname=$_POST['saccname'];
    $siban=$_POST['siban'];
    $sauthorize=$_POST['sauthorize'];
    $sBcountry=$_POST['sBcountry'];
    $sother=$_POST['sother'];
    
    
    
        
             $query12= "INSERT INTO student_info(Fname, Lname, email, phone, stuid, stupass,"
                     . " bankname, accname, iban,authorize,Bcountry,other) "
                     . "VALUES ('$sFname', '$sLname', '$semail', $sphone, '$stuid', '$stupass', "
                     . "'$sbankname', '$saccname', $siban, $sauthorize, '$sBcountry', '$sother')";
                     $res = mysqli_query($conn, $query12);        

            //STEP 6: Check the result
            if($res==1)
            {
                $status = "done";
            }
            else
            {
                $status = "notdone";
            }

            }
        }

?>
<html>
    
    <head>
        <script>
            function stuRegValidation()  
            {
                var stuid = document.registration.stuid;
                var stupass = document.registration.stupass;
                var sFname = document.registration.sFname;
                var sLname = document.registration.sLname;
                var sbankname = document.registration.sbankname;
                var sBcountry = document.registration.sBcountry;
                var sphone = document.registration.sphone;
                var semail = document.registration.semail;
                var saccname = document.registration.saccname;
                var siban = document.registration.siban;
                var sauthorize = document.registration.sauthorize;
                var sother = document.registration.sother;
                var valid=true;
                
                if(stuid == "")
                {
                    valid=false;
                    estuid.style.visibility = "visible";
                }
                else
                {
                    estuid.style.visibility = "hidden";
                }
                
                if(stupass == "")
                {
                    valid=false;
                    estupass.style.visibility = "visible";
                }
                else
                {
                    estupass.style.visibility = "hidden";
                }
                
                if(sFname == "")
                {
                    valid=false;
                    esfname.style.visibility = "visible";
                }
                else
                {
                    esfname.style.visibility = "hidden";
                }
                
                if(sLname == "")
                {
                    valid=false;
                    eslname.style.visibility = "visible";
                }
                else
                {
                    eslname.style.visibility = "hidden";
                }
                
                if(sbankname == "")
                {
                    valid=false;
                    esbankname.style.visibility = "visible";
                }
                else
                {
                    esbankname.style.visibility = "hidden";
                }
                
                if(sBcountry.selected.value() === "Default")
                {
                    valid=false;
                    esBcountry.style.visibility = "visible";
                }
                else
                {
                    esBcountry.style.visibility = "hidden";
                }
                
                if(sphone == "")
                {
                    valid=false;
                    esphone.style.visibility = "visible";
                }
                else
                {
                    esphone.style.visibility = "hidden";
                }
                
                if(semail == "")
                {
                    valid=false;
                    esemail.style.visibility = "visible";
                }
                else
                {
                    esemail.style.visibility = "hidden";
                }
                
                if(saccname == "")
                {
                    valid=false;
                    esaccname.style.visibility = "visible";
                }
                else
                {
                    esaccname.style.visibility = "hidden";
                }
                
                if(siban == "")
                {
                    valid=false;
                    esiban.style.visibility = "visible";
                }
                else
                {
                    esiban.style.visibility = "hidden";
                }
                
                if(sauthorize == "")
                {
                    valid=false;
                    esauthorize.style.visibility = "visible";
                }
                else
                {
                    esauthorize.style.visibility = "hidden";
                }
                
                if(valid)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            
        </script>
    </head>
    <body>
        <div id="wrapper">
        <div id="inside">
        <div class="row"><!--second row-->
            <div class="reg_col">
                <?php if(isset($_GET['status']) && $_GET['status']==="done") { ?>
                <p>Item added successfully to the Database</p>
                    <?php } else {if(isset($_GET['status']) && $_GET['status']==="notdone") { ?>
                <p>Sorry Item was not added</p>
                <?php } else { ?>
                <form name='registration' onSubmit="return stuRegValidation();" method="POST" action="stuReg.php">
                    <h3>PERSONAL INFORMATION</h3>
                    <ul>
                        <li><label for="sFname">First Name:</label></li>
                        <li><input type="text" name="sFname" /></li>
                        <span class="error" id="esfname">* Required </span>
                        <li><label for="sLname">Last Name:</label></li>
                        <li><input type="text" name="sLname"/></li>
                        <span class="error" id="eslname">* Required </span>
                        <li><label for="semail">Email:</label></li>
                        <li><input type="email" name="semail" /></li>
                        <span class="error" id="esemail">* Required </span>
                        <li><label for="sphone">Phone Number:</label></li>
                        <li><input type="number" name="sphone"/></li>
                        <span class="error" id="esphone">* Required </span>
                    </ul>
                        <br>
                    <h3>LOGIN INFORMATION</h3>
                    <ul>
                        <li><label for="stuid">Student id:</label></li>
                        <li><input type="text" name="stuid" /></li>
                        <span class="error" id="estuid">* Required </span>
                        <li><label for="stupass">Password:</label></li>
                        <li><input type="password" name="stupass" /></li>
                        <span class="error" id="estupass">* Required </span>
                    </ul>
                        <br>
                    <h3>PAYMENT INFORMATION</h3>
                    <ul>
                        <li><label for="sbankname">Bank Name:</label></li>
                        <li><input type="text" name="sbankname" /></li>
                        <span class="error" id="esbankname">* Required </span>
                        <li><label for="saccname">Name on the Account:</label></li>
                        <li><input type="text" name="saccname" /></li>
                        <span class="error" id="esaccname">* Required </span>
                        <li><label for="siban">IBAN Number:</label></li>
                        <li><input type="number" name="siban"/></li>
                        <span class="error" id="esiban">* Required </span>
                        <li><label for="sauthorize">Authorization Code:</label></li>
                        <li><input type="number" name="sauthorize"/></li>
                        <span class="error" id="esauthorize">* Required </span>
                        <li><label for="sBcountry">Bank Branch:</label></li>
                        <li><select name="sBcountry">
                                <option selected="" value="Default">(Please select a Bank Branch)</option>
                                <option value="AF">Australia</option>
                                <option value="AL">Canada</option>
                                <option value="DZ">India</option>
                                <option value="AS">Suadi Arabia</option>
                                <option value="AD">USA</option>
                            </select>
                            <span class="error" id="esBcountry">* Required </span>
                        </li>
                    </ul>
                        <br>
                    <h3>OTHER INFORMATION</h3>
                    <ul>
                        <li><label for="sother">Where did you hear about us:</label></li>
                        <li><input type="radio" name="sother" value="Friend" /><span>Friend</span></li>
                        <li><input type="radio" name="sother" value="Social" /><span>Social Media</span></li>
                        <li><input type="radio" name="sother" value="news" /><span>Newspaper</span></li>
                        <li><input type="radio" name="sother" value="ads" /><span>Advertisement</span></li>
                        <li><input type="radio" name="sother" value="other" /><span>Other</span></li>
                    </ul>
                        <br>
                    <input type="submit" name="submit" value="Submit"/>
                </form>
                 <?php } } ?>
            </div>
        </div>
        </div>    
        <?php include 'footer.php'; ?>
        </div>
    </body>
</html>


What I have tried:

i tried using sessions,, cookies, connecting by statement and adding it to the query but nothing seems to be working
Posted
Updated 5-May-17 19:57pm
Comments
CHill60 4-May-17 11:19am    
"it doesn't want to work" - what actually happens?
ZurdoDev 4-May-17 11:56am    
You need to debug it and see what is happening and where it is breaking down.
MarkNopfler 5-May-17 13:39pm    
Maybe your error wouldn´t be in your code, can be in your database.
Anna Ar 6-May-17 3:54am    
what actually happens is that the form works, the database connection works, but the values inserted in the form are not inserted in the database

First of all debug your code, you will sure resolve your issue by yourself.

I don't know PHP but I have a doubt

Your insert statement does not contain actual values of a variables. It is just a normal string that you are passing to execute.

$query12= "INSERT INTO student_info(Fname, Lname, email, phone, stuid, stupass,"
                    . " bankname, accname, iban,authorize,Bcountry,other) "
                    . "VALUES ('$sFname', '$sLname', '$semail', $sphone, '$stuid', '$stupass', "
                    . "'$sbankname', '$saccname', $siban, $sauthorize, '$sBcountry', '$sother')";


There are variables like '$sFname', '$sLname'... etc

From where you are passing values to a variable.

From where your insert command will find the exact values which are you are filling in the variables ?
 
Share this answer
 
v2
Comments
Anna Ar 6-May-17 3:50am    
I have used the names of the inputs from the html and turned them to variables in php and then used them as insert values
Nirav Prabtani 6-May-17 3:59am    
Yes that I can see but in insert statement your variable values are not applicable as you have generated whole query as a string it self
Try to verify your database.
 
Share this answer
 
Comments
Anna Ar 6-May-17 3:52am    
My database is working and my connections are fine
when I go to the connection page I ask the php to write success if the connection is alright and it does write it

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900