Jump to content

update existing table


esoteric

Recommended Posts

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.