Wednesday, August 5, 2009

PHP script help?

Ok first off my goal



I have a website where I am selling multiple products from home thought I had everything set up but come to find out when the item sells it is not deleted which could cause a problem if multiple people order and I am out of stock so I am have created a database using MySQL that is hosted on a web server the database has 1 table with 2 rows one row is the product description and the other a field that tells if it is avalaible



I need to create a page that has a button on it to check if the product is available and if it is available to return with a webpage %26quot;examplepage1.html%26quot; and if not available return with a seperate webpage %26quot;examplepage2.html%26quot;



I also need to have a way of deleting it from the database if it is bought



When using a webpage with php script to do these tasks do I need to connect to the database using the host, user, password set?



sorry for all the questions but I am in desperate need of accomplishing this as I cannot start business until the page is repaired with this inventory managment



I appriciate any code examples or refereces anyone can give me ty for your time.



PHP script help?





OSCommerce is a free, open-source and powerful PHP/MySQL shopping cart. You can set inventory levels and choose to either remove the product from view or have it marked as out of stock. You can also allow checkout on out of stock items while alerting your customers there is going to be a delay.



PHP script help?



Firstly, you%26#039;re probably better having a row for each type of product.



It sounds like you%26#039;re a little over your head, but don%26#039;t worry, we%26#039;ll help you out :)



[1] is a tutorial explaing the mySQL bindings in PHP. This will teach you how to set everything up and how to connect to your database.



To get any work done, you will need to know some SQL. This is a simple language that you use to tell your database what to do. [2]



will teach you everything you need to know about SQL.



To delete stuff from the database you will want the %26quot;DELETE FROM%26quot; command (dont expect that to make sense till you know some sql)



Hope this helps :)



Other Replys:It is hard to give you the information you are asking for. You will have a hard time getting this to work.



Since you are talking about a business, I suggest you get help.



You can email me and I can help you.



ryan@devsanctum.com



Other Replys:I don%26#039;t quite get the 1 table, 2 rows statement. Should it be 2 columns, where one column is the %26quot;description%26quot; and the second the %26quot;availability%26quot;, like:



description | avalable



----------------------------



my item1 | yes



my item2 | yes



my item3 | no



Anyway, if I got it right, here%26#039;s how I%26#039;d go about it.



I%26#039;d add a new column for an ID so that can find things faster. I%26#039;ll probably end up with something like:



id | description | available



----------------------------------



1 | my item1 | yes



2 | my item2 | yes



3 | my item3 | no



Then on the button that you say you%26#039;ll put, I%26#039;ll have an href %26quot;checkAvailable.php?id=xxx%26quot;, where %26quot;xxx%26quot; is the `id` of the item.



In checkAvailable.php, I%26#039;ll write something like:



$myItem = $_GET[%26quot;id%26quot;] ;



$sql = %26quot;select `available` from `theTable` where `id`=%26#039;%26quot; . mysql_real_escape_string ($myItem) . %26quot;%26#039; ;%26quot; ;



$result = mysql_query($sql) ;



// check is there%26#039;s a result



if ($result) {



// see if it%26#039;s available and redirect



if (mysql_result($result,0) == %26quot;yes%26quot;) {



header(%26quot;location: examplePage1.html%26quot;) ;



} else {



header(%26quot;location: examplePage2.html%26quot;) ;



}



} // end of first IF



else {



echo %26quot;What are you taking about?%26quot; ;



}



...wasn%26#039;t able to check this though. Anyway, this link maybe useful:



http://www.php.net/function.mysql-result



Other Replys:A good question would be... is your PHP script built from scratch? Or are you using an existing solution like osCommerce or ZenCart?



The one I recommend to most of my clients is Drupal%26#039;s eCommerce package. You%26#039;ll definitely want to have a long look at it before deciding on anything else... at the very least, you%26#039;ll know what you%26#039;re missing {grin}



http://drupal.org



http://drupal.org/project/ecommerce



Setting up a demo store wouldn%26#039;t take that long, if you wanted something to experiment with before going %26quot;live%26quot;. Especially if your web host has cPanel and Fantastico installed.

No comments:

Post a Comment