Jump to content

[SOLVED] Need help fixing script. what is wrong here?


bchandel

Recommended Posts

I am getting the following error message while running the following script. I want to find out what is wrong here and would appreciate if some one can fix it. Thank you very much in advance!

 

Parse error: syntax error, unexpected ';' in /home/blphpind/public_html/try/script.php on line 30

 

And the line 30 is

 

$d['Email'] = $d['Email'] ? "<a href='mailto:{$d['Email']}'>{$d['Email']}</a>" ? "-";

 

The complete modified script is as under:

 

<?php

$db_connect = mysql_connect("xxx.com", "user", "password");

mysql_select_db("xxx", $db_connect) or die( "Unable to select database");

$query = "SELECT * FROM Directory";

$result = mysql_query($query);

?>

<html>

<head>

<style type="text/css">

.custom {font-family: Arial, Helvetica, sans-serif; }

</style>

<head>

<body>

<h1><left>Search Results:</left></h1>

<table border="1" width="100%" cellspacing="2" cellpadding="2">

<tr>

<th class="custom">Name</th>

<th class="custom">Last Name</th>

<th class="custom">First Name</th>

<th class="custom">Phone</th>

<th class="custom">Mobile</th>

<th class="custom">E-mail</th>

<th class="custom">Web</th>

<th class="custom">State</th>

<th class="custom">Country</th>

<th class="custom">Profile</th>

</tr>

<?php

while($d = mysql_fetch_array($result)) {

$d['Email'] = $d['Email'] ? "<a href='mailto:{$d['Email']}'>{$d['Email']}</a>" ? "-";

$d['Web']    = $d['Web'] ? "<a href='{$d['Web']}>{$d['Web']}</a>" ? "-";

$d['Profile']    = $d['Profile'] ? "<a href='{$d['Profile']}>{$d['Profile']}</a>" ? "-";

 

echo "<tr>

<td class='custom'>{$d['Name']}</td>

<td class='custom'>{$d['LastName']}</td>

<td class='custom'>{$d['FirstName']}</td>

<td class='custom'>{$d['Phone']}</td>

<td class='custom'>{$d['Mobile']}</td>

<td class='custom'>{$d['Email']}</td>

<td class='custom'>{$d['Web']}</td>

<td class='custom'>{$d['State']}</td>

<td class='custom'>{$d['Country']}</td>

<td class='custom'>{$d['Profile']}</td>

</tr>";

 

}

?>

</table>

 

</body>

</html>

 

make sure you are using the code tags!

change your line from:

<?php
$d['Email'] = $d['Email'] ? "<a href='mailto:{$d['Email']}'>{$d['Email']}</a>" ? "-";
?>

 

to:

<?php
$d['Email'] = $d['Email'] ? "<a href='mailto:{$d['Email']}'>{$d['Email']}</a>" : "-";
?>

Thank you for your message. The code now look like this. still there is small mistake somewhere. see if you can figure out and correct it.

 

Thank you,

 

Bhugol

 

<?php

while($d = mysql_fetch_array($result)) {

<?php

$d['Email'] = $d['Email'] ? "<a href='mailto:{$d['Email']}'>{$d['Email']}</a>" : "-";

?>

 

<?php

$d['Web']    = $d['Web'] ? "<a href='{$d['Web']}>{$d['Web']}</a>" : "-";

?>

 

<?php

$d['Profile']= $d['Profile'] ? "<a href='{$d['Profile']}>{$d['Profile']}</a>" : "-";

?>

 

 

 

 

and I am getting this error message:

 

Parse error: syntax error, unexpected '<' in /home/blphpind/public_html/try/script.php on line 30

 

and line 30 is

<?php

$d['Email'] = $d['Email'] ? "<a href='mailto:{$d['Email']}'>{$d['Email']}</a>" : "-";

?>

Why do you have <?php

while($d = mysql_fetch_array($result)) {

<?php

$d['Email'] = $d['Email'] ? "<a href='mailto:{$d['Email']}'>{$d['Email']}</a>" : "-";

?>

 

 

I mean, you already have <?php

 

I think your problem is your continuous <?php and ?>s

Thank you for your meesage. I have revised it per your suggestion. Below is the complete revised code. I am stlll geting this error:

 

Parse error: syntax error, unexpected '<' in /home/blphpind/public_html/try/script.php on line 30

and line 30 is

 

d['Email'] = $d['Email'] ? "<a href='mailto:{$d['Email']}'>{$d['Email']}</a>" : "-";

 

Full script code is below:

 

 

<html>

<head>

<style type="text/css">

.custom {font-family: Arial, Helvetica, sans-serif; }

</style>

<head>

<body>

<h1><left>Search Results:</left></h1>

<table border="1" width="100%" cellspacing="2" cellpadding="2">

<tr>

<th class="custom">Name</th>

<th class="custom">Last Name</th>

<th class="custom">First Name</th>

<th class="custom">Phone</th>

<th class="custom">Mobile</th>

<th class="custom">E-mail</th>

<th class="custom">Web Site</th>

<th class="custom">State</th>

<th class="custom">Country</th>

    <th class="custom">Profile</th>

</tr>

<?php

while($d = mysql_fetch_array($result)) {

 

$d['Email'] = $d['Email'] ? "<a href='mailto:{$d['Email']}'>{$d['Email']}</a>" : "-";

$d['Web']    = $d['Web'] ? "<a href='{$d['Web']}>{$d['Web']}</a>" : "-";

$d['Profile']= $d['Profile'] ? "<a href='{$d['Profile']}>{$d['Profile']}</a>" : "-";

?>

echo "<tr>

<td class='custom'>{$d['Name']}</td>

<td class='custom'>{$d['LastName']}</td>

<td class='custom'>{$d['FirstName']}</td>

<td class='custom'>{$d['Phone']}</td>

<td class='custom'>{$d['Mobile']}</td>

<td class='custom'>{$d['Email']}</td>

<td class='custom'>{$d['Web']}</td>

<td class='custom'>{$d['State']}</td>

<td class='custom'>{$d['Country']}</td>

<td class='custom'>{$d['Profile']}</td>

</tr>";

 

}

?>

</table>

 

</body>

</html>

Try this anyway

<html>
      <head>
         <style type="text/css">
            .custom {font-family: Arial, Helvetica, sans-serif; }
         </style>
      <head>
   <body>
   <h1><left>Search Results:</left></h1>
   <table border="1" width="100%" cellspacing="2" cellpadding="2">
      <tr>
         <th class="custom">Name</th>
         <th class="custom">Last Name</th>
         <th class="custom">First Name</th>
         <th class="custom">Phone</th>
         <th class="custom">Mobile</th>
         <th class="custom">E-mail</th>
         <th class="custom">Web Site</th>
         <th class="custom">State</th>
         <th class="custom">Country</th>
          <th class="custom">Profile</th>
      </tr>
<?php
while($d = mysql_fetch_array($result)) {

$d['Email'] = $d['Email'] ? "<a href='mailto:{$d['Email']}'>{$d['Email']}</a>" : "-";
$d['Web']    = $d['Web'] ? "<a href='{$d['Web']}>{$d['Web']}</a>" : "-";
$d['Profile']= $d['Profile'] ? "<a href='{$d['Profile']}>{$d['Profile']}</a>" : "-";

   echo "<tr>
         <td class='custom'>{$d['Name']}</td>
         <td class='custom'>{$d['LastName']}</td>
         <td class='custom'>{$d['FirstName']}</td>
         <td class='custom'>{$d['Phone']}</td>
         <td class='custom'>{$d['Mobile']}</td>
         <td class='custom'>{$d['Email']}</td>
         <td class='custom'>{$d['Web']}</td>
         <td class='custom'>{$d['State']}</td>
         <td class='custom'>{$d['Country']}</td>
         <td class='custom'>{$d['Profile']}</td>
      </tr>";

}
?>
   </table>

   </body>
   </html>

Thank you for your help. I loaded the script. See display by visiting

 

http://www.chandel.com/try/script.php

 

The data is in wrong columns and long URLs are there as well. But seems close to success. may need to move things around.

 

Is there any other way to achieve the same results?

 

Thank you,

 

Bhugol Chandel

 

$d['Email'] = $d['Email'] ? "<a href='mailto:{$d['Email']}'>{$d['Email']}</a>" : "-";
$d['Web']    = $d['Web'] ? "<a href='{$d['Web']}>{$d['Web']}</a>" : "-";
$d['Profile']= $d['Profile'] ? "<a href='{$d['Profile']}>{$d['Profile']}</a>" : "-";

 

Look, you have to close the href on your web and profile

How to close and where to close? What would be the correct format for:

 

d['Email'] = $d['Email'] ? "<a href='mailto:{$d['Email']}'>{$d['Email']}</a>" : "-";

 

$d['Web']    = $d['Web'] ? "<a href='{$d['Web']}>{$d['Web']}</a>" : "-";

 

$d['Profile']= $d['Profile'] ? "<a href='{$d['Profile']}>{$d['Profile']}</a>" : "-";

 

Try looking at your page in Chrome, it'll help. I'll show you

 

$d['Web']    = $d['Web'] ? "<a href='{$d['Web']}>{$d['Web']}</a>" : "-";

 

$d['Profile']= $d['Profile'] ? "<a href='{$d['Profile']}>{$d['Profile']}</a>" : "-";

 

I put blue to show you what's being considered the URL. Put a ' after {$d['Web']} and {$d['Profile']}

Put ' at the very end of {$d['Web']}' and {$d['Profile']}' . Checked in Chrome.

 

Now the E-mail, Web and profile hyperlink are missing. Need to try may be one last time. Coming close to victory.

 

$d['Email'] = $d['Email'] ? "<a href='mailto:{$d['Email']}>{$d['Email']}</a>" : "-";

$d['Web']    = $d['Web'] ? "<a href='{$d['Web']}>{$d['Web']}'</a>" : "-";

$d['Profile']= $d['Profile'] ? "<a href='{$d['Profile']}>{$d['Profile']}'</a>" : "-";

Put this in, it'll work

 

$d['Email'] = $d['Email'] ? "<a href='mailto:{$d['Email']}'>{$d['Email']}</a>" : "-";
$d['Web']    = $d['Web'] ? "<a href='{$d['Web']}'>{$d['Web']}</a>" : "-";
$d['Profile']= $d['Profile'] ? "<a href='{$d['Profile']}'>{$d['Profile']}</a>" : "-";

 

You were meant to put it in at href='{$d['Web']} not at >{$d['Web']}</a>

 

The code above should work

Thank you. It made it lot better. Check it at http://chandel.com/try/script.php

 

The only problem is these long URLs. It should only read Email, Web and Profile which is not happening. See what else left to be fixed below:

 

$d['Email'] = $d['Email'] ? "<a href='mailto:{$d['Email']}'>{$d['Email']}</a>" : "-";

 

$d['Web']    = $d['Web'] ? "<a href='{$d['Web']}'>{$d['Web']}</a>" : "-";

 

$d['Profile']= $d['Profile'] ? "<a href='{$d['Profile']}'>{$d['Profile']}</a>" : "-";

Instead for long URL in Email, Website, and Profile fields it shoud read say Send E-mail, Website, View Profile. Don't want Long URLS

 

It will be something like in this format

 

<a href="http://www.chandel.com">Go to Website</a></p>

I hope I am able to make it clear.

 

 

 

I'm sorry, but do you know much about PHP at all? Try this

 

$d['Email'] = $d['Email'] ? "<a href='mailto:{$d['Email']}'>Email</a>" : "-";
$d['Web']    = $d['Web'] ? "<a href='{$d['Web']}'>Website</a>" : "-";
$d['Profile']= $d['Profile'] ? "<a href='{$d['Profile']}'>Profile</a>" : "-";

 

All I did was replace the variables from the link text with constant strings

Finally I got this figured out.

 

Here what I did. It is working fine now. I really appreciate your help and patience. Do you work on projects? let me know. I still have to fix few things like table look and to avoid cells without data to merge.

 

Thank you again very much. People like you make this world wonderful.

 

$d['Email'] = $d['Email'] ? "<a href='mailto:{$d['Email']}'>E-mail</a>" : "-";

 

$d['Web']    = $d['Web'] ? "<a href='{$d['Web']}'>Web Site</a>" : "-";

 

$d['Profile']= $d['Profile'] ? "<a href='{$d['Profile']}'>Profile</a>" : "-";

 

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.