Jump to content

[SOLVED] Problem with SQL statement ??


coldfiretech

Recommended Posts

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.";
}
//


?>

Link to comment
Share on other sites

$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.";
}
//


?>

Link to comment
Share on other sites

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.";
}
//


?>

Link to comment
Share on other sites

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.";
}
//

Link to comment
Share on other sites

<?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.";
}
//

?>



Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.