Print Page | Close Window

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

Printed From: Forum openElement
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: http://forum.openelement.com/fr/forum_posts.asp?TID=1023
Printed Date: 19 Oct 2021 at 22:29
Software Version: Web Wiz Forums 10.11 - 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: 11 Mar 2017 at 10:25
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: 11 Mar 2017 at 21:39
What error message do you have? Please post it here



Print Page | Close Window

Forum Software by Web Wiz Forums® version 10.11 - http://www.webwizforums.com
Copyright ©2001-2012 Web Wiz Ltd. - http://www.webwiz.co.uk