Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Glasses Prescription Help Needed!!


EViLOPTiC

Recommended Posts

I am trying to find the best way to add a feature to OSC. Problem is, i have very very limited PHP skills :(

 

What i need is the means for a customer to add their Glasses Prescription so it can be saved against the users profile\account details.

 

I have the form all made etc, it writes its details to a Table called Prescription with all the fields needs by the form, with the small exception of the 1st field being Customer_ID.

 

What i need to find out is how to get the Customer id from the system so that the currently logged in users custid is saved to the table along with the prescription details. Sounds really easy, but i have no clue on where to even start!

 

Like i said, my PHP is very limited, LoL

 

once i can do this, i can add the reverse details, i.e. a QUERY to the order, based on the users personal prescription details.

 

I am in waaaaayyyyyy over my head.

 

If anyone has something like this on their site i am willing to pay for it. Failing that i shall continue blundering my way though it.

 

The form in question is located in the User Details\Members page as a seperate link called "Update Prescription". This loads the form with the details needed so the Lab can make the Glasses.

 

My Webpage

 

Any advise would be great, anyone who has already done this in one way or another who is willing to sell the code would be even greater :)

 

Please please please help me...

Link to comment
Share on other sites

What i need to find out is how to get the Customer id from the system so that the currently logged in users custid is saved to the table along with the prescription details.  Sounds really easy, but i have no clue on where to even start!
The customer_id is a session variable (so available the moment a customer logs in). See for example the page checkout_payment where it is checked if a customer is logged in:

// if the customer is not logged on, redirect them to the login page
 if (!tep_session_is_registered('customer_id')) {
   $navigation->set_snapshot();
   tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL'));
 }

Since osc ms2.2 uses the infamous "register globals" it will be available as $customer_id and if not first add to the code:

global $customer_id;

Once register globals is no longer used in the next versions of osC you would need to use $_SESSION['customer_id'] (a so called super global). Maybe not a bad idea to start using that now.

Link to comment
Share on other sites

The customer_id is a session variable (so available the moment a customer logs in). See for example the page checkout_payment where it is checked if a customer is logged in:

// if the customer is not logged on, redirect them to the login page
?if (!tep_session_is_registered('customer_id')) {
? ?$navigation->set_snapshot();
? ?tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL'));
?}

Since osc ms2.2 uses the infamous "register globals" it will be available as $customer_id and if not first add to the code:

global $customer_id;

Once register globals is no longer used in the next versions of osC you would need to use $_SESSION['customer_id'] (a so called super global). Maybe not a bad idea to start using that now.

 

Thank you very much for the prompt reply :D

 

I added the global to my dbupdate script, but the mysql INSERT record is not inserting, i take the customer_id out, and it works, lol, sorry to bug u like this, but where did i go wrong :'(

 

<?

require('includes/application_top.php');


//if (!$optSphere_L || !$optSphere_R || !$optCylinder_R || !$optCylinder_L || !$txtAxis_R || !$txtAxis_L || !$optAddition_R || !$optAddition_L || !$txtExtra)

//{

 //echo "You have not entered the correct information.<br>"
//       ."Please go back and try again.";

   // exit;
//}

global $customer_id;

$db = mysql_pconnect("localhost", "user", "password") or die("Failure to communicate with database");

mysql_select_db("glassesdb");

$query = "INSERT INTO prescription (customer_id, optSphere_L, optSphere_R, optCylinder_R, txtAxis_R, txtAxis_L, optAddition_R, optAddition_L, txtExtra) 
VALUES('$customer_id', '$optSphere_L', '$optSphere_R', '$optCylinder_R', '$txtAxis_R', '$txtAxis_L', '$optAddition_R', '$optAddition_L', '$txtExtra')";

$result = mysql_query ($query) or die("Unable to record your information.  Please click back and try again.");

print("Your prescription has been updated.");

?>

 

If i am anoying you, then sorry, please fire me out of a cannon into the sun if u want, i just want this to work :D

Link to comment
Share on other sites

I added the global to my dbupdate script, but the mysql INSERT record is not inserting, i take the customer_id out, and it works, lol, sorry to bug u like this, but where did i go wrong

Now that is mighty strange because there doesn't seem to be something wrong with the script in itself. If it is not inserting, it surely should come with an error (or there is already a row with that customer_id in the table? In that case I can imagine mysql fails without a visible error: you need another mysql command there, not insert into but update, with a "WHERE customer_id = '" . $customer_id . "' " added of course).

 

Try debugging it. E.g. after global $customer_id add:

echo '<pre>customer id is: ';
echo $customer_id;
// exit; // in case you want to stop here, uncomment

 

You could do the same with $query, that gives you feedback on what is sent to mysql (personally I would prefer to use (...VALUES('" . $customer_id . "', '" . $optSphere_L . "' ....) but this might work also.

 

After you have echo'ed the query cut and paste it into phpMyAdmin and see what it reports there. You could also better use the osC code of doing db queries. It is shorter, will keep the login name and passport centrally stored in a config file and you also get mysql errors echo'ed back.

 

In short, there is plenty of room for debugging and improvement of your script.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...