Sending data from form to database

Posted December 11, 2016 4k views
MySQLPHPLAMP StackUbuntu 16.04

I don’t know why, but everything works fine on my local environment, but when i upload to D.O, my forms don’t seem to send data to my database. my connection is correct . is it because i tend to use action="<?php echo $_SERVER['PHP_SELF']?>" ? is there any alternative? i’m freaking out because i used throughout my whole project…

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
2 answers

Can you share the rest of your script? The first step in debugging this type of issue would be to look for anything recorded in your error log /var/log/apache2/error.log

Using this environment variable to set the form target shouldn’t be a problem as long as php is functioning properly.

  <form class="form awesome-form"  action="<?php echo $_SERVER['PHP_SELF']?>" method="post">

                    <section class="form-group col-md-12">

                    <input type="text" class="form-control" name="hostel-name" id="hostel-name" autocomplete="off"  required>
                    <label> Name</label>

                    <section class="form-group col-md-12">
                    <input type="email" class="form-control" name="email" id="email" autocomplete="off" required>

                    <section class="form-group col-md-12">

                    <input type="email" class="form-control" name="conf-email" id="conf-email" autocomplete="off"  required>
                    <label>Confirm Email</label>

                    <section class="form-group col-md-12">

                    <input type="password" class="form-control" name="password" id="password" autocomplete="off"  required>

                    <section class="form-group col-md-12">
                        <button class="form-control " name="register" id="register-btn" type="submit" ><span class="fa fa-paper-plane"> Sign Up</span></button>
                    <section class="form-group">
                        <ul class="list-inline" style="display: block;">
                            <li class="pull-left"> Have an Account?</li>
                            <li class="pull-right"><a href="login.php">Log in!</a></li>


for the insert script


 include 'database/connection.php';
 //new block added
 if($name="" or $email=="" || $password=="" || $confemail==""  ){echo '<p class="alert alert-danger text-center">Please Make Sure All Fields Are Filled <span class="close pull-right"><span class="close pull-right"> <a href="#" >&times;</a></span></p>';}

   $query=$dbc->query("select email from users where email='$email'");

 if($result=$query->fetch(PDO::FETCH_NUM)!=0){ echo '
<p class="alert alert-danger text-center">We already have someone with that email <span class="close pull-right"><span class="close pull-right"> <a href="#" >&times;</a></span></p>'; }elseif($result=$query->fetch(PDO::FETCH_NUM)==0){ 
  $data_result=$dbc->query("insert into users(hostel_name,email,password,confirm_code,user_id) values('$hostel_name','$email','$password','$confirm_code','$user_id')");


       echo '<p class="alert alert-success text-center error-message"> You\'re almost there!  Check your inbox to activate your account.</p>';


echo '<p class="alert alert-danger text-center error-message">Something is not right <span class="pull-right close"> <a href="#" >&times;</a></span></p>';}



i know am exposed to sql injection but i just want to see the data inserted first