Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

A PHP/MySQL question


noob

Recommended Posts

ok i basically want a function thattakes $id from url and shoes the according stuff

and if the id doesnt exist then i want it to say wrong id - thats teh part its not doing

hers the simple code:

if(isset($id)){
mysql_connect('localhost');
mysql_select_db('test');

$result = @mysql_query("SELECT cool FROM tbl1 WHERE id = '$id'");

if(!$result){

echo "wrong id";

} else {
$result = @mysql_query("SELECT cool FROM tbl1 WHERE id = '$id'");
while ($row = mysql_fetch_array($result)) { 
echo '<p>' . $row['cool'] . '</p>'; 
}
}
} else {
echo "no id";
}

can anyone see what im doing wrong?

Checkout my osc contrib here!

You can also checkout the site im working on by clicking the card button!

Link to comment
Share on other sites

Try:

 

if(isset($id))
{
 mysql_connect('localhost');
 mysql_select_db('test');

 $result_query = tep_db_query("select count(*) as count from tbl1 WHERE id = '" . $id . "'");
 $result = $apm = tep_db_fetch_array($result_query);
 if($result['count'] < 1)
 {
   echo "wrong id";
 }
 else
 {
   $row_query = tep_db_query("SELECT cool FROM tbl1 WHERE id = '" . $id . "'");
   while ($row = tep_db_fetch_array($row_query))
   {
     echo '<p>' . $row['cool'] . '</p>';
   }
 }
}
else
{
 echo "no id";
}

Your online success is Paramount.

Link to comment
Share on other sites

WOOT!

it worked

i just had to change tep_db to mysql

because i was trying it on a separate page

whats teh difference betwen them?

Checkout my osc contrib here!

You can also checkout the site im working on by clicking the card button!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...