Skip Navigation Links
EZWEB
PHPExpand PHP

Adding New Information

Syntax:

$query=insert into tablename(col1,col2,col3…) values(‘var1’,’var2’,’var3’...);
$result=mysql_query($query) or die(“cannot add”);

 

Add.html:
Add to Database in PHP

Code Example:

1

<html><head></head>

2

<body>

3

<?

4

require( ‘db_params.php’ ); 

5

$connection=mysql_connect(DB_HOST,DB_USER,DB_PW) or die("Could not connect");

6

$db=mysql_select_db(DB_NAME) or die("Cannot select database");

7

$name=$_POST["name"];;

8

$comments=$_POST["comments"];

9

$q= "insert into mysurvey (myname,comment)Values('$name','$comments')";

10

$result = mysql_query($q);

11

mysql_close($connection);

12

?>

13

<p><a href="viewdata.php">View</a></p>

14

</body></html>

Save as: Add.php

You have to modify the viewdata.php so it does no cache the page
Add this code to the top of the page:


1

<?

2

header('Cache-Control: no-store, no-cache, must-revalidate');

3

header('Cache-Control: post-check=0, pre-check=0', FALSE);

4

header('Pragma: no-cache');

5

?>





Free Tutorials and Training