Urgent help needed. i am a newbie, and starting to have a headache with this problem,
i am using form to enter firstname so that all the details of that person can be pulled.

where am i doing it wrong?
its showing me the headings of firstname, lastname, and age but no data in it. when data is actually available in database.


databasename=testdb
table name = persons1

please check both of my files below.

1) Pullform.html
<html>
<body>

<form action="get1.php" method="post">
<strong>last:</strong>
<input type="text" name="Firstname" />

<input type="submit" name="submit" value="Check employee" />
</form>

</body>
</html>


2) get1.php

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("testdb", $con);
// by just adding ORDER By, i could fetch info in alphabetical order.
$sql = ("SELECT * FROM persons1 WHERE Firstname='$Firstname'");
$result = mysql_query($sql);
echo "<table border='1'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>";

while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row . "</td>";
echo "<td>" . $row . "</td>";
echo "<td>" . $row . "</td>";
echo "</tr>";
}
echo "</table>";

mysql_close($con);
?>

$Firstname is already variable, but not is filled (register_globals = Off in the php.ini, should be is On if you wont to use this writable.
It's right writable.
$_POST or $Firstname = $_POST;
or this:

extract(($_POST),  EXTR_PREFIX_ALL, 'post');

Then all your POST data will be $post_Firstname and etc.

dear sam, thank you very much for the response, ...

as i am newbie so didnt really understook it.. could you please tell that if i need to replace any part of my code in get1.php with extract(($_POST), EXTR_PREFIX_ALL, 'post');
?


or do i need to do any changed in my phpinfo();
?

thanks

Add the line:

$Firstname = $_POST['Firstname'];

before the line with mysql_select_db.

You are welcome.

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
    die('Could not connect: ' . mysql_error());
}

mysql_select_db("testdb", $con);
extract(($_POST), EXTR_PREFIX_ALL, 'post');
// by just adding ORDER By, i could fetch info in alphabetical order.
$sql = ("SELECT * FROM persons1 WHERE Firstname='  . $post_Firstname . '");
$result = mysql_query($sql);
echo "<table border='1'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>";

while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['Firstname'] . "</td>";
echo "<td>" . $row['Lastname'] . "</td>";
echo "<td>" . $row['Age'] . "</td>";
echo "</tr>";
}
echo "</table>";

mysql_close($con);
?>

dear sam, i did what you said but it just shows this

Firstname Lastname Age
which are the headings of table but no data in it?

$sql = ("SELECT * FROM persons1 WHERE Firstname='  . $post_Firstname . '");

should be

$sql = ("SELECT * FROM persons1 WHERE Firstname='$post_Firstname'");

brilliant stuff samael, great job, my code works, thanks again mate.... :-)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.