Print Page | Close Window

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

Printed From: openElement Website
Category:

openElement


Forum Name: User Tutorials
Forum Description: Browse or create a tutorial to get the most out of the openElement software.
Please do not post support questions in this section.
URL: https://forums.openelement.uk/en/forum_posts.asp?TID=1023
Printed Date: Mar 28 2024 at 8:08am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Is my php code wrong can't connect to sql databas
Posted By: marlonmata01
Subject: Is my php code wrong can't connect to sql databas
Date 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()

?>





Replies:
Posted By: Dmit OE
Date Posted: Mar 11 2017 at 8:39pm
What error message do you have? Please post it here



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net