Jump to content

blank result page


zenrab

Recommended Posts

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>";

}

}

}

?>

Link to comment
https://forums.phpfreaks.com/topic/118398-blank-result-page/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/118398-blank-result-page/#findComment-609392
Share on other sites

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>";
}
}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/118398-blank-result-page/#findComment-609393
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/118398-blank-result-page/#findComment-609398
Share on other sites

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() );

Link to comment
https://forums.phpfreaks.com/topic/118398-blank-result-page/#findComment-609400
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/118398-blank-result-page/#findComment-609404
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/118398-blank-result-page/#findComment-609406
Share on other sites

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.