The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

> Help with MySQLi needed
CHerbert
post Feb 9 2018, 08:07 AM
Post #1





Group: Members
Posts: 1
Joined: 9-February 18
Member No.: 26,585



I am trying to learn Mysqli and have got as far as the following, but even though I've ironed out the connection issues it is not actually inserting the data into the relevent table.

Any help most appreciated.

In checklogin file:

// Insert the values into the database
$result = db_query("INSERT INTO `logs` (`email`,`logged`,`ip`) VALUES ('" . $user . "','" . $logged . "','" . $IP . "')");
if($result == false) {
echo "fault here";
// Handle failure - log the error, notify administrator, etc.
} else {
// We successfully inserted a row into the database
echo "log added";
}

In dbfuncs file:

function db_connect() {

// Try and connect to the database, if a connection has not been established yet
$config = parse_ini_file('../config.ini');
$con = new mysqli('localhost',$config['username'],$config['password'],$config['database']);

// If connection was not successful, handle the error
if($con == false) {
// Handle error - notify administrator, log to a file, show an error screen, etc.
return mysqli_connect_error();
}
}


function db_query($query) {
echo $query; //temp check for info sent
// Connect to the database
$con = db_connect();
// Query the database
return $con ? mysqli_query($con, $query) : mysqli_connect_error();
}


Output on screen:

INSERT INTO `logs` (`email`,`logged`,`ip`) VALUES ('xxx','2018-2-9 10:27:1','xxx')log added

However, no entry added to the actual dabatase.

This post has been edited by CHerbert: Feb 9 2018, 08:08 AM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
 
Reply to this topicStart new topic
Replies
jimlongo
post Aug 6 2020, 03:50 PM
Post #2


This is My Life
*******

Group: Members
Posts: 1,128
Joined: 24-August 06
From: t-dot
Member No.: 16



The argument for PDO vs mysqli used to be debatable, but I think nowadays you should use PDO. It's really not much of a contest.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Posts in this topic


Reply to this topicStart new topic
3 User(s) are reading this topic (3 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 28th March 2024 - 01:58 PM