Jump to content

problem with php-mysql connectivity


Recommended Posts

am having a small problem with my php-mysql connectivity. am entering values in a form and retrieving them in a atabase.But if i go on the refresh link the previous values gets added again.

the code is below:

<html>

<head>

<title>

this is a program

</title>

</head>

<body>

<form method="post">

<input type="hidden" name="act" value="add"/>

<table width="700" border="0" cellpadding="2" cellspacing="1" align="center">

<tr>

<td width="100">Title</td>

<td><input name="title" type="text"></td>

</tr>

<tr>

<td width="100">Content</td>

<td><textarea name="content" cols="50" rows="10"></textarea></td>

</tr>

<tr>

<td width="100"> </td>

<td> </td>

</tr>

<tr>

<td colspan="2" align="center"><input name="save" type="submit" value="Save Article"></td>

</tr>

</table>

</form>

<?php

//unset($_POST["act"]);

if($_POST["title"]=="")

{

echo "Please enter a title";

exit();

}

if($_POST["act"]=="add")

{     

    echo $_POST["act"];

$username="root";

$password="";

$host="localhost";

/*$fd=*/mysql_connect($host,$username,$password) or die("Error connecting to MySQL");

$dbname='cms2';

@mysql_select_db($dbname) or die("Unable to select database");

$field1=$_POST["title"];

$field2=$_POST["content"];

$field3=$_POST["act"];

/* $field4=$_POST["Headline"];

$field5=$_POST["Article"];*/

unset($_POST);

$query="CREATE TABLE cmstable(id int (6) NOT NULL auto_increment,title varchar(15) NOT NULL,content varchar(100) NOT NULL,act varchar(20) NOT NULL,PRIMARY KEY(id), UNIQUE id (id),KEY id_2 (id))";

mysql_query($query);

$query="INSERT into cmstable VALUES('','$field1','$field2','$field3')";

mysql_query($query);

    mysql_close();

exit();

}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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