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
https://forums.phpfreaks.com/topic/120649-solved-problem-with-sql-statement/
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.";
}
//


?>

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


?>

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

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());

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

?>



Archived

This topic is now archived and is closed to further replies.

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