php - data from my database won't show up -
i trying update data database don't show when go edit page. help? thank you.
index.php
<?php include_once('db.php'); if(isset($_post['description'])) { $description = $_post['description']; if(mysql_query("insert values('','$description')")) echo "sucacessful update"; else echo "please try again"; } $res = mysql_query("select * about"); ?> <form action = "." method="post"> name <input type = "text" name="description"><br/> <input type="submit" value="save"> </form> <?php while( $row = mysql_fetch_array($res) ) echo "$row[id]. $row[description] <a href='edit.php?edit=$row[description]'>edit</a><br />"; ?>
edit.php
<?php include_once('db.php'); if( isset($_get['edit']) ) { $id = $_get['edit']; $res= mysql_query("select * id='$id'"); $row= mysql_fetch_array($res); } if( isset($_post['newdescription']) ) { $newdescription = $_post['newdescription']; $id = $_post['id']; $sql = "update set description='$newdescription' id='$id'"; $res = mysql_query($sql) or die("could not update".mysql_error()); echo "<meta http-equiv='refresh' content='0;url=index.php'>"; } ?> <form action="edit.php" method="post"> name: <input type="text" name="newdescription" value="<?php echo $row[1]; ?>"><br /> <input type="hidden" name="id" value="<?php echo $row[0]; ?>"> <input type="submit" value=" update "/> </form>
the name table , have 2 columns id , description. 1 i'm trying here edit description column through php.
pass row's id
, not description
edit.php
script , work better
<?php while( $row = mysql_fetch_array($res) ) echo "$row[id]. $row[description] <a href='edit.php?edit=$row[id]'>edit</a><br />"; ?>
please dont use
mysql_
database extension, deprecated (gone ever in php7) if learning php, spend energies learningpdo
ormysqli_
database extensions, and here decide use
Comments
Post a Comment