CRUD - JWalshe86/nags-with-notions4 GitHub Wiki
To run the xampp gui
sudo /opt/lampp/manager-linux-x64.run
Going to use FidelTech's youtube video
Created a crud branch Created signUp.php, login.php & connection.php in root folder
Several tutorials go to xampp

index.php

Using How to install xampp on Ubuntu
Installed net-tools
Get this error

🎉 Removed all docker containers and Apache Server now runs



sudo ln -s ~/projects/nags-with-notions4 /opt/lampp/htdocs
This worked xampp-access-forbidden-php
but getting page not found now

Symlink to projects present but getting 403 permission errors

This isn't working:

Trying to restart apache


I created a 'tests' folder in htdocs and this worked, so it's the symlink

🎉

sudo chown johnwalshe:johnwalshe /opt/lampp/htdocs
Changing the owner of the projects dir in the htdocs folder to 'johnwalshe' and in the 'etc/httpd.conf' file changing the User from daemon to johnwalshe appeared to fix the issue


This is where I got the httpd.conf solution

To run the xampp gui
sudo /opt/lampp/manager-linux-x64.run
if apache doesn't run try turning down all docker containers

🎉

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Sign Up</title>
</head>
<body>
<div class="form">
<form action="" method='post'>
<input type='text' name="name" placeholder='Name'>
<input type='text' name="lastName" placeholder='Last Name'>
<input type='text' name="email" placeholder='Email'>
<input type='text' name="password" placeholder='Password'>
<input type='text' name="confiPassword" placeholder='Confirm Password'>
</form>
</div>
</body>
</html>

SignUP

http://localhost/phpMyAdmin

sudo chown -R root:root temp
Changed permissions to temp dir and get the following:

From this reset mysql password article I changed the password
/opt/lampp/bin/mysqladmin --user=root password 'new password'
Get this error now


Went to config.inc.php and entered password:

🎉

Created CRUDsystem database

PHP to connect to mysql
<?php
class crud{
/* The static keyword is used to declare properties and methods of a class as static. Static properties and methods can be used without creating an instance of the class. You don't need to instantiate the class with 'new'. Use when inheritance isn't required.*/
public static function connect()
{
try {
/* The new keyword is used to create an object from a class. PDO (PHP Data Objects) is a built in PHP class used to make it easier
to interact with a database. With PDO you can issue queries or fetch data using the same functions on different databases
*/
$con=new PDO('mysql:localhost=host; dbname=ol5wws00_crudsystem2','root','Sunshine7!');
return $con;
/*
The PHP PDOException is a runtime exception that occurs when something goes wrong while using the PDO (PHP Data Objects) class or its related extensions. */
} catch (PDOException $error1)
echo 'Something went wrong, with you connection!'.$error1->getMessage();
}catch (Exception $error2){
echo 'Generic error!'.$error2->getMessage();
}
}
public static function Selectdata()
{
/* An array is used so multiple values can be stored here in the one variable */
$data=array();
/*
the double colon, is a token that allows access to a constant, static property, or static method of a class or one of its parents.
'prepare' is a feature used to execute the same (or similar) SQL statements repeatedly with high efficiency.
*/
$p=crud::connect()->prepare('SELECT * FROM crudtable');
$p->execute();
$data=$p->fetchAll(PDO::FETCH_ASSOC);
return $data;
}
public static function delete($id)
{
$p=crud::connect()->prepare('DELETE FROM crudtable WHERE id=:id');
$p->bindValue(':id',$id);
$p->execute();
}
public static function userDataPerId($id)
{
$data=array();
$p=crud::connect()->prepare('SELECT * FROM crudtable WHERE id=:id');
/* bindValue is used as a safety feature for placeholders when using prepare */
$p->bindValue(':id',$id);
$p->execute();
$data=$p->fetch(PDO::FETCH_ASSOC);
return $data;
}
}
?>
when use PDO or mysqli_connect?
Test to check connection in signUP.php
<?php
require('./connection.php');
if (isset($_POST['signUP_button'])) {
echo 'It is working!';
}
?>
🎉

Getting this error:

Changed root password to default password. Screen shows empty now.
🎉 Had incorrect table name
Can see entry in phpMyAdmin

🎉 Logged in successfully

<?php
require('./connection.php');
if (isset($_POST['signUP_button'])) {
$name=$_POST['name'];
$lastName=$_POST['lastName'];
$email=$_POST['email'];
$password=$_POST['password'];
$confPassword=$_POST['confiPassword'];
if (!empty($_POST['name'])&& !empty($_POST['lastName'])&& !empty($_POST['email'])&&!empty($_POST['password'])) {
if ($password== $confPassword) {
$p=crud::conect()->prepare('INSERT INTO CRUDTables(name,lastName,email,pass) VALUES(:n,:l,:e,:p)');
$p->bindValue(':n', $name);
$p->bindValue(':l', $lastName);
$p->bindValue(':e', $email);
$p->bindValue(':p',$password);
$p->execute();
echo 'User added successfully!';
}else{
echo 'Password does not match!';
}
}
}
?>
🎉 Users display in table

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./table.css">
<title>Document</title>
</head>
<body>
<table>
<thead>
<tr>
<th>Name</th>
<th>Last Name</th>
<th>Email</th>
<th>Password</th>
<th>Delete</th>
<th>Edit</th>
</tr>
</thead>
<tbody>
<?php
require('./connection.php');
$p=crud::Selectdata();
if (isset($_GET['id'])) {
$id=$_GET['id'];
$e=crud::delete($id);
}
if (count( $p)>0) {
for ($i=0; $i < count( $p); $i++) {
echo '<tr>';
foreach ( $p[$i] as $key => $value) {
if ($key!='id') {
echo '<td>'.$value.'</td>';
}
}
?>
<td><a href="users.php?id=<?php echo $p[$i]['id'] ?>"><img src="./trash.svg" alt="" srcset=""></a></td>
<td><a href="upDate.php?id_up=<?php echo $p[$i]['id'] ?>"><img src="./edit.svg" alt="" srcset=""></a></td>
<?php
echo '</tr>';
}
}
?>
</tbody>
</table>
</body>
</html>
New users being added successfully

Trash icon by Icons8
🎉 Delete button working
🎉 updated successfully

🐛 Updating updates all names

Data not rendering

The table name was incorrect in the update function.
Update form preloads now & updates name correctly

🐛 #1932 - Table 'CRUDsystem.CRUDTables' doesn't exist in engine

Attempting to delete CRUDsystem db
Get this error

when running mysql_upgrade I get this

As per this mysql error upgrade I ran
mysqld_upgrade --upgrade=FORCE
It then got this

Changed the binlog.index permissions & get this:

This error now:

There's an ibdata1 in /var/lib/mysql && in /opt/lampp/var/mysql
Get this error now:

changed server host from 'localhost' to 127.0.0.1

Used remove mysql = i think I've a lampp version & a normal version and it's causing mix ups
Installed new version of phpmyadmin - old tables not there

🎉 Working again

Needed to add update password to table & not just database to get it working again
Added image table to crud db
