nockemout Posted November 4, 2010 Posted November 4, 2010 Does this function need arguments? I see it in my application-top which i've included in my page's header. I'd like to start moving data over to SQL, and I need to know if // make a connection to the database... now tep_db_connect() or die('Unable to connect to database server!'); is enough to establish a connection to the db, and if I can proceed to use tep_db_perform on my page. Thanks
♥FWR Media Posted November 4, 2010 Posted November 4, 2010 Does this function need arguments? I see it in my application-top which i've included in my page's header. I'd like to start moving data over to SQL, and I need to know if // make a connection to the database... now tep_db_connect() or die('Unable to connect to database server!'); is enough to establish a connection to the db, and if I can proceed to use tep_db_perform on my page. Thanks No the function does not need arguments the arguments are preset using defines from includes/configure.php. As long as includes/application_top.php is included at the top of the file attempting to access the database then all of the tep_db_ functions will work. Ultimate SEO Urls 5 PRO - Multi Language Modern, Powerful SEO Urls KissMT Dynamic SEO Meta & Canonical Header Tags KissER Error Handling and Debugging KissIT Image Thumbnailer Security Pro - Querystring protection against hackers ( a KISS contribution ) If you found my post useful please click the "Like This" button to the right. Please only PM me for paid work.
nockemout Posted November 4, 2010 Author Posted November 4, 2010 Thanks. I just tried it myself and I have a live connection. Now, I have a question about tep_db_perform() Here's the code I've tried for storing some custom input $customers_petName = tep_db_prepare_input($HTTP_POST_VARS['customers_petName']); $customers_petPhoto = tep_db_prepare_input($HTTP_POST_VARS['customers_petPhoto']); $sql_data_array = array('customers_petName' => $customers_petName, 'customers_petPhoto' => $customers_petPhoto); tep_db_perform(customers, $sql_data_array, 'update') I'm getting the error: ]1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 update customers set customers_petName = 'MyDawg', customers_petPhoto = 'examples_adultdogs.png' where [TEP STOP] I'd like for it to do something like this: $customer_id = $_POST["customer_id"]; $breedName = $_POST['breedName']; $age = $_POST['age']; $weight = $_POST['weight']; $con = mysql_connect("XXXXX","XXXXXXXX","XXXXXXXX"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("XXXXXXXX", $con); $query = sprintf( "UPDATE customers SET customers_breed = '%s', customers_age = '%s', customers_weight = '%s' WHERE customers_id = '%s'", $breedName, $age, $weight, $customer_id ); mysql_query($query, $con) or die(mysql_error()); How can I do this and retain my session AND have the data land in the appropriate user's table in SQL?
nockemout Posted November 4, 2010 Author Posted November 4, 2010 Im thinking I have to have a customer_id variable or something to ID the user to the acct (which has already been created)
♥FWR Media Posted November 4, 2010 Posted November 4, 2010 Something like this: - $customer_id = (int)$_POST["customer_id"]; $breed_name = tep_db_prepare_input( $_POST['breedName'] ); $age = (int)$_POST['age']; $weight = tep_db_prepare_input( $_POST['weight'] ); $sql_data_array = array( 'customers_breed' => tep_db_input( $breed_name ), 'customers_age' => tep_db_input( $age ), 'customers_weight' => tep_db_input( $weight ) ); tep_db_perform( 'customers', $sql_data_array, 'update', 'customers_id = \'' . $customer_id . '\'' ); Ultimate SEO Urls 5 PRO - Multi Language Modern, Powerful SEO Urls KissMT Dynamic SEO Meta & Canonical Header Tags KissER Error Handling and Debugging KissIT Image Thumbnailer Security Pro - Querystring protection against hackers ( a KISS contribution ) If you found my post useful please click the "Like This" button to the right. Please only PM me for paid work.
nockemout Posted November 5, 2010 Author Posted November 5, 2010 It looks like my session expired or something, and I'm getting a customer_id of 0 and my data isn't transferring properly Would it make more sense to pull the customer's id from the db, rather than from the post vars?
nockemout Posted November 5, 2010 Author Posted November 5, 2010 Even as a new customer, my customer_id is 0
nockemout Posted November 5, 2010 Author Posted November 5, 2010 I think i've figured it out. at the top of my signup pages, I have <?php include 'includes/application_top.php'; if (!tep_session_is_registered('customer_id')) { $navigation->set_snapshot(); tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL')); } else { $customer_id = $_SESSION['customer_id']; echo $customer_id; } ?> Looks like it's working. Hopefully someone can tell me if I'm right. lol. I'm excited about learning PHP and this platform!!
nockemout Posted November 5, 2010 Author Posted November 5, 2010 and finally.. Thanks so much Robert you've been a great help!
♥FWR Media Posted November 5, 2010 Posted November 5, 2010 and finally.. Thanks so much Robert you've been a great help! My pleasure re: $customer_id I wasn't even considering the validity of the variables just offering a working idea for the solution. Ultimate SEO Urls 5 PRO - Multi Language Modern, Powerful SEO Urls KissMT Dynamic SEO Meta & Canonical Header Tags KissER Error Handling and Debugging KissIT Image Thumbnailer Security Pro - Querystring protection against hackers ( a KISS contribution ) If you found my post useful please click the "Like This" button to the right. Please only PM me for paid work.
nockemout Posted November 5, 2010 Author Posted November 5, 2010 I see. I may start a new thread, but I'll ask here first: I'd like to be able to display customer fields from SQL after their identity has been verified. I saw something similar to this in includes/functions/general.php : if (tep_session_is_registered('customers_petName') && tep_session_is_registered('customer_id')) { } Is this in the right direction? I'm continuing here: http://www.oscommerce.com/forums/topic/366623-customer-dashboard/
Recommended Posts
Archived
This topic is now archived and is closed to further replies.