Jump to content

how to add data in mysql thru php


tabatsoy

Recommended Posts

1. Connect to your DB

 

mysql_connect("localhost", "admin", "admin") or die(mysql_error());

mysql_select_db("test") or die(mysql_error());

 

2. Insert that information into the DB

 

mysql_query("INSERT INTO table

(math,english,logic,total) VALUES('3', '2','5',NULL ) ")

or die(mysql_error()); 

 

 

write the sql code and run the code

 

<?php

// we connect to example.com and port 3307

$link = mysql_connect('host', 'mysql_user', 'mysql_password');

if (!$link) {

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

}

mysql_select_db($dbname);

$insert_query="insert into tablename values('1','2','3')";

$result=mysql_query($insert_query);

 

?>

complete code

 


<?php

$link = mysql_connect('host', 'mysql_user', 'mysql_password');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
mysql_select_db($dbname);
$result = mysql_query("select * from examinee
							where firstname = '".$_SESSION['bago']."'
							and lastname = '".$_SESSION['bago2']."'");
while ($row_result = mysql_fetch_array($result)) {
    $total = $row_result['math'] + $row_result['english'] + $row_result['logic'];
	echo $total;
}
?>

 

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.