Click here to Skip to main content
15,905,071 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to set Parameter in Html Page which is redirect from Php with Parameter as below


$servername = "localhost";
$database = "mydatabase";
$username = "myuser";
$password = "mypwd";

// Create connection

$conn = mysqli_connect($servername, $username, $password, $database);
    $sql = mysqli_query($conn,
    "SELECT * FROM myuser WHERE mobi='"
    . $_POST["mobi"] . "' AND
    pwd='" . $_POST["pwd"] . "'    ");

    $num = mysqli_num_rows($sql);
    if($num > 0) {
    header("Location:" .$mobi);

    echo "Invalid Credential";



<!Doctype html>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- Bootstrap CSS -->
<link href="" rel="stylesheet">
<script src=""></script>

<body style="margin:0;padding:0">
	<div style="width:100%;" >
		<img  src="img/logo1.jpg" style="display:inline; width:170px; height:70px;" />

		<a href="logout.html" style="display:inline;float:right;padding-right:1%;text-decoration:none;font-size:15px;">LogOut</a>
			<a href="login.html" style="display:inline;float:right;padding-right:1%;text-decoration:none;font-size:15px;margin-bottom:0">Login</a>

		    <input type="hidden" id="nn" style="display-inline;float:right;padding-right:1%" name="mobil" value="<?php echo $mobi; ?>"/>
		    <span id="nn123"></span>


<nav class="navbar navbar-expand-lg navbar-light bg-light" style="margin-top:20px">
    <div class="container-fluid">
        <button type="button" class="navbar-toggler" data-bs-toggle="collapse" data-bs-target="#navbarCollapse">
        <div class="collapse navbar-collapse" id="navbarCollapse">
            <div class="navbar-nav">
                <a href="#" style="color:black;" class="nav-item nav-link active">Home</a>
                <div class="nav-item dropdown">
                    <a href="#" style="color:black;" class="nav-link dropdown-toggle" data-bs-toggle="dropdown">Products</a>
                    <div class="dropdown-menu">
                        <a href="tshirt.html" style="color:black;" class="dropdown-item">T-Shirt</a>
                        <a href="#" style="color:black;" class="dropdown-item">Jeans</a>
                <a href="#" class="nav-item nav-link disabled" style="color:black;" tabindex="-1">About Us</a>
                <a href="#" style="color:black;" class="nav-item nav-link disabled" tabindex="-1">Contact Us</a>


    document.getElementById( 'nn123' ).innerHTML = document.getElementById( 'nn' ).value;



I am not define variable in index.php but set in input hidden. So how to define $mobi variable in index.php page please suggest.

What I have tried:

I am browsing this issue from two days on Google but not success
Updated 6-Feb-23 1:02am
Member 15627495 6-Feb-23 6:05am    
header("Location:" .$mobi   , true);

1 solution

Firstly, while you are developing your code, use this at the top of each PHP page, this will return the errors thrown so you can easily identify where your code errors occur -
ini_set('display_errors', 1);

Looking at your code, you have a no return data because of some operators missing at this line -
header("Location:" .$mobi);
//This should look like the following -
header("Location:" .$mobi. "");

If this does not help, let us know on which line the error occured and what error were returned.

Looking at your edited question, you are calling a re-direct to index.html, your code is however in index.php

I will then suggest that you rather store all the variables in a session and call it from there. You can do this easily enough, read up on sessions from THIS PHP manual.

In your login.php, right at the top as the first line of code, add the following -
if (session_status() == PHP_SESSION_NONE) {

	//Create a new session id after each login...

    ini_set('display_errors', 1);
//Remember to comment the error checking out after development...
//Now add your values to your session -
$_SESSION['mobi'] = $mobi;

In your index.php page (maybe look at naming this page different as index pages is your landing or 1st page in your site, then followed by login or whichever other page) -
<input type="hidden" id="nn" style="display-inline;float:right;padding-right:1%" name="mobil" value="<?php echo $_SESSION['mobi']; ?>"/>

You can add as many variables to your sessions as you wish, just read up more on closing sessions, flushing variables and arrays etc.
Share this answer
MAHESH WAGHELA 6-Feb-23 6:26am    
Warning: main(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /home/brandstu/public_html/index.php on line 27

Notice: Undefined variable: mobi in /home/brandstu/public_html/index.php on line 27
MAHESH WAGHELA 6-Feb-23 6:28am    
Error at index.php page vaiable not properly set at hidden in html
Andre Oosthuizen 6-Feb-23 6:45am    
It seems that your calls to variables is on different pages, edit your question with the code for page 1 and then code for page 2 to make sense of where which call is made.
MAHESH WAGHELA 6-Feb-23 7:04am    
check it I have changed it as per your suggestion
Andre Oosthuizen 6-Feb-23 7:37am    
Updated my solution with Session

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