BullGuard Antivirus Sale - 60% Off with openElement !
openElement Website Homepage
Forum Home Forum Home >

openElement

> User Tutorials
  New Posts New Posts RSS Feed - Is my php code wrong can't connect to sql databas
  FAQ FAQ  Forum Search   Register Register  Login Login

Is my php code wrong can't connect to sql databas

 Post Reply Post Reply
Author
Message
marlonmata01 View Drop Down
Newbie
Newbie
Avatar

Joined: Mar 06 2017
Location: Davao City
Status: Offline
Points: 2
Post Options Post Options   Thanks (0) Thanks(0)   Quote marlonmata01 Quote  Post ReplyReply Direct Link To This Post Topic: Is my php code wrong can't connect to sql databas
    Posted: Mar 11 2017 at 9:25am
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()

?>


Back to Top
Dmit OE View Drop Down
Admin Group
Admin Group
Avatar

Joined: May 31 2012
Status: Offline
Points: 4647
Post Options Post Options   Thanks (0) Thanks(0)   Quote Dmit OE Quote  Post ReplyReply Direct Link To This Post Posted: Mar 11 2017 at 8:39pm
What error message do you have? Please post it here
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 10.11
Copyright ©2001-2012 Web Wiz Ltd.

This page was generated in 0,016 seconds.