Wednesday, 15 August 2012

mysqli - Updating a database with simple php and mysql -



mysqli - Updating a database with simple php and mysql -

i have simple form not working. trying accomplish when user clicks update button, presented form filled in information. when alter info , click update, sent main form of changes presented. works update. when alter , click update, nil changed. here update form code:

<h4>update record</h4> <?php $con=mysqli_connect("localhost", "root", "", "customers"); //check connection if (mysqli_connect_errno()) { echo "failed connect mysql: " . mysql_connect_error(); } ?> <form action="update_process.php" method="get"> band: <input type="text" name="artist" value="<?php echo $_get['artist'] ?>"/><br/> album: <input type="text" name="title" value="<?php echo $_get['title'] ?>" /><br/> format: <select name="format"> <option value="compact disc" name="compact disc">compact disc</option> <option value="album" name="album">album</option> <option value="cassette" name="cassette">cassette</option> <option value="mp3" name="mp3">mp3</option> </select><br/> notes: <textarea name="notes" rows="3" cols="30"><?php echo $_get['notes'] ?> </textarea><br/> <input type="submit" value="update" /> </form>

and here code update_process.php file:

<?php $artist = $_get['artist']; $title = $_get['title']; $format = $_get['format']; $notes = $_get['notes']; //create connection db $con=mysqli_connect("localhost", "root", "", "customers"); //check connection if (mysqli_connect_errno()) { echo "failed connect mysql: " . mysqli_connect_error(); } $sql = "update music set title='$title', artist='$artist', format='$format', notes='$notes' id='$id'"; if ($con->query($sql) === true) { header('location:index.php'); } else { echo "error: " . $sql . "<br>" . $con->error; } ?>

in clause says id = '$id', $id value set? think $id not have value.

php mysqli

No comments:

Post a Comment