Using php and mysql how do I insert data into a column in my tables based on that...

  • Thread starter Thread starter aed_422
  • Start date Start date
A

aed_422

Guest
...member who is logged in?
Thank you for that answer it doesnt answer my question though..

in my situation I already have the columns with firstname, lastname, age done. by say later on peter logs in and submits a form which says hes from chicago. how would I add chicago in a column for peter based on that fact that peter is logged in and not glenn
 
The first form doesn't specify the column names where the data will be inserted, only their values:
INSERT INTO table_name
VALUES (value1, value2, value3,...)

The second form specifies both the column names and the values to be inserted:
INSERT INTO table_name (column1, column2, column3,...)
VALUES (value1, value2, value3,...)

Example
<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("my_db", $con);

mysql_query("INSERT INTO Persons (FirstName, LastName, Age)
VALUES ('Peter', 'Griffin', '35')");

mysql_query("INSERT INTO Persons (FirstName, LastName, Age)
VALUES ('Glenn', 'Quagmire', '33')");

mysql_close($con);
?>
 
Back
Top