0

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>";
5
  • Location:http://www.administrator.html.php?name=".$name.". impressive Commented Apr 11, 2013 at 16:41
  • 1
    You are vulnerable to SQL injection attacks Commented Apr 11, 2013 at 16:42
  • @Prisoner no need for sarcasm, I'm begginer... Commented Apr 11, 2013 at 16:42
  • There are two common ways to send data from the client to the server. A <form> or ajax. Commented Apr 11, 2013 at 16:44
  • @IvanPandžić I didn't mean that to come off as sarcastic, I was just poking fun at the url. Commented Apr 11, 2013 at 22:24

2 Answers 2

1

Try this:

header('Location: http://www.administrator.html.php?name=' .$name);
Sign up to request clarification or add additional context in comments.

2 Comments

Tnx for fast help, it is a small problem, but I'm begginer and searching on the net takes me a lot of time...
no problem :), note that the parameters dont need to be wrapped with quotes " or '
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.