Jump to content

How to check the data in mysql?


mark103

Recommended Posts

Hi guys,

 

I'm recent working on my php to add the row in mysql database. I need a bit of your help as I would like to know how to check the data in mysql database if it have added in mysql and then print it out without adding another same row?

 

here's the current code:

 

<?php
session_start();
    define('DB_HOST', 'localhost');
    define('DB_USER', 'mydbuser');
    define('DB_PASSWORD', 'mydbpass');
    define('DB_DATABASE', 'mydbname');
       
    $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']);
    $pass = clean($_GET['pass']);
    $login = clean($_GET['login']);
    $all = clean($_GET['all']);


if($username == '' && $pass == ''){
   // both are empty
   $errmsg_arr[] = 'Username and password are missing. You must enter both or the other one.';
   $errflag = true;
}

    if($errflag) {
  $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
  echo implode('<br />',$errmsg_arr);
   }
   else {

$insert = array();
if(isset($_GET['user'])) {
    $insert[] = 'username = \'' . clean($_GET['user']) .'\'';
}
if(isset($_GET['pass'])) {
    $insert[] = 'pass = \'' . clean($_GET['pass']) . '\'';
}
if(isset($_GET['login'])) {
    $insert[] = 'LoggedUser = \'' . clean($_GET['login']) . '\'';
}
if(isset($_GET['all'])) {
    $insert[] = 'all = \'' . clean($_GET['all']) . '\'';
}


if (count($insert)>0) {
   $names = implode(',',$insert);


if($username) {
  $qrytable1="SELECT username, LoggedUser FROM Online_Users WHERE username='$username'";
  $result1=mysql_query($qrytable1) or die('Error:<br />' . $qry . '<br />' . mysql_error());

while ($row = mysql_fetch_array($result1)) {
  echo "<p id='LoggedUser'>";
  echo $row['LoggedUser'] . "</p>";
  }
}


if($username && $login == '1') {

  $sql="INSERT INTO Online_Users (username, LoggedUser)
VALUES
('$_GET[user]','$_GET[login]')";
  $result = mysql_query($sql);

if($result) {
  $qrytable1="SELECT username, LoggedUser FROM Online_Users WHERE username='$username'";
  $result1=mysql_query($qrytable1) or die('Error:<br />' . $qry . '<br />' . mysql_error());

while ($row = mysql_fetch_array($result1)) {
  echo "<p id='LoggedUser'>";
  echo $row['LoggedUser'] . "</p>";
  }
}

} elseif($username == 'all') {
  $names = implode(',',$insert);
  $result = mysql_query("SELECT * FROM Online_Users") or die('Error: ' . mysql_error());
  $num_rows = mysql_num_rows($result);
  echo "There are $num_rows Users Online right now";
  }
}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/255169-how-to-check-the-data-in-mysql/
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.