PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, January 25, 2022

[FIXED] What is servername

 January 25, 2022     database, mysql, mysqli, php, phpmyadmin     No comments   

Issue

i just wanted to insert data into database from a form, with php. i ran the code below in my Localhost using XAMPP and everything was fine but where i upload it to my host it didn't work.

Question is What shold i put for $servername and when should i look for it ?

There is my codes:

Register.php (in localhost)

<?php

$servername = "localhost";
$username = "root";
$password = "";
$dbname = "test";

$Name = $_POST['Name'];
$Username = $_POST['Username'];
$Password = $_POST['Password'];
$Email = $_POST['Email'];

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    header("Location:#");
}

//Inserting Data
 try{
$sql = "INSERT INTO User (uName , uUsername , uPassword , uEmail) VALUES ('$Name' , '$Username' , '$Password' , '$Email')";
mysqli_query($conn, $sql);
 }catch (Exception $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
 }
$conn->close();
header("Location:#");
}
?>

Solution

I asked my host service providers about the "$servername" and they answered me that the "$serverneme" is localhost.



Answered By - payamQorbanpour
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing