xtjx09 Posted February 12, 2009 Share Posted February 12, 2009 I am trying to update, for now, just the name in my database. user is the name in the database, and name2 is my variable i'm trying to update it with. Did I do something wrong with the php? not sure if you necessarily need more of my code. just comment and ill post anymore that may be needed. Thank you. (I couldn't find any posts to fix my problem) <?php session_start(); if (!isset ( $_SESSION['admin'])) { header( 'Location: Index.php' ); } else { ?> <html> <body> <form method= "POST"> Selection: <select name= "selection"> <option value= "users">users</option> <option value= "download">download</option> <input type= "submit" name= "submit" value= "submit" > </form> <!-- Starts Selection User --> <?php if ($_POST['selection'] == "users") { ?> <form action= "" method= "POST" enctype="multipart/form-data"> Name<input type= "text" name= "name" > <br /> E-Mail<input type= "text" name= "email"><br /> Password<input type= "password" name= "pass" ><br /> Re-enter Password<input type= "password" name= "pass2" ><br /> <?php if ($_SESSION['user'] == "tj") { ?> <br />Privilages<select name= "priv"><option>member</option><option>admin</option></select><br /> <?php } ?> <input type= "submit" name= "create" value= "create"> <input type= "submit" name= "update" value= "update"> <?php if (isset ($_POST['create'])) { mysql_connect("server", "user", "pass"); @mysql_select_db(user) or die("Unable to connect to database."); $mysql = mysql_query("SELECT * FROM login WHERE user = '{$_POST['name']}'"); if(mysql_num_rows($mysql) >= 1) { echo "User Exists."; } else { if ($_POST['pass'] == $_POST['pass2']) { $name = $_POST['name']; $pass = $_POST['pass']; $priv = $_POST['priv']; $email = $_POST['email']; $query= "insert into login(user, password, email, priv ) values ('$name', '$pass','$email' ,'$priv')"; mysql_query($query); mysql_close(); } else echo "Passwords do not match"; } } mysql_connect("server", "user", "pass"); @mysql_select_db(user) or die("Unable to connect to database."); $users="select * from login"; $result=mysql_query($users); ?> <table border= "1"> <th>User:</th> <th>Pass:</th> <th>E-mail:</th> <th>Priv:</th> <?php while (list($id, $user, $password, $email, $priv)=mysql_fetch_array($result)) { ?> <tr> <td><input type= "text" name= "name2" value="<?php echo $user; ?>"></td> <td><input type= "text" name= "pass2" value="<?php echo $password; ?>"></td> <td><input type= "text" name= "email2" value="<?php echo $email; ?>"></td> <td><input type= "text" name= "priv2" value="<?php echo $priv; ?>"></td> </tr> <input type= "hidden" name= "id2" value="<?php echo $id; ?>"> </form> <?php } if (isset($_POST['update'])) { $id2 = $_POST['id2']; $user2= $_POST['name2']; $sql2 = "UPDATE `login` SET `user` = '$user2' WHERE `id`='$id2' "; mysql_query($sql2); } ?> </table> <?php } } ?> <!-- Ends User--> <?php if ($_POST['selection'] == "download") { mysql_connect("server", "user", "pass"); @mysql_select_db(user) or die("Unable to connect to database."); $query2 = "SELECT * FROM home"; $result2= mysql_query($query2); ?> <table border= "1"> <th>Uploader:</th> <th>Filename:</th> <th>Type:</th> <th>Size:</th> <?php while (list($id, $uploader, $filename, $type, $size, $content, $password)=mysql_fetch_array($result2)) { ?> <tr> <td><?php echo $uploader; ?></td> <td><a href="abyss.php?id=<?php echo $id ?>"> <?php echo $filename ?> </a></td> <td><?php echo $type; ?> </td> <td><?php echo $size; ?></td> </tr> <?php } } ?> </body> </html> <?php ?> Link to comment https://forums.phpfreaks.com/topic/145001-update-button/ Share on other sites More sharing options...
samshel Posted February 12, 2009 Share Posted February 12, 2009 placing complete code of this page will help ! Link to comment https://forums.phpfreaks.com/topic/145001-update-button/#findComment-760856 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.