Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

Creating your first PHP page with MySql interaction in Web
#1

Code:
<?php
$con = mysql_connect(<servername>,<username>,<passwd>);
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

// Create table
mysql_select_db(<db name>, $con);

$sql = "CREATE TABLE myTable (firstname VARCHAR(20), lastname VARCHAR(20), age INT);"
// Execute query
mysql_query($sql,$con);

$sql = "INSERT INTO myTable VALUES ("somanath", "reddy", 23);"
// Execute query
mysql_query($sql,$con);

$data = mysql_query("select *from myTable");

Print "<table border cellpadding=3>";
while($info = mysql_fetch_array( $data ))
{
Print "<tr>";
Print "<th>FirstName:</th> <td>".$info['FirstName'] . "</td> ";
Print "<th>LastName:</th> <td>".$info['LastName'] . " </td>";
Print "<th>Age:</th> <td>".$info['Age'] . " </td></tr>";
}
Print "</table>";

mysql_close($con);
?>
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)