Jump to content

spode

Members
  • Posts

    43
  • Joined

  • Last visited

    Never

Everything posted by spode

  1. thanks for the great reply guys, it worked perfectly, but one quick question is it necessary to use 'mysql_fetch_assoc()' rather than using 'myspl_fetch_array()' ? thanks again
  2. the result SHOULD be automaticaly assigned to the variable using $gender = $_POST['gender_thingy']; because i'm pretty sure it doesnt matter on the type of input, the result is just what is assigned to the variable
  3. i use Programmer's Notepad because its brilliant for like every coding language, and its constantly being updated for the new ones...i'd check it out
  4. no, this is: <?php $host = "*****"; $username = "*****"; $password = "****"; $dbc = mysql_connect($host, $username, $password) or die (mysql_error()); $select = mysql_select_db('colsim0_mysql'); $uid = $_GET['uid']; $action = $_GET['action']; switch($action) { case 'edit': if (isset($_POST['submit'])) { $uname = $_POST['uname']; $npass = $_POST['npass']; $vpass = $_POST['vpass']; if ($vpass == $npass) { $insertinfo = "UPDATE `tbl_users` SET `username`='$uname', `password`='$npass' WHERE `uid`='$uid'"; if (mysql_query($insertinfo)) { echo "Information successfully updated! Your new username is " . $uname . " and your new password is " . $npass . "<br /> Click <a href=\"show_ids.php\">here</a> to go back."; } else { echo "Information failed to update because " . mysql_error(); } } else { echo "Your passwords did not match. Please <a href=\"crud.php?uid={$list['uid']}&action=edit\">try again</a>"; } } else { $query = "SELECT * FROM tbl_users WHERE (uid=$uid)"; $r = mysql_query ($query); $info = mysql_fetch_array($r); echo "<h1>Edit Information</h1> <form action=\"crud.php?action=edit\" method=\"post\"> <table> <tr> <td>Username:</td> <td><input type=\"text\" name=\"uname\" value='{$info['username']}' size=\"20\"></td> </tr> <tr> <td>New Password:</td> <td><input type=\"password\" name=\"npass\" value='{$info['password']}' size=\"20\"></td> </tr> <tr> <td>Verify Password:</td> <td><input type=\"password\" name=\"vpass\" size=\"20\"></td> </tr> <tr> <td><input type=\"submit\" name=\"submit\" value=\"Update\"> </form> </table>"; } break; case 'delete': $delete = "DELETE FROM tbl_users WHERE uid=$uid"; $r = mysql_query($delete); if (mysql_affected_rows() == 1) { echo '<p>Your account has been deleted.'; } else { echo '<p>Could not delete your account because: ' . mysql_error(); } break; case 'new': if(isset($_POST['submit'])) { $newusername = $_POST['newusername']; $newpassword = $_POST['newpassword']; $result = mysql_query("SELECT `username` FROM `tbl_users` WHERE (username='$newusername')") or die(mysql_error()); if (mysql_num_rows($result) == 0) { $createaccount = "INSERT INTO tbl_users (username, password) VALUES ('$newusername','$newpassword')"; $result = mysql_query($createaccount) or die(mysql_error()); echo "<p>Go back to the account viewer by clicking <a href=\"show_ids.php\">here</a></p>"; } else { echo "<p>That username already exists. Please <a href=\"crud.php?uid={$list['uid']}&action=new\">try again</a></p>"; } } else { echo "<h1>New Account</h1> <form action=\"crud.php?action=new\" method=\"post\"> <table> <tr> <td>Username:</td> <td><input type=\"text\" name=\"newusername\" size=\"20\"></td> </tr> <tr> <td>Password:</td> <td><input type=\"password\" name=\"newpassword\" size=\"20\"></td> </tr> <tr> <td><input type=\"submit\" name=\"submit\" value=\"Register\"></td> </tr> </form> </table>"; } break; case 'login': if(isset($_POST['submit'])) { $username1 = $_POST['username']; $password = $_POST['password']; $fetch = "SELECT `password` FROM `tbl_users` WHERE (username='$username1')"; $password2 = mysql_query($fetch); if($password == $password2) { echo "Welcome, you are now logged in. Click <a href=\"index.php\">HERE</a> to go back to the home page."; } else { echo "Your password was incorrect, please try again by clicking <a href=\"crud.php?action=login\">HERE</a>."; } } else { echo "<h2><center>LOGIN</center></h2>"; echo "<form action=\"crud.php?action=login\" method=\"post\"> <table> <tr> <td>Username:</td> <td><input type=\"text\" name=\"username\" size=\"20\"></td> </tr> <tr> <td>Password:</td> <td><input type=\"password\" name=\"password\" size=\"20\"></td> </tr> <tr> <td><input type=\"submit\" name=\"submit\" value=\"Login\"></td> </tr> </table> </form>"; } break; case 'admin': $username = $_POST['username']; $password = $_POST['password']; if(isset($_POST['submit'])) { if($username == "admin" AND $password == "admin") { echo "Welcome to the Admin Control Panel. Please select your action below:<br /><br /> If you would like to see a list of users, please click <a href=\"show_ids.php\">HERE</a>"; } else { echo "Please <a href=\"crud.php?action=admin&failures=$failures\">try again</a>"; } } else { echo "<h2><center>ADMIN LOGIN</center></h2>"; echo "<form action=\"crud.php?action=admin\" method=\"post\"> <table> <tr> <td>Username:</td> <td><input type=\"text\" name=\"username\" size=\"20\"></td> </tr> <tr> <td>Password:</td> <td><input type=\"password\" name=\"password\" size=\"20\"></td> </tr> <tr> <td><input type=\"submit\" name=\"submit\" value=\"Login as Admin\"></td> </tr> </table> </form>"; } break; default: echo "Action not found."; break; } ?>
  5. hey guys, sorry for such an undescriptive title, i just couldnt think of somethign to title it anyways this is my very very first (and simple) login script..i have a simple table set up that has a username and password. For some reason though, when i try to 'login', even though i know for a fact the password is right, i still get my error telling me 'Your password was incorrect.' Help me out? Do I have something wrong? <?php case 'login': if(isset($_POST['submit'])) { $username1 = $_POST['username']; $password = $_POST['password']; $fetch = "SELECT `password' FROM `tbl_users` WHERE (username='$username1')"; $password2 = mysql_query($fetch); if($password == $password2) { echo "Welcome, you are now logged in. Click <a href=\"index.php\">HERE</a> to go back to the home page."; } else { echo "Your password was incorrect, please try again by clicking <a href=\"crud.php?action=login\">HERE</a>."; } } else { echo "<h2><center>LOGIN</center></h2>"; echo "<form action=\"crud.php?action=login\" method=\"post\"> <table> <tr> <td>Username:</td> <td><input type=\"text\" name=\"username\" size=\"20\"></td> </tr> <tr> <td>Password:</td> <td><input type=\"password\" name=\"password\" size=\"20\"></td> </tr> <tr> <td><input type=\"submit\" name=\"submit\" value=\"Login\"></td> </tr> </table> </form>"; } break; ?>
  6. yep, that worked, thanks a lot
  7. Is there a function (or way) to see how many times a user has viewed a page during a session? I've been searching for quite a while and have come to a speed bump.
  8. just assign the file to a variable, then just do: <?php $file = whatever; if(isset($file)){ //display file button } else { // dont } ?>
  9. use the * operator after your SELECT statement
  10. I just updated my post...try looking at that code...I'm kind of a noob but that should work, to my understanding. What I'm saying is from the code you have provided, it looks as if you are trying to reorder it by updating the table, which is unneccesary. Just order the array that is returned.
  11. You don't need to update the database. Just get the information and THEN order it out. That way you dont change your database everytime someone wants to reorder it. <?php $getinfo = mysql_query("SELECT `order` FROM `test`") or die(mysql_error()); $neworder = sort($getinfo); $reverse = rsort($neworder); //etc. ?>
  12. Post this in the free-lance section, thanks.
  13. My suggestion would be to use $_POST instead, and then on the next page (or whatever page handles the form), simply combine all of those values into an array. So you could do: <?php $array = implode ($_POST['$button1'], $_POST['$button4'], $_POST['$button']); echo $array; ?>
  14. it isnt required, but it suppresses any error messages, which are instead handled by a die() function in conjunction with a mysql_error()
  15. still no form...it was the same exact file...
  16. spode

    oh noes!

    The back ticks worked, thanks
  17. spode

    oh noes!

    Information failed to update because You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
  18. spode

    oh noes!

    Still gettin' a MySQL syntax error: <?php case 'edit': if (isset($_POST['submit'])) { $uname = $_POST['uname']; $npass = $_POST['npass']; $vpass = $_POST['vpass']; if ($vpass == $npass) { $insertinfo = "UPDATE tbl_users SET username='$uname', `password`='$npass' WHERE uid=$uid"; if (mysql_query($insertinfo)) { echo "Information successfully updated!"; } else { echo "Information failed to update because " . mysql_error(); } } else { echo "Your passwords did not match. Please <a href=\"crud.php?uid={$list['uid']}&action=edit\">try again</a>"; } } else { $query = "SELECT * FROM tbl_users WHERE (uid=$uid)"; $r = mysql_query ($query); $list = mysql_fetch_array($r); echo "<h1>Edit Information</h1> <form action=\"crud.php?action=edit\" method=\"post\"> <table> <tr> <td>Username:</td> <td><input type=\"text\" name=\"uname\" value='{$list['username']}' size=\"20\"></td> </tr> <tr> <td>New Password:</td> <td><input type=\"password\" name=\"npass\" value='{$list['password']}' size=\"20\"></td> </tr> <tr> <td>Verify Password:</td> <td><input type=\"password\" name=\"vpass\" size=\"20\"></td> </tr> <tr> <td><input type=\"submit\" name=\"submit\" value=\"Update\"> </form> </table>"; } break; ?>
  19. try double checking your connection info
  20. Meh...\ heres the error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1. I get these all the friggin' time. ??? <?php $uname = $_POST['uname']; $npass = $_POST['npass']; $vpass = $_POST['vpass']; if ($vpass == $npass) { $insertinfo = "UPDATE tbl_users SET username='$uname', password='$npass' WHERE uid=$uid"; if (mysql_query($insertinfo)) { echo "Information successfully updated!"; } else { echo "Information failed to update because " . mysql_error(); } } else { echo "Your passwords did not match. Please <a href=\"crud.php?uid={$list['uid']}&action=edit\">try again</a>"; } ?> that's not the whole code but it's enough to figure it out
  21. it works now, thanks guys
  22. ok, now i'm getting the MySQL syntax error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''tbl_users' VALUES ('gensilver91','tennis')' at line 1 hmm?
  23. I'm clueless...the data isn't inserting into the database and it's not showing any errors. Any ideas? <?php case 'new': if(isset($_POST['submit'])) { $newusername = $_POST['newusername']; $newpassword = $_POST['newpassword']; $createaccount = "INSERT INTO tbl_users values ('$newusername','$newpassword')" or die(mysql_error()); $result = mysql_query($account); echo "<p>Go back to the account viewer by clicking <a href=\"show_ids.php\">here</a></p>"; } else { echo "<h1>New Account</h1> <form action=\"crud.php?action=new\" method=\"post\"> <table> <tr> <td>Username:</td> <td><input type=\"text\" name=\"newusername\" size=\"20\"></td> </tr> <tr> <td>Password:</td> <td><input type=\"password\" name=\"newpassword\" size=\"20\"></td> </tr> <tr> <td><input type=\"submit\" name=\"submit\" value=\"Register\"></td> </tr> </form> </table>"; } break; ?> thanks
  24. Problem solved. The variable action wasnt defined the second time through. So in the form the action was simply crud.php. When it needed to be crud.php?action=edit Thanks
×
×
  • 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.