Click here to Skip to main content
14,929,103 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I created databse and table on sql but I have a problem that is  data inserted doesnt show on my mysql database on localserver its important thank you


What I have tried:

<?php
$connection = mysqli_connect('localhost', 'root');
if($connection){
    echo"connection";
}
else{
    echo"connection failes";




<a href=""></a>
}

mysqli_select_db($connection,'authentication');

$text = $_POST['Email'];
$password  =  $_POST['psw'];
$password  =  $_POST['pswrepeat'];


$data="INSERT INTO signup(Email,psw,pswrepeat) VALUES ('$Email','$psw','$pswrepeat')";
mysqli_query($connection,$data);
header('location:signupsuccessfull.php');?>
Posted
Updated 16-May-21 20:43pm
v4
Comments
Richard MacCutchan 17-May-21 3:43am
   
You are not checking the return value from mysqli_query, so you have no idea whether it succeeded or not.

Quote:
its important

No, it isn't - I just checked and nobody in the office has it even on their ToDo list.
It may be important to you, but every question is important to the person who wants an answer: All that your stressing the urgency does is to make us think you have left it too late, and want us to do it for you. Or that you are rude and arrogant, thinking you are much more important than anyone else. This annoys some people, and can slow a response.

And to be honest, the slower that code is developed the better: it's dangerous, both to the world in general and to you specifically. Never store passwords in clear text - it is a major security risk. There is some information on how to do it here: Password Storage: How to do it.[^]

And remember: this is web based so GDPR applies and that means you need to handle passwords as sensitive data and store them in a safe and secure manner. Text is neither of those and the fines can be .... um ... outstanding. In December 2018 a German company received a relatively low fine of €20,000 for just that.

It's not as if PHP doesn't have inbuilt password hashing: PHP: Password Hashing - Manual[^]

And then there is the other Elephant in the room: Never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Always use Parameterized queries instead.

When you concatenate strings, you cause problems because SQL receives commands like:
SQL
SELECT * FROM MyTable WHERE StreetAddress = 'Baker's Wood'
The quote the user added terminates the string as far as SQL is concerned and you get problems. But it could be worse. If I come along and type this instead: "x';DROP TABLE MyTable;--" Then SQL receives a very different command:
SQL
SELECT * FROM MyTable WHERE StreetAddress = 'x';DROP TABLE MyTable;--'
Which SQL sees as three separate commands:
SQL
SELECT * FROM MyTable WHERE StreetAddress = 'x';
A perfectly valid SELECT
SQL
DROP TABLE MyTable;
A perfectly valid "delete the table" command
SQL
--'
And everything else is a comment.
So it does: selects any matching rows, deletes the table from the DB, and ignores anything else.

So ALWAYS use parameterized queries! Or be prepared to restore your DB from backup frequently. You do take backups regularly, don't you?

Once you have fixed those throughout your whole app, look at your problem - which we can't fix for you, as we have no access at all to your code running with your DB, and you need both in order to fix it.
So, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. How you use it depends on your compiler system, but a quick Google for the name of your IDE and "debugger" should give you the info you need.

Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!
I'd start by looking at the error message it generates, because that could well be important and contain information on why it gave an error ...
   
PHP
$data="INSERT INTO signup(Email,psw,pswrepeat) VALUES ('$Email','$psw','$pswrepeat')";

Not necessary a solution to your question, but another problem you have.
Never build an SQL query by concatenating strings. Sooner or later, you will do it with user inputs, and this opens door to a vulnerability named "SQL injection", it is dangerous for your database and error prone.
A single quote in a name and your program crash. If a user input a name like "Brian O'Conner" can crash your app, it is an SQL injection vulnerability, and the crash is the least of the problems, a malicious user input and it is promoted to SQL commands with all credentials.
SQL injection - Wikipedia[^]
SQL Injection[^]
SQL Injection Attacks by Example[^]
PHP: SQL Injection - Manual[^]
How can I explain SQL injection without technical jargon? - Information Security Stack Exchange[^]
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900