...

if statement not working

Spudster
07-10-2012, 01:57 AM
II have created a password change script one minor issue
When i write a else statement it ignoes it? But if i take the else statement out it procceses it succesdfully.


Heres my code (First big code ive written getting better

I know The sql select query is a sql injection prone im going to chànge this once i get thè script working.

Please Tweak This abit to get the else statements in (Been Working Hard Today)


<?php
session_start();

require "connect.php";

$oldpass = $_POST['oldpass'];
$newpass = $_POST['newpass'];
$compass = $_POST['compass'];

$username = $_SESSION['username'];

//create values as md5 for securiry

$oldpassmd5 = md5($_POST['oldpass']);
$newpassmd5 = md5($_POST['newpass']);
$compassmd5 = md5($_POST['compass']);


$query = mysql_query ("SELECT * FROM users WHERE username='$username'") or die ("SQL Error");

$numrows = (mysql_num_rows($query));

if ($numrows!=0)

while ($row = mysql_fetch_assoc($query))

$dbpassword = $row['password'];







if (empty($oldpass) && empty ($newpass) && empty ($compass))
die ("You Haven't Filled In The Required Fields");





if ($oldpassmd5==$dbpassword)



if ($compassmd5==$newpassmd5)


$passchange = mysql_query ("UPDATE users SET password='$newpassmd5' WHERE username='$username'") or die ("Error");
if ($passchange==true)
echo "Password Changed";

//otherwise if there not equal
if ($oldpassmd5!=$dbpassword)
echo "Wrong Password";

//otherwise statement should go here aswill

if ($compass!=$newpass)
echo "Password Do Not Match";

?>
<meta name='viewport' name='width'content='width=device-width' </

Microsuck
07-10-2012, 04:07 AM
Are you against the use of braces/curly brackets?

sunfighter
07-10-2012, 02:13 PM
You never showed us the else that did not work. Here's one place it might have been:
if ($passchange == true){
echo "Password Changed";
}else{
echo "Wrong Password";
}

Keleth
07-10-2012, 03:02 PM
Curly braces, tabbing, elseifs/else and &&/|| are all needed in that code block... Show us the else that failed, or we can't really debug anything... showing us working code does nothing...

Arcticwarrio
07-10-2012, 04:11 PM
something like this?

<?php
session_start();
require "connect.php";
$username = $_SESSION['username'];

if (empty($_POST['oldpass']) && empty($_POST['newpass']) && empty($_POST['compass'])){
die ("You Haven't Filled In The Required Fields");
}
else{
if ($_POST['newpass'] == $_POST['compass']){
$newpass = md5($_POST['newpass']);
$query = mysql_query ("SELECT * FROM users WHERE username='$username'") or die ("SQL Error");
if (mysql_num_rows($query) != 0){
$row = mysql_fetch_assoc($query);
$dbpassword = $row['password'];
}
}
else{
echo "Password Do Not Match";
}
}

if ($dbpassword == md5($_POST['oldpass'])){
$passchange = mysql_query ("UPDATE users SET password='$newpass' WHERE username='$username'") or die ("Error");
if ($passchange==true){
echo "Password Changed";
}
else{
echo "Wrong Password";
}
}else{

// your else statement here

}
?>

tangoforce
07-10-2012, 05:53 PM
When i write a else statement it ignoes it?

There is no else section of code in the code you have supplied.

Spudster
07-11-2012, 12:46 AM
Oh didnt know that curly brackets was for that

That probably why it didnt work, learnt something new :D

Thanks for your help.

This seems like a great communnity.

I managed to get the else statements working by adding the if contion now i can take that out and replace it with curly brackets.

Internet exployer is the worst browser i will remove that and add $_POST instead.


Getting to fixing bugs..

Spudster
07-13-2012, 12:46 PM
Another question:

Is it posdible to loop though all errors and display everything the users done wrong?

It makes it alot more user friendly.

Arcticwarrio
07-13-2012, 12:50 PM
yes,

post your latest code and i'll take a look for you

jdswebservice
07-14-2012, 02:04 AM
I'll also chime in on this as well! I'm interested in keeping up to date with this. looks like a fun project! :D

Spudster
07-14-2012, 01:07 PM
This is going to be a great project once im done :D

I will post the new code when tommorow.

And Im adding A field for users Websites how can i post hem as hyperlinks? so any with admintalk.net or http:// will show up as a Link.

Thanks Alot,

Spudster

jdswebservice
07-14-2012, 08:26 PM
I could just do this project for you and then have you look at the code, but it wouldnt be as fun.

If you are having users submit stuff to a database, you have to loop through the database and then pull out the information you need, sort it, and throw it back at the user using echo.

Functions that will be helpful to you are,

for loop
echo (duh)
mysql_connect()

Listing data bases, etc

the site that i personally learned from is this one. Its been around for 10+ years

http://www.tizag.com/mysqlTutorial/index.php

This will teach you all you need to know about syntax, and everything else. :)

Have fun! happy coding!

J-

Spudster
07-14-2012, 11:32 PM
Thanks You could write some codes out for me And i have a look how its done To code it myself its a good way of learning..

And im going to have A look at that site :D

tangoforce
07-15-2012, 01:20 PM
the site that i personally learned from is this one. Its been around for 10+ years

http://www.tizag.com/mysqlTutorial/index.php

This will teach you all you need to know about syntax, and everything else. :)

+1

The only thing I disliked about tizag is its tutorials about joining in mysql. That was very confusing.. I ended up on another site for that.

Spudster
07-16-2012, 01:05 AM
Tizag have okld tutorial that ive seen before..

jdswebservice
07-16-2012, 04:13 AM
Well, like i said thats the ones that ive been using before. So thats totally up to you. I'm busy the next day or so, so i'll deliver the code asap.

Spudster
07-16-2012, 04:49 AM
Ok Thanks I Won,t use it but it will help me study it and learn from it

my other threD

http://www.codingforums.com/showthread.php?t=267951



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum