Jump to content

Row/item add on previous item once I refreshs page


kelliethile

Recommended Posts

Hi guys,

 

I'm doing a To-Do-List management kind of project for school. I'm a newbie at PHP - programming in general.

I was wondering, everytime I refreshes/F5 the page, the last item would be added automatically. How to change that?

 

Here's my code (just try typing in an item, and refreshing it, you'll see what I mean)

 

<html>

<head><title>Add To List</title>

<body>

 

<form method="post" action="todolist.php">

 

<label for="item">Add item: </label>

<input type="text" name="item" id="item" size="30">

 

<br />

 

<label for="tag">Add tag: </label>

<select name="tag">

<option value="Personal" selected="selected">Personal</option>

<option value="School">School</option>

<option value="Selling">Selling</option>

</select>

 

 

<br />

 

<input type="submit" value="Add to list" />

 

</form>

 

 

<?php

 

 

// Connecting, selecting database

$link = mysql_connect('localhost', 'root', '')

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

echo '';

mysql_select_db('productivity') or die('Could not select database');

 

 

 

// Inserting data

 

if (isset($_POST['item'])) {

$item = mysql_real_escape_string($_POST['item']);

$tag = mysql_real_escape_string($_POST['tag']);

 

// Performing SQL query

$query = "INSERT INTO todo_table (item, tag)

VALUES ('$item', '$tag')";

$result = mysql_query($query) or die('Query failed: ' . mysql_error());

}

 

 

?>

 

<h2>Things To Do</h2>

 

<?php

 

// Selecting the data

 

$resultselect = mysql_query('SELECT * FROM todo_table');

 

// Fetching and displaying data

 

while($row = mysql_fetch_array($resultselect)) {

?>

 

<input type="checkbox" name="done[]"

id="<?php echo $row['id'] ?>"

value ="<?php echo $row['id'] ?>" />

 

<label for="<?php echo $row['id'] ?>">

 

<?php  echo $row['item'] . ' - tagged ' . $row['tag'];?>

</label>

 

<br />

 

 

<?php } ?>

 

<input type="submit" value="Mark Items Complete" />

 

</form>

 

 

 

 

 

 

</body>

</head>

 

 

Please help, thanks (:

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.