mysql - PHP register form not connecting to database -
i have simple user registration form , external connection script strange results. page register.php shows form fine, seems display entire connection string before form? throws errors in relation connection variable '$dbcon' (i have commented line @ happens) here register.php code:
<?php session_start(); require "connect.php"; if (isset($_session['username'])){ header("location: members.php"); } if (isset($_post['submit'])) { $user = $_post['user']; $pass = $_post['pass']; $rpass = $_post['rpass']; $fname = $_post['fname']; $lname = $_post['lname']; if ($user == "" || $pass == "" || $rpass == "") { echo "please fill fields"; } else { if ($pass != $rpass) { echo "passwords not match"; } else { //this errors found $query = mysqli_query($dbcon, "select * users username = '$user' ") or die ("cannot query table"); $row = mysqli_num_rows($query); if($row == 1) { echo "this username taken"; } else { $add = mysqli_query($dbcon, "insert users (id, firstname, lastname, username, password, admin) values (null, '$fname', '$lname', '$user', '$pass', '$admin') ") or die ("cant insert data"); echo "successfully added user!"; } } } } ?>
and here connection file 'connect.php' (the $dbcon string 1 prints out??)
$server = 'localhost'; $user = 'root'; $pass = ''; $dbname = 'bodgett'; $dbcon = mysqli_connect($server, $user, $pass, $dbname)or die("can not connect server.");
specifically, error 'notice: undefined variable: dbcon in c:\webserver...\register2.php' can suggest why doesn't recognize variable?
probably wrong filename (maybe file isn't called connect.php) or wrong file extension? (html instead of .php)
i copied code, , works me. aswell don't see php start , closing tags.
Comments
Post a Comment