Jump to content
Larry Ullman's Book Forums

luisfalcon

Members
  • Posts

    9
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by luisfalcon

  1. hello Mr Ullman: I am currently building an application using stripe. I ran into the following problem. I have members on the applications who sell their goods. anonymous users come and pay for those goods. I can create the charge on stripe and send the money to my users no problem. However, I want to charge my users a percentage, or a flat fee, from that transaction. ex: (This is a fictional example!! i don't have a old underwear selling site). Members of my site post and sell their old underwear using my platform. people visit the site, they like the underwear and they decide to buy it. the underwear costs 100$ (overpriced but whatever). i want to take lets say 5% of that transaction for me (for providing the platform in which they sell their underwear) and the rest of the money send it to my member. I do not want to charge the credit card of the buyer 2ce because he only should make one payment from the checkout. I want to take the money from the total amount, split it in 2 and send 1 to the stripe account of my member, and the other amount (the 5%) to my application's (my own) account. I have looked to solve this problem for like a month now and I am stuck. This is the last thing I need to implement before starting beta tests with some of my members. Do you know How I would go about doing this? I thank you in advance for any help I can get on this issue (or to any forum member who can remove this block I have had for a while). Thanks =)
  2. SELECT `AUTO_INCREMENT` FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'database_name' AND TABLE_NAME = 'table_name'; with this command you can get the auto increment value for the table that you want. so you could build your insert using a subquery like this $q3 = "INSERT INTO movie_actor (movie_no,actor_no,rate) VALUES ( SELECT `AUTO_INCREMENT` FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'movie' AND TABLE_NAME = 'table_name', SELECT `AUTO_INCREMENT` FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'actor' AND TABLE_NAME = 'table_name', '$rate'); but this is an ugly solution. that subquery is a mess. You could use the last_inserted_id() function on a select statement and run the query and assign it to a variable then use those variables on your query. But this is not a super good solution either i think since you have to hit the database too many times. Now think of this word (auto_increment) Meaning that it increases all the time so the last id inserted on a table is the biggest one too!!! So going back to sub-queries you could do the approach from the first answer i gave (the ugly one) but with a simpler and prettier query: $q3 = "INSERT INTO movie_actor (movie_no,actor_no,rate) VALUES (SELECT MAX(id) FROM movies, SELECT MAX(id) FROM actor, $rate); =) hope this helps... sorry for the long post =)
  3. SELECT `AUTO_INCREMENT` FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'database_name' AND TABLE_NAME = 'table_name'; with this command you can get the auto increment value for the table that you want. so you could build your insert using a subquery like this $q3 = "INSERT INTO movie_actor (movie_no,actor_no,rate) VALUES ( SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'movie' AND TABLE_NAME = 'table_name', SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'actor' AND TABLE_NAME = 'table_name', '$rate'); but this is an ugly solution. that subquery is a mess. You could use the last_inserted_id() function on a select statement and run the query and assign it to a variable then use those variables on your query. But this is not a super good solution either i think since you have to hit the database too many times. Now think of this word (auto_increment) Meaning that it increases all the time so the last id inserted on a table is the biggest one too!!! So going back to sub-queries you could do the approach from the first answer i gave (the ugly one) but with a simpler and prettier query: $q3 = "INSERT INTO movie_actor (movie_no,actor_no,rate) VALUES (SELECT MAX(id) FROM movies, SELECT MAX(id) FROM actor, $rate); =) hope this helps... sorry for the long post =)
  4. OK, after so much research (and a lot of trial and error). I found the solution to the problem. Here it is : Since browsers cache the pages and every time you visit a site or press the back button all you received is the cached version of the page (including the information that was submitted on a form). When you press the back button the cache version of the page will be taken ( in the case of the login the Resubmit Form page will appear and if you refresh you are back on). The solution is not letting the browser cache the page that has the submission. So to do this we just need to change the "header" to something else so that the browser chaches something different than the login info. For those who do not understand (and i am pretty sure nobody will get my vague ideas and mind mess till they try it lol). Try to do this on the application. Add the following line of code on your login.inc.php right after you set all the session variables. (right at the end of the password_verify conditional) if (password_verify($p, $row['pass'])) { //all the code here header('Location: index.php') // this is the line that will fix the error } the solution i found it reading this article http://en.wikipedia.org/wiki/Post/Redirect/Get I am aware that I probably did not give the most clear explanation out there so if there are any doubts and someone still has this problems please just ask your question and i will happily help out. Thanks and sorry for the long post.
  5. check this command. SELECT * FROM `information_schema`.`INNODB_SYS_INDEXES` WHERE table_id = (select table_id from `information_schema`.`INNODB_SYS_TABLES` where name = 'database_name/table_name') this will give you the name of all the indexes created for that table. named or unnamed. created by you or the system. you could use this to build another level of subquery to automatically select the right index and drop it. you could also run it like this SELECT * FROM `information_schema`.`INNODB_SYS_INDEXES` WHERE table_id = (select table_id from `information_schema`.`INNODB_SYS_TABLES` where name like '%table_name') However, if more than one database have tables with same names, it will return indexes for all those tables. so the first syntax is more specific. Hope this helps though late. =)
  6. Hello. Your instructor is right. relationships are not needed between tables. However, you should do them since mysql is after all a Relational database management system. The foreign key relationships ensures referential integrity, which means, that you are making sure that the data in the child table is directly mapped to an existing value on the parent table. If this "referential integrity" between tables is not maintain then some garbage values can be imputed. If you do not build the relationship, you or malicious users, could enter a product id in the sales tables even if the item does not really exist in your products table. Which can create a lot of garbage values. If mysql does not let you create relationships it might be because: 1) the type of the data (int, varchar, etc) in the fields used for the primary/foreign key relationship are not the same. This happens because you cannot say that the value on an id (which is numeric usually) will map to a string value. 2) A foreign key on other tables or fields with the same name already exists (keys are objects. Just like tables, views, and others, you cannot have more than 1 of the same name). 3)The relationship in fact already exists. If i forget any please someone quote and add =). Hope this helps =). I also recommend reading about database normalization and being familiar with at least the 1st, 2nd, and 3rd normal forms. Sorry for the long POST =).
  7. Hello Mr. Ullman. Yes please, I do still need help with this. I have tried different forums and methods to avoid that from hapenning. Changing headers to avoid browser chaching pages and others. but I still have the problem I you, or anyone reading the forum could help me out I would very much appreciate it. Thank you again.
  8. I confirm if i Close the browser of course I cannot access the page. There is no information in the browser back button stack to get the error and the page cannot be access without the session variables. I output the session array after i log out and it is indeed empty. I think this error is more on how the login process is done than the output. It is as if when i press the back button on the browser my login form gets re submitted and I am all of a sudden back on the site. One solution I thought about was completely separating the login process (i.e. having a page alone by itself do the login form and log in by redirecting the page to the index.php) in this case the headers would change and I do not think i would have this problem, what do you think? but again I really like the design of having the login as it is in the book. I will keep trying to find a solution. If someone can find one Please share =). Thank you again MR. Ullman... Again great book, I am planning on buying some more of your collection. =)!!! keep on writing !!!!
  9. Hello: I am reading this book and following on the examples. I finished the ex1 and I am testing the site. I notice that When i Log out from an account then refresh the page I go back to the index.php (which is OK). Now the problem is when i use the back button of the browser. If i go back to the log out page then back again (to the page where I logged out from) at first there will be an error, but if i refresh the page There i am logged back in with all the credentials as if i never logged out. This of course is a flaw. Imagine I am on an public place and I log out of a site and go. then someone (accidentally or maliciously) sits on the same pc and hits back on the browser twice and all of a sudden he is logged in on my account. My question is: How can i fix this security hole ? can someone point me in the right direction? Thank you. By the way Mr Ullman, if you reading this GREAT BOOK!!!. Sorry for the long post. Thank you in advance to all who answer.
×
×
  • Create New...