Jump to content

How to get a name from sql by input


MUUYT

Recommended Posts

I need help i am trying to get some sql data by inputing the name of the person in a form and i can't get it done take a look $name ="$_POST[name1]"

mysql_connect("localhost", "markbur_456", "*******") or die(mysql_error());

mysql_select_db("markbur_northwind") or die(mysql_error());

$data = mysql_query("SELECT * FROM Customers WHERE ContactName ='$name1' ")

or die(mysql_error());

Print "<table border cellpadding=3>";

while($info = mysql_fetch_array( $data ))

{

Print "<tr>";

Print "<th>Name:</th> <td>".$info['ContactName'] . "</td> ";

Print "<th>Phone:</th> <td>".$info['Phone'] . "</td> ";

Print "<th>Company Name:</th> <td>".$info['CompanyName'] . " </td></tr>";

Print "<th>Contact Title:</th> <td>".$info['ContactTitle'] . "</td> ";

Print "<th>Country:</th> <td>".$info['Country'] . "</td> ";

 

}

Print "</table>";

Link to comment
https://forums.phpfreaks.com/topic/110047-how-to-get-a-name-from-sql-by-input/
Share on other sites

<?php
$con =mysql_connect("localhost", "markbur_456", "*******") or die(mysql_error());
mysql_select_db("markbur_northwind",$con) or die(mysql_error());
$name =$_POST['name1'];
$data = mysql_query("SELECT * FROM Customers WHERE ContactName ='$name1' ")
or die(mysql_error());
Print "<table border cellpadding=3>";
while($info = mysql_fetch_array( $data ))
{
Print "<tr>";
Print "<th>Name:</th> <td>".$info['ContactName'] . "</td> ";
Print "<th>Phone:</th> <td>".$info['Phone'] . "</td> ";
Print "<th>Company Name:</th> <td>".$info['CompanyName'] . " </td></tr>";
Print "<th>Contact Title:</th> <td>".$info['ContactTitle'] . "</td> ";
Print "<th>Country:</th> <td>".$info['Country'] . "</td> ";

}
Print "</table>";

Your variables are messed up... Your input is $_POST['name1'] but the variable you set it to is just plain $name... then in the query, you are using $name1 again... either put $_POST['name1'] directly in the query (which you should not do :)), or change the query to use $name instead of $name1.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.