I am trying to make a page where people can register to be users on my site. the connection is fine (labled as $cxn here) so the problem must be with the query. I've tried typing in queries with the exact same syntax into mySQL, so I must have some problem with the PHP here. can someone help me out? Also, the part that shows the mysqli_error isn't working for some reason either. //the variables $username = $_GET['username']; $password = $_GET['password']; $email = $_GET['email']; $first = $_GET['firstname']; $last = $_GET['lastname']; $date = date("Y-m-d"); //checks to make sure username isn't taken $query = "Select * from $t_user WHERE username = $username"; $result = mysqli_query($query,$cxn); if($result){ echo "Username is already taken!"; $_GET = null; echo "<a href=\"register.php\"> Try Again? </a>"; } //adds them to database. else{ $query = "INSERT INTO users (username, password, email, first_name, last_name, create_date) VALUES ('$username', '$password', '$email', '$first', '$last', '$date')"; $result = mysqli_query($query,$cxn); if($result){ echo "Welcome to Athens Bar Hopper!"; } else{ echo "my bad, something didn't go right"; $problem = mysqli_error($cxn); echo $problem; } } PHP:
//the variables $username = $_GET['username']; $password = $_GET['password']; $email = $_GET['email']; $first = $_GET['firstname']; $last = $_GET['lastname']; $date = date("Y-m-d"); //checks to make sure username isn't taken $query = "Select * from $t_user WHERE username = $username"; $result = mysqli_query($cxn,$query); if($result){ echo "Username is already taken!"; $_GET = null; echo "<a href=\"register.php\"> Try Again? </a>"; } //adds them to database. else{ $query = "INSERT INTO users (username, password, email, first_name, last_name, create_date) VALUES ('$username', '$password', '$email', '$first', '$last', '$date')"; $result = mysqli_query($query,$cxn); if($result){ echo "Welcome to Athens Bar Hopper!"; } else{ echo "my bad, something didn't go right"; $problem = mysqli_error($cxn); echo $problem; } } PHP:
Try adding some escaped quotes around $username like: WHERE username = \"$username\""; So the whole query looks like: $query = "Select * from $t_user WHERE username = \"$username\""; By the way, is the Georgia Bar still there?
... ok, I really don't understand some of the people in the forum anymore. cornetofreak, so spend one post just quoting my code, and another telling me to use mysqli_error, when I already said: in my first post, and in the code there is a call to the mysqli_error function. Karin, thanks for pointing out that typo. but the problem is that when I fill out all of the forums correctly, it still will not execute the INSERT query, and I don't know why. oh, and Georgia Bar is still there.
It looks like he made a slight modification to your code : $result = mysqli_query($cxn,$query); And he was asking for the error message, not asking to you to use it. My only question would be, did you mean to use a variable to select the table (it isn't defined in what you posted). $query = "Select * from $t_user WHERE username = $username";