Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialKonrad Pilch
2,435 PointsPHP error
What does this error mean?
Warning: mysqli_real_escape_string() expects exactly 2 parameters, 1 given in /Applications/MAMP/htdocs/071YTMembership/register.php on line 25
Warning: mysqli_query() expects at least 2 parameters, 1 given in /Applications/MAMP/htdocs/071YTMembership/register.php on line 28 Could not chekc username
Konrad Pilch
2,435 PointsThis is my connect :
<?php
mysqli_connect("localhost","root","root","membership") or die("Could not connect to server!");
?>
AND THIS IS MY GLOBAL:
<?php
session_start();
include_once("connect.php");
ini_set('display_startup_errors',1);
ini_set('display_errors',1);
error_reporting(-1);
?>
So i believe it should work
1 Answer
shawn stokes
5,651 Pointsexpects exactly 2 parameters . you need to connect to the db also. you set the string but sql can not connect to the db. $example = mysqli_real_escape_string($connection, $string);
notice $A this is the variable for connecting to the my sql database. it looks like the same error for both they need two arguments A connection to the data base and B the string
Konrad Pilch
2,435 PointsOh here i see .
I changed this to
$email = mysqli_real_escape_string($con,$email);
and not it works
Konrad Pilch
2,435 PointsBut how can i connect this ?
$user_query = mysqli_query("SELECT username FROM members WHERE username='$username'LIMIT 1") or die("Could not chekc username");
$count_username = mysqli_num_rows($user_query);
The $con is the database
<?php
$con = mysqli_connect("localhost","root","root","membership") or die("Could not connect to server!");
?>
Konrad Pilch
2,435 PointsOh i added the con
$email = mysqli_real_escape_string($con, $email);
//check for dublicates
$user_query = mysqli_query($con, "SELECT username FROM members WHERE username='$username'LIMIT 1") or die("Could not chekc username");
$count_username = mysqli_num_rows($user_query);
$email_query = mysqli_query($con, "SELECT email FROM members WHERE email='$email'LIMIT 1") or die("Could not chekc username");
$count_email = mysqli_num_rows($email_query);
But it could not send of the informaiton
Konrad Pilch
2,435 PointsActually i made a clean post : p here
Konrad Pilch
2,435 PointsKonrad Pilch
2,435 PointsAnd this is my code if thats any use
register