esoteric Posted August 12, 2011 Share Posted August 12, 2011 I have an order system that adds all the order details to the database, once i have reviewed the order i email the customer a unique username and password that i generate at random. I want to add this new information to the existing information that is already there in teh table when i send the email but im struggling. I am trying something like mysql_connect("xxxx", "xxxxx", "xxxxx") or die( "Unable to connect to database"); mysql_select_db("orderTable") or die( "Unable to select database"); $query="INSERT INTO orderTable WHERE orderNum = '$custOrderNum'"; but im not sure how to go about adding the new data? I have created two new columns in my database called custUsername and custPassword , im trying to make it check the ordernum i type in the email against the tables existing data, and where it matches add the two new fields of data which is the username and password. Sorry if i explain this badly, hope you understand Quote Link to comment Share on other sites More sharing options...
Psycho Posted August 12, 2011 Share Posted August 12, 2011 UPDATE orderTable SET custUsername = '$username', custPassword = '$password' WHERE orderNum = '$custOrderNum' Quote Link to comment Share on other sites More sharing options...
WatsonN Posted August 12, 2011 Share Posted August 12, 2011 As I have read it you already have the inital entry with the customer order number using INSERT, so now what you will want to do is use UPDATE. mysql_query("UPDATE orderTable SET col1 = '{$col1data}', col2 = '{$col2data}' WHERE orderNum = '{$custOrderNum}'")or die(mysql_error()); If I read it right? Quote Link to comment Share on other sites More sharing options...
esoteric Posted August 12, 2011 Author Share Posted August 12, 2011 Thanks for the quick replies. @mjdamato I tried what you said, it appears to connect ok, well i get no error telling me it can't and the info is being emailed correctly but the table isnt being updated, both fields are still blank. in the script i have the following to get my input data from a form when i press submit $custuser = $_POST['custuser']; $custpass = $_POST['custpass']; then just before it sends the mail i have mysql_connect("xxxxxxx", "$username", "$password") or die( "Unable to connect to database"); mysql_select_db("membership") or die( "Unable to select database"); mysql_query (" UPDATE orderTable SET custUsername = '$custuser', custPassword = '$custpass' WHERE orderNum = '$custOrderNum' "); maybe you can see where im going wrong? @WatsonN sorry but i don't understand what col1 = '{$col1data}', is referencing, im far from skilled at this so excuse me if i sound stupid. Quote Link to comment Share on other sites More sharing options...
esoteric Posted August 12, 2011 Author Share Posted August 12, 2011 Changed it too UPDATE orderTable SET custUsername = '". $custuser ."', custPassword = '". $custpass ."' WHERE orderNum = '". $orderNum ."' Seems to have fixed it. Thanks very much for the speedy help. Quote Link to comment Share on other sites More sharing options...
WatsonN Posted August 12, 2011 Share Posted August 12, 2011 Sorry, Col1 would be the column you want to add information to and $col1data is the variable with data you want to add like $address or $name So for a Name $firstname = $_POST['FirstName']; $LastName = $_POST['LastName']; mysql_query("UPDATE orderTable SET FirstName = '{$firstname}', LastName = '{$LastName}' WHERE orderNum = '{$custOrderNum}'")or die(mysql_error()); post is from the form you were using to submit the data Is this better or do you still not understand? Quote Link to comment Share on other sites More sharing options...
esoteric Posted August 12, 2011 Author Share Posted August 12, 2011 Oh i think i understand, so if i had a column in my sql database called 'UserID' and from a form i was getting a variable called 'id' i would use UserID = '{$id}'? Also does the { brackets make a difference? So far i been using quotations and they seem to be working, or is this the wrong way to do it? Quote Link to comment Share on other sites More sharing options...
esoteric Posted August 12, 2011 Author Share Posted August 12, 2011 Also you sure seem to know you stuff so maybe you can help me with my next task? I hate keep asking for help without being able to give any myself but this is a great place to solve these problems. Now i have a form emailing the customer and updating the database correctly i need it to somehow create a new .php page from a template page i already have but with some details updated (its a invoice page). Im currently having to create them manually which is a bit of pain to be honest. I can post the whole page if it helps, if you can't help then that's fine, thought it makes sense to ask here before starting a new topic. Quote Link to comment Share on other sites More sharing options...
WatsonN Posted August 12, 2011 Share Posted August 12, 2011 Oh i think i understand, so if i had a column in my sql database called 'UserID' and from a form i was getting a variable called 'id' i would use UserID = '{$id}'? Also does the { brackets make a difference? So far i been using quotations and they seem to be working, or is this the wrong way to do it? Yes that is correct. brackets don't make a difference, that is just one way of writing. Also you sure seem to know you stuff so maybe you can help me with my next task? I hate keep asking for help without being able to give any myself but this is a great place to solve these problems. Now i have a form emailing the customer and updating the database correctly i need it to somehow create a new .php page from a template page i already have but with some details updated (its a invoice page). Im currently having to create them manually which is a bit of pain to be honest. I can post the whole page if it helps, if you can't help then that's fine, thought it makes sense to ask here before starting a new topic. I'd be glad to help in any way possible as is others in the forum. If you will post a new topic I will gladly help Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.