logo-dw

Go Back   Dreamweaver Club Forums > Hand Coders Forum > PHP
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 09-12-2012, 09:07 PM   #1
tony09uk
 
Join Date: Oct 2010
Posts: 340
Default UPDATE row

Can anyone tell me why this isnt working?

Its not throwing up any errors either, so Im kinda stuck.

Ive been trying for over an hour now but cant work it out.

<?php

include('connection.php');


if(!isset($_POST['submit'])){
$id = $_GET['id'];
}else{
$id = $_POST['id'];
}

$query = "SELECT * FROM people WHERE id = $id";
$result = mysqli_query($link, $query);

while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){

$name = $row['name'];
$age = $row['age'];
$hobby = $row['hobby'];
echo $name . $age . $hobby;

}

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

$id = $_POST['id'];
$update = "UPDATE people
SET name = '$name',
age = '$age',
hobby = '$hobby'
WHERE id = $id
LIMIT 1";
$r = @mysqli_query($link, $update) or die(mysqli_error($link));

if(mysqli_affected_rows($link)){
echo "done";
}else{
echo mysqli_error($link);
}

}

?>

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<?php
// put your code here

?>

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

<p>Name<input type="text" name="name" value="<?php echo "$name"; ?>" /></p>
<p>Age<input type="text" name="age" value="<?php echo "$age"; ?>" /></p>
<p>Hobby<input type="text" name="hobby" value="<?php echo "$hobby"; ?>" /></p>
<p><input type="hidden" name="id" value="<?php echo "$id"; ?>" /></p>
<p><input type="submit" name="submit" value="SUBMIT" /></p>

</form>
</body>
</html>
tony09uk is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:15 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com