Försök att inte använda mysql_connect använd istället mysqli_connect eller PDO_MySQL läs detta
Använd även die för att se om det finns några fel i din kod
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
Annars (rekommenderat sätt)-
Procedurstil
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "INSERT INTO Persons (firstname, lastname, email)
VALUES ('Happy', 'John', '[email protected]le.com')";
if (mysqli_query($conn, $sql)) {
echo "New Person created successfully";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
mysqli_close($conn);
MySQLi Objektorienterad stil
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO Persons (firstname, lastname, email)
VALUES ('Happy', 'John', '[email protected]')";
if ($conn->query($sql) === TRUE) {
echo "New Person created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();