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!
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 trial
Maie Bauza
653 Pointsis this code right to connect html form to my sql using php
<?php
$con=mysqli_connect("localhost","root","****","inquiry_box");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// escape variables for security
$name = mysqli_real_escape_string($con, $_POST['name']);
$email = mysqli_real_escape_string($con, $_POST['email']);
$contact_no = mysqli_real_escape_string($con, $_POST['contact_no']);
$comment = mysqli_real_escape_string($con, $_POST['comment']);
$sql="INSERT INTO form (name, email, contact_no, comment)
VALUES ('$name', '$email', '$contact_no', '$comment')";
if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));
}
echo "1 record added";
mysqli_close($con);
?>
is this code right ?? i am trying to connect the html inquiry box with mysql and i am using this code but the probleme is it dont catch the data i type in html form but it rather show id number no data in the fields please help me thank you so much :D

Philip Cox
14,818 PointsYou should very much consider using the PHP PDO object to connect to your database. It is much safer than this older method. Work through the PHP courses here on Treehouse, and all will be explained.

Maie Bauza
653 Pointsyes i right it ... i made a form and i put data on it then it got connect then every time i fill up the form data does not enter into mysql phpmyadmin

Andrew Shook
31,709 PointsFixed formatting issues and removed the password from you sql connection.
1 Answer

Chris Shaw
26,662 PointsThis is a duplicate of the following thread, please stick to the one thread.
Christian Andersson
8,712 PointsChristian Andersson
8,712 PointsCould you explain better what the issue is? Are you getting any error messages? If not, does anything save to the database?
The code looks very solid though -- did you write it???