Jump to content

how to check the value in mysql database?


mark103

Recommended Posts

Hi guys,

 

I need your help. I am checking on a database as I want to see if I have the same value in the url and in the database.

 

 

<?php
session_start();
    define('DB_HOST', 'localhost');
    define('DB_USER', 'mydbuser');
    define('DB_PASSWORD', 'mydbpass');
    define('DB_DATABASE', 'mydbtable');
       
    $errmsg_arr = array();
    $errflag = false;

    $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
    if(!$link) {
  die('Failed to connect to server: ' . mysql_error());
    }

    $db = mysql_select_db(DB_DATABASE);
    if(!$db) {
  die("Unable to select database");
    }

   function clean($var){

return mysql_real_escape_string(strip_tags($var));
    }
  
    $username = clean($_GET['user']);
    $password = clean($_GET['pass']);
    $test = clean($_GET['test']);
    $public = clean($_GET['public']);
   
   
   if (isset($_GET['user']) && (isset($_GET['pass']))) {
    if($username == '' || $password == '') {
  $errmsg_arr[] = 'username or password are missing';
  $errflag = true;
    }
} elseif (isset($_GET['user']) || (isset($_GET['test'])) || (isset($_GET['public']))) {
    if($username == '' || $test == '' || $public == '') {
  $errmsg_arr[] = 'user or others are missing';
  $errflag = true;
    }
  }

    if($errflag) {
  $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
  echo implode('<br />',$errmsg_arr);
   }
   else {
  $qry="SELECT * FROM members WHERE username='$username' AND passwd='$password'";
  $result=mysql_query($qry) or die('Error:<br />' . $qry . '<br />' . mysql_error());


if ($username && $password) {
  if(mysql_num_rows($result) > 0) {
     $qrytable1="SELECT images, id, test, links, Public FROM user_list WHERE username='$username'";
    $result1=mysql_query($qrytable1) or die('Error:<br />' . $qry . '<br />' . mysql_error());

    while ($row = mysql_fetch_array($result1)) {
        echo "<p id='test'>";
        echo $row['test'] . "</p>";
        echo '<p id="images"> <a href="images.php?test=test&id='.$row['id'].'">Images</a></td> | <a href="http://' .  $row["links"] . '">Link</a> </td> | <a href="delete.php?test=test&id='.$row['id'].'">Delete</a> </td> | <span id="test">'.$row['Public'].'</td>';
     }
   } else {
    echo "user not found";
  }
} elseif($username && $test && $public) {
    $qry="SELECT * FROM members WHERE username='$username'";
    $result1=mysql_query($qry) or die('Error:<br />' . $qry . '<br />' . mysql_error());
    
    if(mysql_num_rows($result1) > 0) {     
      $qrytable1="SELECT Public FROM user_list WHERE username='$username' && test='$test'";
      $result2=mysql_query($qrytable1) or die('Error:<br />' . $qry . '<br />' . mysql_error());
      
      if(mysql_num_rows($result2) > 0) {
        $row = mysql_fetch_row($result2);
        mysql_query("UPDATE user_list SET Public=('$_GET[public]') WHERE username='$username' AND test='$test'");
        echo "update!";
      } else {
        echo "already updated!";
      }
    } else {
      echo "user not found";
    }
  }
} 
?>

 

This is the function I use to check the value in the database:

 

if (mysql_affected_rows($result2) > 0) {
         mysql_query("UPDATE user_list SET Public=('$_GET[public]') WHERE username='$username' AND test='$test'");
         echo "you have update it!";
       } else if (mysql_affected_rows($result2) < 0) {
         echo "it is not on the database";
       } else {
         echo "you have already updated!";
       }

 

 

When i input the different value in a url bar while the records are not the same as the value in the url and in the database, i can't get passed and I am keep getting "you have already updated!!" when the value in a database are different than I have input in a url.

 

Do you know how i can get pass it when I have input the different value in the url while it is not the same in the database?

 

Any advice would be much appreicated.

 

Thanks,

Mark

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.