Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

Search Data from textbox in php

Codes here !

Moderators: macek, egami, gesf

Search Data from textbox in php

Postby Gamers » Mon Aug 20, 2012 12:05 pm

Hi Everyone,

In my website i want to search data after submitting a query in the text box, for this purpose i had add a on textbox and one search button. but its not working i am unable to retrive information from my database.
Please find my code below.

<form action="search.php" method="post">
<input type=text name=search >
<input type=submit name=submit value=Search>
</form>

<?php

if(isset($_POST['submit'])) {


date_default_timezone_set('Asia/Calcutta');
$date=date("m/d/Y");
echo "Current Date Is = ";
echo "$date";

$con = mysql_connect("localhost","root","access");
if(!$con) {
die("Unable Connect To Database Server " .mysql_error());
}

$selectdb=mysql_select_db("baltimore",$con);

if(!$selectdb)
{
die ("Database Connection Error" .mysql_error());
}

$table="baltimore";

$sql= "select DATE,JOBNAME,INITIALS,TIME,TIMESTAMP from $table where DATE='{$_POST["submit"]}'";
$mydata=mysql_query($sql,$con);

if (isset($_POST['submit'])) {
echo "<table width=100% height=10% border=1>

<tr>
<th>DATE</th>
<th>JOBNAME</th>
<th>INITIALS </th>
<th>TIME</th>
<th>System TIMESTAMP</th>
</tr>";
}
while($records = mysql_fetch_array($mydata)){
echo "<tr>";
echo "<td>" . $records['DATE'] . "</td>";
echo "<td>" . $records['JOBNAME']. "</td>";
echo "<td>" . $records['INITIALS'] . "</td>";
echo "<td>" . $records['TIME'] . "</td>";
echo "<td>" . $records['TIMESTAMP'] . "</td>";
echo "<br>";
}
echo "</table>";
}

?>


I am not finding any error, But the strange thing is after loading my webpage table heading is display automatically, which i dont want this, i want my table show after fetching data, please guys do help me out.
Gamers
New php-forum User
New php-forum User
 
Posts: 48
Joined: Mon Jun 11, 2012 9:13 am

Re: Search Data from textbox in php

Postby lvidya » Tue Aug 21, 2012 12:25 am

Hai,
your query should be $sql= "select * from $table where joined_date=".$_POST["search"];
the name of the text box search, you should post $_post["search"] to find the values
lvidya
New php-forum User
New php-forum User
 
Posts: 37
Joined: Wed Jun 20, 2012 3:20 am

Re: Search Data from textbox in php

Postby Gamers » Tue Aug 21, 2012 12:58 am

Thanks a lot ividya.

Now i can Fetch data from my database, my last question is after loading my search webpage table is display automatically, which i dont want , i want my table will show just after fetching the data from database. is it possible.
Gamers
New php-forum User
New php-forum User
 
Posts: 48
Joined: Mon Jun 11, 2012 9:13 am

Re: Search Data from textbox in php

Postby lvidya » Tue Aug 21, 2012 1:13 am

Hi, Gamers i did not understand your question, is that you mean, display the table if data is not empty??
lvidya
New php-forum User
New php-forum User
 
Posts: 37
Joined: Wed Jun 20, 2012 3:20 am

Re: Search Data from textbox in php

Postby Acesystech » Tue Aug 21, 2012 3:04 am

your query should be like this...
$sql= "select * from $table where DATE='{$_POST["submit"]}'";
$mydata=mysql_query($sql,$con);
Acesystech
New php-forum User
New php-forum User
 
Posts: 35
Joined: Mon Aug 20, 2012 10:27 pm
Location: Ernakulam

Re: Search Data from textbox in php

Postby Gamers » Tue Aug 21, 2012 3:53 am

Thanks all for the reply my problem has been solved, Now i am facing a new problem while updating a database viewtopic.php?f=5&t=20541
Gamers
New php-forum User
New php-forum User
 
Posts: 48
Joined: Mon Jun 11, 2012 9:13 am


Return to mySQL & php coding

Who is online

Users browsing this forum: Google [Bot] and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron