I have been on this issue for a while now, having tried everything from the code you would see below and not getting any result.
Here is the database i created and is finally updating;
I have been on this issue for a while now, having tried everything from the code you would see below and not getting any result.
Here is the database i created and is finally updating;
PHP:
<?php
session_start();
$_SESSION['message'] = '';
$mysqli = new mysqli('localhost', 'root', 'root', 'accounts');
if ($mysqli->connect_error) {
die("Connection failed: " . $mysqli->connect_error);
}
echo "Connected successfully";
// sql to create table
//$sql = "CREATE TABLE Added (
//id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
//name VARCHAR(30) NOT NULL,
//email VARCHAR(30) NOT NULL,
//address VARCHAR(30) NOT NULL,
//phone VARCHAR(30) NOT NULL,
//district VARCHAR(50),
//reg_date TIMESTAMP
//)";
//if ($mysqli->query($sql) === TRUE) {
//echo "Table Added created successfully";
//} else {
//echo "Error creating table: " . $mysqli->error;
//}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
//two passwords are equal to each other
$name = $mysqli->real_escape_string($_POST['name']);
$email = $mysqli->real_escape_string($_POST['email']);
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = "Invalid email format";
}
$phone = $mysqli->real_escape_string($_POST['phone']);
$address = $mysqli->real_escape_string($_POST['address']);
$district = $mysqli->real_escape_string($_POST['district']);
//make sure file type is image
$sql = "INSERT INTO Added (name, email, phone, address, district) "
. "VALUES ('$name', '$email', '$phone', '$address', '$district')";
if ($mysqli->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $mysqli->error;
}
}
//if the query is successful, redirect to welcome
And here is the code to try retrieving all the user data;
PHP:
<?php
// Get user data
// sort the data based on the district
// customize the message, concatinate the username with the message.
// then send the message.
session_start();
$mysqli = new mysqli('localhost', 'root', 'root', 'accounts');
if ($mysqli->connect_error) {
die("Connection failed: " . $mysqli->connect_error);
}
echo "Connected successfully";
$json = array( );
$sql = mysql_query("SELECT * FROM Added",$mysqli) or die (mysql_error());
while( $users = mysql_fetch_assoc( $sql ) ) {
$json[] = $users;
}
echo json_encode( $json );
var_dump($users);
//$query= $mysqli->query($sql);
//$arr = mysql_fetch_array($query);
//$num = mysql_numrows($query);
//$array = [{
//name: "Chisimdi Damian",
//id: 1
//},{
//}
//];
//$garki = [];
//$lokogoma = [];
//foreach(i) {
//$garki.push($item);
//}
//var_dump($array);
I've been on these for some hours now and i'm in dire need to move ahead with my work.
I have commented out the not needed parts yet. I've tried all i know about selection, it just tells me connected successfully.
I have commented out the not needed parts yet. I've tried all i know about selection, it just tells me connected successfully.
I have commented out the not needed parts yet. I've tried all i know about selection, it just tells me connected successfully.