-2

I have run it on the local server and it worked perfectly, but when I uploaded it to my web hosting, it stopped working. Basically when I submit the form the browser just keeps loading and when I check the database no data was inserted. I checked my database connection and I was able to connect it but can't get data from it.

This is my php:

<?php
$servername   = "localhost";
$username     = "itclubac_root";
$password     = "*******";
$dbname       = "itclubac_itclub";


$tnp          = 0;
$name         = $_POST['name'];
$email        = $_POST['email'];
$gender       = $_POST['gender'];
$phone        = $_POST['phone'];
$id           = $_POST['id'];
$section      = $_POST['section'];
$skills       = $_POST['skills'];
$interests    = $_POST['interests'];
$expectations = $_POST['expectations'];
$tnp          = $_POST['tnp'];
$ip           = $_SERVER['REMOTE_ADDR'];

if ( $tnp == 0 ) { 
  header('Location: ../../get_involved.php'); 
} else {    
  // Create connection
  $con = new mysqli($servername, $username, $password, $dbname);

  // Check connection
  if ($con->connect_error) {
    die("Connection failed: " . $con->connect_error);
  }
  $query = mysqli_query($con, "SELECT * FROM member_registration WHERE email = '".$email. "'"); 
  if ( mysqli_num_rows($query) > 0 ) {
    header('Location: ../../get_involved.php?status=exist');
  } else {    
    $query = mysqli_query($con, "SELECT * FROM member_registration WHERE college_id = '".$id. "'"); 
    if ( mysqli_num_rows( $query) > 0 ) { 
      header('Location: ../../get_involved.php?status=exist'); 
    } else { 
      $sql = "INSERT INTO member_registration (name, email, gender, phone_no, college_id, section, skills, interests, expectations, ip_address) VALUES ('$name', '$email', '$gender', '+880$phone', '$id', '$section', '$skills', '$interests', '$expectations', '$ip')";
      if ($con->query($sql) === TRUE) {
        header('Location: ../../get_involved.php?status=success'); 
      } 
    } 
  } 
} 
$con->close();
?>

Edit

This is the site: Form Pagehttp://itclub.acc.edu.bd/get_involved.php if you register here, the page will just keep loading. However if you try to access the registration.php directly it sends you to the form page page as I said it to. When I tested it on local, it worked perfectly but after uploading to the host this problem is occurring.

Riyadh
  • 1
  • 5
  • You realize that you forgot the `$` signs for `'skills', 'interests', 'expectations'` – Funk Forty Niner Jul 03 '16 at 01:24
  • Plus, we also don't know whether your POST arrays contain values or not. You've no error checking at all. – Funk Forty Niner Jul 03 '16 at 01:26
  • 1
    [Little Bobby](http://bobby-tables.com/) says ***[your script is at risk for SQL Injection Attacks.](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php)*** Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php). Even [escaping the string](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string) is not safe! – Jay Blanchard Jul 03 '16 at 01:30
  • I won't guess this but I could, yet I won't. Good luck with this. – Funk Forty Niner Jul 03 '16 at 01:31
  • @Fred-ii- I fixed the typo but it still doesn't work :/ – Riyadh Jul 03 '16 at 01:32
  • No one hates you, you just need to fix the syntax errors. Make sure to check your server's error logs. – Jay Blanchard Jul 03 '16 at 01:36
  • @JayBlanchard i fixed but it still doesn't work. – Riyadh Jul 03 '16 at 01:37

1 Answers1

0

I tried to sort your code and maybe the error is related on the of your query,

$sql = "INSERT INTO member_registration (name, email, gender, phone_no, college_id, section, skills, interests, expectations, ip_address) VALUES ('$name', '$email', '$gender', '+880$phone', '$id', '$section', $'skills', '$interests', '$expectations', '$ip')";

Have you notice this part $'skills' of the line? change your code into,

$sql = "INSERT INTO member_registration (name, email, gender, phone_no, college_id, section, skills, interests, expectations, ip_address) VALUES ('$name', '$email', '$gender', '+880$phone', '$id', '$section', '$skills', '$interests', '$expectations', '$ip')";

maybe it help.

Fil
  • 8,225
  • 14
  • 59
  • 85