Jump to content

can some one explain this code line by line


gibigbig

Recommended Posts

<?php

$con = mysql_connect("localhost","peter","abc123");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }mysql_select_db("my_db", $con);$sql="INSERT INTO person (FirstName, LastName, Age)

VALUES

('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";if (!mysql_query($sql,$con))

  {

  die('Error: ' . mysql_error());

  }

echo "1 record added";mysql_close($con)

?>

 

<?php
// connect to database localhost with username peter and password abc123
$con = mysql_connect("localhost","peter","abc123");

// if the connection did not take do inside the if.
if (!$con)
  {
  // kill the script as a db connection could not be made
  die('Could not connect: ' . mysql_error());
  }
// select the database (my_db) we wish to use with our db connection
mysql_select_db("my_db", $con);
// insertt data into the database using POST data from a form.
$sql="INSERT INTO person (FirstName, LastName, Age)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";

// if the query returns false for $sql than die and print out the error
if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }

// print that everything went good.
echo "1 record added";
// close the connection.
mysql_close($con)
?> 

Look at this line right here:

 

<?php

$sql="INSERT INTO person (FirstName, LastName, Age)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";

?>

 

It does specify a table.

 

INSERT INTO person

 

"person" is the name of the table that you are storing the information in.

 

EDIT: Geez your fast Frost, haha.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.