Jump to content

isset & empty problem


phpsycho

Recommended Posts

When the form is summited it is supposed to check if the password field contained any text so that way it updates the password. so only if $password exists should it run that query. I tried all different ways of making that happen and it never works. I will summit the form without anything in the password field and it will still update the password to something encrypted in md5 anyways.

<?php
include ('header.php');

if(isset($_GET['sa'])) {
  switch ( $_GET['sa']) {

case 'edit':
edit();
break;

}

  }else{


echo "<div class='header'>Edit admins</div><div class='content'>";
$query = mysql_query("SELECT * FROM `admins`");
while($row = mysql_fetch_array($query)){
$username = clean_up($row['username']);
$id = clean_up($row['id']);
$email = clean_up($row['email']);
$website = clean_up($row['website']);
echo "$id $username $email $website | <a href='index.php?action=editadmins&sa=edit&id=$id'> Edit</a><br>"; 
}


echo "</div>";
}

function edit() {
$id = clean_up($_GET['id']);

if(isset($_POST['submit'])){
$username = clean_up($_POST['username']);
$password = md5(clean_up($_POST['password']));
$email = clean_up($_POST['email']);
$website = clean_up($_POST['website']);

if(isset($username)){
if(isset($password)){
mysql_query("UPDATE `admins` SET `password`='$password' WHERE `id`='$id'");
}

mysql_query("UPDATE `admins` SET `username`='$username', `email`='$email', `website`='$website' WHERE `id`='$id'");

echo "<b><font color=green>Information edited. Go <a href='index.php'>home</a>?</font></b><br>";

}else{
echo "please enter a username";
}

}else{

$query = mysql_query("SELECT * FROM `admins` WHERE `id`='$id'");
while($row = mysql_fetch_array($query)){
$username = clean_up($row['username']);
$email = clean_up($row['email']);
$website = clean_up($row['website']);

echo "<div class='header'>Edit $username</div><div class='content'><form action='index.php?action=editadmins&sa=edit&id=$id' method='post'>
<b>Username:</b> <input type='text' name='username' id='username' value='$username'><br>
<b>Password:</b>(leave blank to keep same) <input type='password' name='password' id='password' value=''><br>
<b>Email:</b> <input type='text' name='email' id='email' value='$email'><br>
<b>Website:</b> <input type='text' name='website' id='website' value='$website'><br>
<input type='submit' name='submit' id=submit' value='Edit $username'></form></div>";

}

}

}


include('footer.php'); ?>

 

Link to comment
https://forums.phpfreaks.com/topic/235304-isset-empty-problem/
Share on other sites

Yeah so I use this:

if(empty($username)){

if(empty($password)){
mysql_query("UPDATE `admins` SET `password`='$password' WHERE `id`='$id'");
}

mysql_query("UPDATE `admins` SET `username`='$username', `email`='$email', `website`='$website' WHERE `id`='$id'");
}

 

nothing goes into the db now.

 

so I try this:

if(!empty($username)){

if(!empty($password)){
mysql_query("UPDATE `admins` SET `password`='$password' WHERE `id`='$id'");
}

mysql_query("UPDATE `admins` SET `username`='$username', `email`='$email', `website`='$website' WHERE `id`='$id'");
}

 

that inserts that empty md5 string

 

Link to comment
https://forums.phpfreaks.com/topic/235304-isset-empty-problem/#findComment-1209216
Share on other sites

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.