PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi,
I have the below simple html page that should allow me to query my database.
could someone help me with the php script to display the records based on what I searched for?
[syntax="html"]
<html>
<head>
<title>Search</title>
</head>
<body>
<center>
<img src=../img/logo.gif><br><br>
<form name="form" action="search.php" method="post">
<input type="text" name="name" />
<input type="submit" name="Submit" value="Search" />
</form>
</body>
</html>
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
$link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password')
or die(mysql_error());
$where = mysql_real_escape_string ($_POST['name']);
$query = "SELECT * FROM table_name WHERE name=\''.$where.'\'';
$sql = mysql_query($query);
while ($row = mysql_fetch_object($sql)) {
//print your data as you like
echo $row->field_name;
}
<?php
$link = mysql_connect('localhost', 'username', 'password')
or die(mysql_error());
$where = mysql_real_escape_string ($_POST['name']);
$query = "SELECT * FROM contacts WHERE name=\''.$where.'\'';
$sql = mysql_query($query);
while ($row = mysql_fetch_object($sql)) {
//print your data as you like
echo $row->name;
}
?>
$link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password')
or die(mysql_error());
mysql_select_db("databsename");
$where = mysql_real_escape_string ($_POST['name']);
$query = "SELECT * FROM table_name WHERE name=\''.$where.'\'';
$sql = mysql_query($query);
while ($row = mysql_fetch_object($sql)) {
//print your data as you like
echo $row->field_name;
}
feyd wrote:~webspider has mistakenly placed a double quote at the beginning of the $query string assignment. Switching to a single quote will fix the issue.
... and silly. If you're going to use double quote strings, use them for their features. If you're not going to use them for their features, don't use them.
going to use double quote strings, use them for their features
Here could you please clarify me what do you mean by the features of double quote strings? Please clarify. I have been using the same syntax in all my projects. I may be wrong using so. So..