zenrab Posted August 6, 2008 Share Posted August 6, 2008 Hello Real Newbie here. I am having problems with my echo, the screen is blank. Can anyone offer any insight: Code below. I am trying to achieve the following: Put customer phone number in search; if record there, display full record, if not there return form with entered phone number in place and all other fields empty. Many thanks in anticipation <?php $host="localhost"; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name=""; // Database name mysql_connect(localhost,$username,$password); @mysql_select_db($db_name) or die( "Unable to select database"); if ($_POST[submit] == "Search") { //Collect Form Data $string = $_POST['search']; //Issue SQL SELECT Statement $query = "SELECT * FROM contacts WHERE telephone1 = '$string'"; $result = mysql_query($query) or die(mysql_error()); $mysql_num = mysql_num_rows($result ); if ($mysql_num == 0) { print "<tr>"; print "<td>First Name:"; print "<td><input name='firstname' type='text'></td>"; print "</td>"; print "<td>Last Name:"; print "<td><input name='lastname' type='text'></td>"; print "</td>"; print "<td>Address 1:"; print "<td><input name='address2' type='text'></td>"; print "</td>"; print "<td>Address 2:"; print "<td><input name='address2' type='text'></td>"; print "</td>"; print "<td>Telephone 1:"; print "<td><input name='telephone1' type='text' value='"; echo $string; print "'></td>"; print "</td>"; print "<td>Telephone 2:"; print "<td><input name='telephone2' type='text'></td>"; print "</td>"; print "<td>Email:"; print "<td><input name='email' type='text'></td>"; print "</td>"; print "</tr>"; } else { // enter your code here if your query finds a customer with the number your searching for while($row = mysql_fetch_array($result)) { print "<tr>"; print "<td>First Name:"; echo $row['firstname']; print "</td>"; print "<td>Last Name:"; echo $row['lastname']; print "</td>"; print "<td>Address 1:"; echo $row['address1']; print "</td>"; print "<td>Address 2:"; echo $row['address2']; print "</td>"; print "<td>Telephone 1:"; echo $row['telephone1']; print "</td>"; print "<td>Telephone 2:"; echo $row['telephone2']; print "</td>"; print "<td>Email:"; echo $row['email']; print "</td>"; print "</tr>"; } } } ?> Quote Link to comment Share on other sites More sharing options...
dilum Posted August 6, 2008 Share Posted August 6, 2008 Your code might be generate some error. Put this line very top of your page "ini_set('display_errors',1);". You will see the error. Quote Link to comment Share on other sites More sharing options...
zenrab Posted August 6, 2008 Author Share Posted August 6, 2008 when you say the top of the page, should it be at the top under the first <?php tag or above it? many thanks Quote Link to comment Share on other sites More sharing options...
dilum Posted August 6, 2008 Share Posted August 6, 2008 Put it like this, <?php ini_set(''....... //your code. ?> Quote Link to comment Share on other sites More sharing options...
zenrab Posted August 6, 2008 Author Share Posted August 6, 2008 Thanks Dilum the error message i am getting is for line 11, which is my local host call! <?php "ini_set('display_errors',1);" $host="localhost"; // Host name Any thoughts? Thanks again Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted August 6, 2008 Share Posted August 6, 2008 change this line: mysql_connect(localhost,$username,$password); to this: mysql_connect("localhost",$username,$password); Quote Link to comment Share on other sites More sharing options...
zenrab Posted August 6, 2008 Author Share Posted August 6, 2008 Hi have made the change. Here's the error message: Parse error: syntax error, unexpected T_VARIABLE for the same line: $host="localhost"; // Host name Here's the top of the code including the error line: $host="localhost"; // Host name $username="mysite"; // Mysql username $password="mypassword"; // Mysql password $db_name="mydb"; // Database name mysql_connect("localhost",$username,$password); (this is line 11) @mysql_select_db($db_name) or die( "Unable to select database"); I know it's going to be something that makes me go "doh",but what? thanks again Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted August 6, 2008 Share Posted August 6, 2008 try: <?php $host="localhost"; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name=""; // Database name mysql_connect($host,$username,$password); mysql_select_db($db_name) or die( "Unable to select database"); if ($_POST['submit'] == "Search") { //Collect Form Data $string = $_POST['search']; //Issue SQL SELECT Statement $query = "SELECT * FROM contacts WHERE telephone1 = '$string'"; $result = mysql_query($query) or die(mysql_error()); $mysql_num = mysql_num_rows($result); if ($mysql_num == 0) { print "<tr>"; print "<td>First Name:"; print "<td><input name='firstname' type='text'></td>"; print "</td>"; print "<td>Last Name:"; print "<td><input name='lastname' type='text'></td>"; print "</td>"; print "<td>Address 1:"; print "<td><input name='address2' type='text'></td>"; print "</td>"; print "<td>Address 2:"; print "<td><input name='address2' type='text'></td>"; print "</td>"; print "<td>Telephone 1:"; print "<td><input name='telephone1' type='text' value='" . $string . "'></td>"; print "</td>"; print "<td>Telephone 2:"; print "<td><input name='telephone2' type='text'></td>"; print "</td>"; print "<td>Email:"; print "<td><input name='email' type='text'></td>"; print "</td>"; print "</tr>"; } else { // enter your code here if your query finds a customer with the number your searching for while($row = mysql_fetch_array($result)) { print "<tr>"; print "<td>First Name:"; echo $row['firstname']; print "</td>"; print "<td>Last Name:"; echo $row['lastname']; print "</td>"; print "<td>Address 1:"; echo $row['address1']; print "</td>"; print "<td>Address 2:"; echo $row['address2']; print "</td>"; print "<td>Telephone 1:"; echo $row['telephone1']; print "</td>"; print "<td>Telephone 2:"; echo $row['telephone2']; print "</td>"; print "<td>Email:"; echo $row['email']; print "</td>"; print "</tr>"; } } } ?> Quote Link to comment Share on other sites More sharing options...
zenrab Posted August 6, 2008 Author Share Posted August 6, 2008 Hi It's just not makng any difference: <?php "ini_set('display_errors',1);" $host="localhost"; // Host name $username="yes"; // Mysql username $password="yes"; // Mysql password $db_name="yes"; // Database name mysql_connect($host,$username,$password); @mysql_select_db($db_name) or die( "Unable to select database"); Still can't get past the line 11 error more thoughts greatly appreciated. many thanks Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted August 6, 2008 Share Posted August 6, 2008 try doing this: <?php // remove ini_set and replace with this... error_reporting(E_ALL); $link = mysql_connect($host,$username,$password); if ( ! $link ) { die( "Couldn't connect to MySQL: ".mysql_error() ); } mysql_select_db( $db_name, $link ) or die ( "Couldn't connect to database: ".mysql_error() ); Quote Link to comment Share on other sites More sharing options...
zenrab Posted August 6, 2008 Author Share Posted August 6, 2008 Hi Could you explain that code to me please. Where do I put the database connect info? Do I need to define the $link. Error messages at the moment all refer to the lack of connection info Notice: Undefined variable: host in /home/gourmet/public_html/control-panel/find12.php on line 12 Notice: Undefined variable: username in /home/gourmet/public_html/control-panel/find12.php on line 12 Notice: Undefined variable: password in /home/gourmet/public_html/control-panel/find12.php on line 12 Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'gourmet'@'localhost' (using password: NO) in /home/gourmet/public_html/control-panel/find12.php on line 12 Couldn't connect to MySQL: Access denied for user 'gourmet'@'localhost' (using password: NO) Many thanks zenrab Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted August 6, 2008 Share Posted August 6, 2008 put this at the very top after the <?php // remove ini_set and replace with this... error_reporting(E_ALL); put this: $link = mysql_connect($host,$username,$password); if ( ! $link ) { die( "Couldn't connect to MySQL: ".mysql_error() ); } mysql_select_db( $db_name, $link ) or die ( "Couldn't connect to database: ".mysql_error() ); after this: $host="localhost"; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name=""; // Database name Quote Link to comment Share on other sites More sharing options...
zenrab Posted August 7, 2008 Author Share Posted August 7, 2008 Hi Thank you both for your input here. I am now able to see an error. However, I will post it under a different header just in case anyone with the same error is looking for help. thanks again Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.