Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Php MySql problems

Status
Not open for further replies.

may1hem

Programmer
Jul 28, 2002
262
GB
Hi there,

I wonder if anyone can help? In my online shop which is created using php and MySql db, I have created a page where the client has to submit contact details to our MySql db, another page which lets the user review the submitted details and a third page from where the user can change the submitted contact details. Now, my problem is that:

1. The user details in the review page and in the change details page contain information from the last entered row in the database. That can cause problem in case there are 2 or more users submitting their contact details at nearly the same time, as the last entered row in the db is not going to match their entry. I think using session object would solve the problem here, but I have no idea how to do it.

2. The second problem that concerns me is that at the moment my page adds a new row to the db every time the data is submitted. I want to stop that and add a new row to the db only if the same item within that particular order with the same quantity doesn't exist already.

Can anyone help please?

Thanks

May
 
For #1, a session variable is a good idea, provided you store the right information in the session variable. Use an auto_increment column in the table and make sure every time to fetch the row ID generated when you insert a row (see mysql_insert_id() . The auto_increment number is maintained on a per-connection basis, so each user will have his own ID.

For #2, your script is going to have to check the table with a SELECt query before it inserts a row.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Hi
I have a problem getting something probably very simple to work but cannot see how to achieve it. The following works perfectly:
<?php

$db = mysql_connect("localhost", "username", "password");

mysql_select_db("helpdesk_calls",$db);

$query = ("select calls from yr2004");

$result = mysql_query($query);

while ($array = mysql_fetch_array($result, MYSQL_NUM)){

foreach ($array as $value) {

echo "$value, ";

?>

However what I want to do is put the array into a comma separated string instead of printing it to screen. I have tried using implode unsuccessfuly. The string is going into a script I have downloaded which places a graph into the browser.
The graph script works when the values are manually inserted and what I need to do is tie the array to the graph and I am done.

Many thanks
 
provide the code you used to implode the array. I believe that this is the simplest answer and maybe you did it wrong.
 
Thanks for your help sleipnir214! The solution for the first issue is clear and it does what I need but the second solution is not very clear for me, what should I select from the table?

Your help is appreciated!

May
 
Don't you want to know how many records with that item and quantity are in the table?

It sounds to me like the query will read something like "SELECT count(*) from .... WHERE ..."



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top