Home > Software engineering >  I can not pass the value from database into a $dom_details array
I can not pass the value from database into a $dom_details array

Time:05-03

This is the problem I encounter. I will show the necessary code.

$sql = "SELECT activation_string FROM user_tbl WHERE username = '$username'";
$result = mysqli_query($conn->connect(), $sql);
$row = mysqli_fetch_array($result);
$row = $result->fetch_assoc();



$dom_details = array(
    "{client-name}"=> $username,
    "{my-website}" => "Mikhael-Worshop",
    "{my-number}" => " 63934738571",
    "{my-message}" => 'https://web.facebook.com/miko.coral.1/'
    "{activation-code}" => $row \\right here is not working
);
 foreach(array_keys($dom_details) as $key){
        $temp_message = str_replace($key, $dom_details[$key], $temp_message);
    }

I want it to pass to my activation URL so that I can access it using $get method. You can see in the tag that their is the {username} and {activation-string}. the {username} is successful in replacing the value and I can access it using the get method however the {activation-string} is not. please help

<html>
    <head>
    </head>
    <body style="background-color:pink; border-radius: 10px;">
        <div style="margin: auto; width: 40%; text-align: center; font-size: 20px; padding: 1% 2% 3% 3%; background-color: eee; border-radius: 12px; margin-top: 3%;">
            <h1>Hi {client-name}!</h1><hr /><br />
            <span>Welcome to {my-website}. Your new account comes with access to all features and services.
            To get started, {activation-string} the button below to active your account.</span>
            <br />
            <br />
            
            
            <a href="http://localhost/prefinal(ias2)/activation.php?username={client-name}&code={activation-string}">
                <button style="padding: 1%; background-color:#045791; border-radius:8px;">
                    <span style="font-size: 20px; color: white;">Activate</span>
                </button>
                </a>
            
            <br />
            <br />
            <p>For any concerns, kindly call or text us at {my-number}.</p>
            <p>Additional message goes here: Visit {my-message}</p>
        </div>
    </body>
</html>

CodePudding user response:

I see where the problem is.

Though you have selected only one column the data is stored as array with index 'activation_string'.

Try this

$act_code=$row['activation_string'];

and then replace

"{activation-code}" => $row;

with

"{activation-code}" => $act_code;

you can also do $row['activation-string'] instead of $row in first place. But i prefer creating a extra variable for this as code looks neat.

CodePudding user response:

finally i found the answer.

$row = $result->fetch_assoc();

    foreach ($row as $value) {  
        
      }

"activation-code" => $value
  • Related