PHP insert is not working please help

I am new on sitepoint I have issue that under function is not working and never insert data into database even I tried to other basic insert code too but it also not worked. Code also not shows any error . I am using php version 7.0(inherited)

I just shifted in a new hosting company where my previous cPanel every thing was good. Let consider if anything mistake in my code then why when I use basic very simple insert code then. It not work? I thought there is mistake in my database version or some setting I left to do.

Please view my phpinfo(); : : https://bit.ly/2M6Wu3R (PHP Info)

Error page: https://bit.ly/2LEcRZs (Registration Page)
Config file: https://bit.ly/2M37gbm (direct access not allowed)
I have been pasted by PHP sir, if you want check my code. Or run in your local host if you register same email 2 times and show error then thing code is now right. Current it not show and continuing show success message but not save into database.

where is my mistake how I fix this issue please help.

ini_set('session.use_strict_mode',1); 
	session_start();
        session_regenerate_id(true);
	$msg = "" ;
	error_reporting(E_ALL);
        ini_set("display_errors", 1);
	use PHPMailer\PHPmailer\PHPMailer;
	$rand=rand();
        $_SESSION['rand']=$rand;

	if (isset($_POST['submit']) )  {	
	include ('../authConfig.php');
		$name = $con->real_escape_string(htmlspecialchars(ucwords(strtolower($_POST['name']))));
		$email = $con->real_escape_string(htmlspecialchars(strtolower($_POST['email'])));
		         
		$extra="regiNew_type=userEmail=confirmed-stg=2.php";
		$host=$_SERVER['HTTP_HOST'];
		$uri=rtrim(dirname($_SERVER['PHP_SELF']),'/\\');
		$uip=$_SERVER['REMOTE_ADDR'];
		$agent = $_SERVER['HTTP_USER_AGENT'];
		
		$crn = 'CRN';
                  $characters = array_merge(range('0','9'));
                  for ($i = 0; $i < 7; $i++) {
                  $rand = mt_rand(0, count($characters)-1);
                  $crn .= $characters[$rand];
                }
        $req = 'REQ';
                  $characters = array_merge(range('A','Z'), range('0','9'));
                  for ($i = 0; $i < 9; $i++) {
                  $rand = mt_rand(0, count($characters)-1);
                  $req .= $characters[$rand];
                }

   	        if ($name == "" || $email == "" )
	      	$msg = "<div id='myTostwarning'>All fields is required to go ahead.</div>";
		else {
		if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
                          $msg= "<div id='myTostwarning'>Invalid formate of your email, re-enter valid email address</div>"; }else{

	        $sql = $con->query("SELECT * FROM UserLogin WHERE Email_ID='$email'");
			if ($sql->num_rows > 0) {
				$msg = "<div id='myTosterror'>Email already exist in our records</div>";
	    	} else {
				$token = 'qwertyuioplkjhgfdsazxcvbnmQWERTYUIOPLKJHGFDSAZXCVBNM0123456789!$/()*';
				$token = str_shuffle($token);
				$token = substr($token, 0,70);
				$con->query("INSERT INTO UserLogin  (CustID,ReqID,Name,Email_ID,Protocol,System,isEmailConfirmed,Emailtoken,EmailtokenExpire) VALUES('$crn','$req','$name','$email','$uip','$agent','PENDING','$token',DATE_ADD(NOW(), INTERVAL 30 MINUTE));");
			

                require_once "PHPMailer/PHPMailer.php";
	        require_once "PHPMailer/Exception.php";
         
                $mail = new PHPMailer();
	        $mail->addAddress($email);
	        $mail->setFrom("noreply@example.com", "Verify Your Email");
	        $mail->Subject = "Please confirm email to complete your registration";
	        $mail->isHTML(true);
                $mail->Body = "Hello $name thank you for registration";
                $mail->AltBody = "Please verify your email to we can proceed to create your account and move you to next step.<br>Copyright © content at all texts or images, logo, designs attached in this mail. ";
                $headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

                if ($mail->send())
                  { 
                   $_SESSION['successmsg']="You have been registered successfully! Please verify your email to create password";
                   header('Location: ../index.php');
                   exit(); } 
                
                else {
                    $_SESSION['errormsg']="Something wrong happened! Please try again..";
                    header('Location: ../index.php');
                    exit();
			}
			}
	   
		}
	}
	}
	

Hi there MrTrouble, welcome to the forums :wave:

First of all, let’s make sure that PHP is valid, which it is not right now, because the string $mail->Body = "Hello $name<br>; is never ended, it should be $mail->Body = "Hello $name<br>"; instead (note the " at the end of the line).

It by mistake when I copy or paste in this post actually it is right in my FTP. Sir thank you for your reply please help

Okay then please copy/paste again and more carefully this time, so that we can see exactly what you’re seeing. This to prevent we catch any other errors that were actually more copy/paste mistakes.

I have been update my post please have a look at there

Your insert query goes

INSERT INTO … VALUE(…)

But it should be

INSERT INTO … VALUES(…)

(note the added S in VALUES)

I do that but still it is not work

Also, why on earth do you have $hashedEmail = password_hash($email, PASSWORD_BCRYPT); in your code? It’s not used anywhere, by password_hash is a rather heavy function (takes a long time) so I would get rid of that line.

What does not work? Do you see an error? Have you tried any debugging with echo, var_dump etc whatsoever?

I’m glad to help out, but I can’t just keep on spotting errors for you to fix until it works, that’s not how forums work.

1 Like

No any error comes. And hashing I used for create secure token.

Hashing of the token sure, but why hash the email address as well?

Please stop scanning, and start reading.

For creating link url which I will send in email included with token sir

What does the insert query return? I notice you don’t check for that.

If you display the variables, then copy/paste them into a query in phpmyadmin, does the query run or does it give you an error?

When I click submit button them shiw success message but not show data in database . I also try to make simple insert function but it also not work.

Your success message is dependant on two things - that the email address does not already exist, and that the email was sent successfully.

If you run the insert query with the same values from phpmyadmin, does it work or do you get an error?

What do you mean by this? Need more details.

1 Like

Whoo boy, that code has a lot of issues!

Before I can even begin to try and help, I need to know the table’s schema. What does

SHOW CREATE TABLE UserLogin 

look like?

Do you need sql of my database? Or screenshot?

I have trouble reading images and would prefer the result of that query posted as text please.

You want sql sir?

No, as I posted