Ivan Pandžić
Ivan Pandžić

Reputation: 373

Sending data from DB to web page

In my form i enter ID of student, which is located in database. On submit I send entered ID to external script, where i search for name of student with entered ID. This works, and after i echo it's name it's correct, but I don't know how to send data back to the my web page so I could read student's name with GET from address bar. Code:

$con=mysqli_connect("localhost","root","","novi-studomat");
if (mysqli_connect_errno($con))
{
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$id=$_POST['id'];
$exe="SELECT * FROM student WHERE id='$id'";
$query=mysqli_fetch_array(mysqli_query($con,$exe));
$ime=$query['name'];

I've tried with this:

header('Location:http://www.administrator.html.php?name=".$name."');

But it doesn't sends data to the page. This worked, but I think that there must be more elegant solution:

echo "<script>window.location.assign('http://www.administrator.html.php?name=".$name."'); </script>";

Upvotes: 0

Views: 68

Answers (2)

user1978081
user1978081

Reputation:

it's simple. when you work on database table you should use primary id not other data. if you know primary id of a table, you can write any query in anywhere even you can store this id in session

Upvotes: 0

razz
razz

Reputation: 10120

Try this:

header('Location: http://www.administrator.html.php?name=' .$name);

Upvotes: 1

Related Questions