Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
<?php
// Load the database configuration file
require_once 'dbConfig.php';
 
$name=mysqli_real_escape_string($conn,$_POST['name']);
$email=mysqli_real_escape_string($conn,$_POST['email']);
$user_id=mysqli_real_escape_string($conn,$_POST['user_id']);
$image=mysqli_real_escape_string($conn,$_POST['image']);

$check=mysqli_num_rows(mysqli_query($conn,"select * from user where user_id='$user_id'"));

if($check>0){

}else{
    mysqli_query($conn,"insert into user(name,email,image,user_id)values('$name','$email,'$image','$user_id')");
}
echo "done";

?>


What I have tried:

This is for login using google in php i want the userdata who logged in to appear his data on my table please help in response im getting done response but there is no data in table
Posted
Updated 4-Jun-21 22:55pm
Comments
Richard MacCutchan 5-Jun-21 4:47am    
You do not check the result of your insert command, so you have no idea whether it succeeded or not.

1 solution

PHP
mysqli_query($conn,"insert into user(name,email,image,user_id) values('$name','$email,'$image','$user_id')");

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[^]
 
Share this answer
 

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