coldfiretech Posted August 21, 2008 Share Posted August 21, 2008 hello all... i cant seem to figure out what i did wrong with this. i am trying to make a form to change a users password.. they have to enter in their old password and the new password twice. here is my code <?php session_start(); $oldpw = $_POST ['oldpw']; $pass = mysql_real_escape_string($_POST['pass']); $passconf = mysql_real_escape_string($_POST['passconf']); $db_host = 'localhost'; $db_user = 'matt'; $db_pass = '****'; $db_db = '****'; $q = "SELECT password FROM users Where login = '".$_SESSION['login']."'"; $r = mysql_query($q,$con) or die(mysql_error()."<br /><br />".$q); if(mysql_num_rows($r) >0){ $row = mysql_fetch_assoc($r); $con = mysql_connect($db_host, $db_user, $db_pass) or die('MySQl Connection Error:'.mysql_error()); mysql_select_db($db_db, $con) or die('MySQL Error: Cannot select table'); $dbpw = $row ['password']; } // if ($oldpw == $dbpw && $pass == $passconf) { echo "those match "; //insert statement // } else { Echo "The passwords you entered did not match."; } // ?> Quote Link to comment Share on other sites More sharing options...
Stooney Posted August 21, 2008 Share Posted August 21, 2008 Which part of it isn't working? Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted August 21, 2008 Share Posted August 21, 2008 Not saw the complete code in details, but what i saw is: You select your db after your query. Change it and try. EDIT: Your database details will be at top before doing transactions. Quote Link to comment Share on other sites More sharing options...
coldfiretech Posted August 21, 2008 Author Share Posted August 21, 2008 $r = mysql_query($q,$con) or die(mysql_error()."<br /><br />".$q); Here is the error it just gave me Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in C:\wamp\www\cellsavior\passconf.php on line 12 SELECT `password` FROM users Where login = 'tester' <?php session_start(); $oldpw = $_POST ['oldpw']; $pass = mysql_real_escape_string($_POST['pass']); $passconf = mysql_real_escape_string($_POST['passconf']); $db_host = 'localhost'; $db_user = '****'; $db_pass = 'i****'; $db_db = '****'; $q = "SELECT `password` FROM users Where login = '".$_SESSION['login']."'"; $r = mysql_query($q,$con) or die(mysql_error()."<br /><br />".$q); if(mysql_num_rows($r) >0){ $row = mysql_fetch_assoc($r); $con = mysql_connect($db_host, $db_user, $db_pass) or die('MySQl Connection Error:'.mysql_error()); mysql_select_db($db_db, $con) or die('MySQL Error: Cannot select table'); $dbpw = $row ['password']; } // if ($oldpw == $dbpw && $pass == $passconf) { echo "those match "; //insert statement // } else { Echo "The passwords you entered did not match."; } // ?> Quote Link to comment Share on other sites More sharing options...
coldfiretech Posted August 21, 2008 Author Share Posted August 21, 2008 Moved the select_db up and here is what i go "Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in C:\wamp\www\cellsavior\passconf.php on line 11 MySQL Error: Cannot select table" <?php session_start(); $oldpw = $_POST ['oldpw']; $pass = mysql_real_escape_string($_POST['pass']); $passconf = mysql_real_escape_string($_POST['passconf']); $db_host = 'localhost'; $db_user = '****'; $db_pass = '****'; $db_db = '****'; mysql_select_db($db_db, $con) or die('MySQL Error: Cannot select table'); $q = "SELECT `password` FROM users Where login = '".$_SESSION['login']."'"; $r = mysql_query($q,$con) or die(mysql_error()."<br /><br />".$q); if(mysql_num_rows($r) >0){ $row = mysql_fetch_assoc($r); $con = mysql_connect($db_host, $db_user, $db_pass) or die('MySQl Connection Error:'.mysql_error()); $dbpw = $row ['password']; } // if ($oldpw == $dbpw && $pass == $passconf) { echo "those match "; //insert statement // } else { Echo "The passwords you entered did not match."; } // ?> Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted August 21, 2008 Share Posted August 21, 2008 try this: <?php session_start(); $db_host = 'localhost'; $db_user = 'stacks'; $db_pass = 'island67'; $db_db = 'cellsavior'; $con = mysql_connect($db_host, $db_user, $db_pass) or die('MySQl Connection Error:'.mysql_error()); mysql_select_db($db_db, $con) or die('MySQL Error: Cannot select table'); $oldpw = $_POST ['oldpw']; $pass = mysql_real_escape_string($_POST['pass']); $passconf = mysql_real_escape_string($_POST['passconf']); $q = "SELECT `password` FROM users Where login = '".$_SESSION['login']."'"; $r = mysql_query($q,$con) or die(mysql_error()."<br /><br />".$q); if(mysql_num_rows($r) >0){ $row = mysql_fetch_assoc($r); $dbpw = $row ['password']; } // if ($oldpw == $dbpw && $pass == $passconf) { echo "those match "; //insert statement // } else { Echo "The passwords you entered did not match."; } // Quote Link to comment Share on other sites More sharing options...
coldfiretech Posted August 21, 2008 Author Share Posted August 21, 2008 thanks bud... guess i wont do that again.. stupid mistake Quote Link to comment Share on other sites More sharing options...
coldfiretech Posted August 21, 2008 Author Share Posted August 21, 2008 Hey, now how can i insert the new password.. This sql statement doesnt work.. $sql = "INSERT INTO users (`password`) VALUES ('$passconf') Where login = '".$_SESSION['login']."'"; $result = mysql_query($sql, $con) or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted August 21, 2008 Share Posted August 21, 2008 Does this query throw an error. OR show us your updated code. Quote Link to comment Share on other sites More sharing options...
coldfiretech Posted August 21, 2008 Author Share Posted August 21, 2008 <?php session_start(); $db_host = 'localhost'; $db_user = '****'; $db_pass = '****'; $db_db = '*****'; $con = mysql_connect($db_host, $db_user, $db_pass) or die('MySQl Connection Error:'.mysql_error()); mysql_select_db($db_db, $con) or die('MySQL Error: Cannot select table'); $oldpw = $_POST ['oldpw']; $pass = mysql_real_escape_string($_POST['pass']); $passconf = mysql_real_escape_string($_POST['passconf']); $q = "SELECT `password` FROM users Where login = '".$_SESSION['login']."'"; $sid = $_SESSION['login']; $r = mysql_query($q,$con) or die(mysql_error()."<br /><br />".$q); if(mysql_num_rows($r) >0){ $row = mysql_fetch_assoc($r); $dbpw = $row ['password']; } // if ($oldpw == $dbpw && $pass == $passconf) { echo "those match "; $userid = $_SESSION['login']; $query = "UPDATE users SET `password` = $passconf Where login = $userid"; mysql_query($query, $con) or die('Error, query failed'); // } else { Echo "The passwords you entered did not match."; } // ?> Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted August 21, 2008 Share Posted August 21, 2008 try this: $query = "UPDATE users SET `password` = '$passconf' Where login = '$userid'"; mysql_query($query, $con) or die(mysql_error()); Any way does it show "Those match". Quote Link to comment Share on other sites More sharing options...
coldfiretech Posted August 21, 2008 Author Share Posted August 21, 2008 Yeah it does! Pretty happy about that Just started php yesterday!! Problem Solved THANK YOU@! Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted August 21, 2008 Share Posted August 21, 2008 Glad to hear, it is solved. and so fast you are. learn things fast.thats good. Click on thread solved button. Thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.