Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Only if data is present in database
Old 03-12-2005, 10:22 AM Only if data is present in database
cforscutt's Avatar
Novice Talker

Posts: 9
Trades: 0
Hi I am newbie so apologies for my ignorance! I am creating a business directory database that stores shops address details phone number etc. I’m currently using the following query to pull back the data from the database and display it in the PHP. I was wondering if someone could help me with the code needed to only pull back present data, for example I specify ‘Fax: $shop_fax’ so if there is a fax number it displays something like ‘Fax: 01458 12345’ but if a fax number isn’t stored im left with ‘Fax:’ and a blank space. What I need is a nifty bit of code that will only display the title if data exists, I’m sure it’s a simple thing to do, anyone know what I need? I would really appreciate the help; my e-mail address is chris@forscutt.com (cc to) cforscutt@hotmail.com

<?
if ($id) {

$result = mysql_query("SELECT * FROM $table WHERE id=$id",$db);

$links = mysql_fetch_array($result);

$id = $links["id"];
$shop_name = $links["shop_name"];
$shop_image = $links["shop_image"];
$shop_short_descr = $links["shop_short_descr"];
$shop_long_descr = $links["shop_long_descr"];
$shop_telephone = $links["shop_telephone"];
$shop_fax = $links["shop_fax"];

echo "<b>$shop_name</b><br><br>";
echo "<table width=525 border=0 cellspacing=0 cellpadding=0>
<tr>
<td width=65% valign=top>$shop_long_descr<br><br>
Tel: $shop_telephone<br>
Fax: $shop_fax
</td>
<td width=200 valign=top align=right><img src=images/shops/$shop_image alt=shopfront hspace=10></td>
</tr>
</table>";

} else {

echo "You need to select a Shop ID";

}
?>
cforscutt is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-12-2005, 10:25 AM
Gaffer Sports's Avatar
Ultra Talker

Posts: 397
Name: Steve
Location: Scotland
Trades: 1
<?
if ($id) {

$result = mysql_query("SELECT * FROM $table WHERE id=$id",$db);

$links = mysql_fetch_array($result);

$id = $links["id"];
$shop_name = $links["shop_name"];
$shop_image = $links["shop_image"];
$shop_short_descr = $links["shop_short_descr"];
$shop_long_descr = $links["shop_long_descr"];
$shop_telephone = $links["shop_telephone"];
$shop_fax = $links["shop_fax"];

echo "<b>$shop_name</b><br><br>";
echo "<table width=525 border=0 cellspacing=0 cellpadding=0>
<tr>
<td width=65% valign=top>$shop_long_descr<br><br>
Tel: $shop_telephone<br>

<? if ( $shop_fax != '')
{
echo "Fax: $shop_fax";
}
?>


</td>
<td width=200 valign=top align=right><img src=images/shops/$shop_image alt=shopfront hspace=10></td>
</tr>
</table>";

} else {

echo "You need to select a Shop ID";

}
?>

That should what you ask.

Steve.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
Gaffer Sports is offline
Reply With Quote
View Public Profile Visit Gaffer Sports's homepage!
 
Old 03-12-2005, 10:52 AM
Experienced Talker

Posts: 36
Trades: 0
Your script is also vulnerable to SQL injection. You need to filter/check ALL user input. Google could be a great help.
tress is offline
Reply With Quote
View Public Profile
 
Old 03-12-2005, 10:53 AM cheers man
cforscutt's Avatar
Novice Talker

Posts: 9
Trades: 0
thats the code I was after thank you very much for the speedy response much appreciated - your a star!
cforscutt is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Only if data is present in database
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.14558 seconds with 12 queries