MUUYT Posted June 13, 2008 Share Posted June 13, 2008 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 More sharing options...
zenag Posted June 13, 2008 Share Posted June 13, 2008 <?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>"; Link to comment https://forums.phpfreaks.com/topic/110047-how-to-get-a-name-from-sql-by-input/#findComment-564670 Share on other sites More sharing options...
MUUYT Posted June 13, 2008 Author Share Posted June 13, 2008 Still not working Link to comment https://forums.phpfreaks.com/topic/110047-how-to-get-a-name-from-sql-by-input/#findComment-565186 Share on other sites More sharing options...
MatthewJ Posted June 13, 2008 Share Posted June 13, 2008 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. Link to comment https://forums.phpfreaks.com/topic/110047-how-to-get-a-name-from-sql-by-input/#findComment-565189 Share on other sites More sharing options...
MUUYT Posted June 13, 2008 Author Share Posted June 13, 2008 still not working changed it Link to comment https://forums.phpfreaks.com/topic/110047-how-to-get-a-name-from-sql-by-input/#findComment-565201 Share on other sites More sharing options...
zenag Posted June 16, 2008 Share Posted June 16, 2008 echo $_POST['name1']; check to see wether u get the name values.... Link to comment https://forums.phpfreaks.com/topic/110047-how-to-get-a-name-from-sql-by-input/#findComment-566295 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.