Is my php code wrong can't connect to sql databas |
Post Reply |
Author | |
Dmit OE
Admin Group Joined: May 31 2012 Status: Offline Points: 5283 |
Post Options
Thanks(0)
Posted: Mar 11 2017 at 8:39pm |
What error message do you have? Please post it here
|
|
marlonmata01
Newbie Joined: Mar 06 2017 Location: Davao City Status: Offline Points: 2 |
Post Options
Thanks(0)
|
Hi guys!!! just wanna need some help what seems to be my mistake in this php code of submitting and posting data to mySQL database?
<?php $servername = "localhost"; $username = "admin"; $password = "1234"; $dbname = "dbtrenzy"; $Name = $_POST ['Name'] ; $Email = $_POST ['Email'] ; $Username = $_POST ['Username'] ; $Password = $_POST ['Password'] ; $Country = $_POST ['Country'] ; $Sex = $_POST ['Sex'] ; $Sha1password = sha1 ($password); $conn = mysqli_connect($servername, $username, $password, $dbname ); if (!$conn) { die("Connection failed: " . mysqli_connect_error()); } if (empty ($Name)){ echo "Name can not be blank. Please press back and correct the issue."; die (); } if (empty ($Email)){ echo "Email can not be blank. Please press back and correct the issue."; die (); } if (empty ($Username)){ echo "Username can not be blank. Please press back and correct the issue."; die (); } if (empty ($Password)){ echo "Password can not be blank. Please press back and correct the issue."; die (); } if (empty ($Country)){ echo "Country can not be blank. Please press back and correct the issue."; die (); } $sql = "INSERT INTO users ( Name, Email, Username, Password, Country, Sex) VALUES ('$Name', '$Email', '$Username', '$Password', '$Country', '$Sex')"; if ($conn->query($sql)=== TRUE){ echo "Thank you! Your info has been entered into the database"; } else { echo "Error:".$sql."<br>".$conn->error; } $conn->close() ?> |
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |