<?php include "dbconnection.php"; $connection = initializeConnectionToDB(); $db = selectDB(); $selected = mysql_select_db($db, $connection) or die("Could not select Database"); $result = mysql_query('SELECT * FROM temp_registrations;') or die("There was an error running the query !<br>"); while ($row = mysql_fetch_array($result)) { echo "Temp_Users: "; echo "ID: " . $row[0] . " Number: " . $row[1] . " Verification Key: " . $row[2]; echo "<br>"; } $result = mysql_query('SELECT * FROM users;') or die("There was an error running the query !<br>"); echo "<br>---------------------------------------------------------------------------<br>"; while ($row = mysql_fetch_array($result)) { echo "Users: "; echo "ID: " . $row[0] . " Number: " . $row[1] . " password: "******"<br>"; } $result = mysql_query('SELECT * FROM contacts;') or die("There was an error running the query !<br>"); echo "<br>---------------------------------------------------------------------------<br>"; while ($row = mysql_fetch_array($result)) { echo "Contacts: "; echo "ID: " . $row[0] . " Source_ID: " . $row[1] . " Destination_ID: " . $row[2] . " Nickname " . $row[3]; echo "<br>"; } $result = mysql_query('SELECT * FROM messages;') or die("There was an error running the query !<br>"); echo "<br>---------------------------------------------------------------------------<br>"; while ($row = mysql_fetch_array($result)) { echo "Messages: "; echo "ID: " . $row[0] . " Contact ID: " . $row[1] . " Content: " . $row[2] . " Timestamp: " . $row[3] . " READ Status: " . $row[4];
function create_user($pNumber, $pPassword) { $response = ""; if (isset($pNumber) && isset($pPassword)) { $number = $pNumber; $ClientPassword = $pPassword; } else { return $response; } // Connect to DB $connection = initializeConnectionToDB(); $db = selectDB(); $selected = mysql_select_db($db, $connection) or die("Could not select Database"); // Check if user already exists $result = mysql_query('SELECT mobileNumber FROM users WHERE mobileNumber ="' . $number . '";') or die("There was an error running the query to look for existing temp registration!<br>"); if (mysql_num_rows($result) != 0) { die("User with number: " . $number . " already exist"); } // Create User $result = mysql_query("INSERT INTO users (mobileNumber,password) VALUES ('" . $number . "','" . $ClientPassword . "')") or die("There was an error running the query in create_user()!<br>"); //Get user id of newly created user if (mysql_affected_rows() != 0) { $result = mysql_query('SELECT id FROM users WHERE mobileNumber ="' . $number . '";'); if (mysql_num_rows($result) != 0) { $userID = mysql_result($result, 0, 0); $response = "OK : " . $userID; } } else { die("Internal Server Error during creating user"); } mysql_close($connection); return $response; }
function getOwnCIDFromOppositeCID($pending_contact_IDs) { $ownContactIDs = array(); //Connect to DB $connection = initializeConnectionToDB(); $db = selectDB(); $selected = mysql_select_db($db, $connection) or die("Could not select Database"); //encode contactID $contactInfo = array(); foreach ($pending_contact_IDs as $contact_id) { $result = mysql_query('SELECT origin_user_id, destination_user_id FROM contacts WHERE ' . 'contact_id=' . $contact_id . '') or die("SQL Error:" . mysql_error() . " with param" . var_dump($contact_id) . " <br>"); if (mysql_num_rows($result) > 0) { for ($i = 0; $i < mysql_num_rows($result); ++$i) { $opponent = mysql_result($result, $i, 0); $own = mysql_result($result, $i, 1); $data = array($opponent, $own); array_push($contactInfo, $data); } } } // find contact id with data foreach ($contactInfo as $info) { $result = mysql_query('SELECT contact_id FROM contacts WHERE origin_user_id=' . $info[1] . ' AND destination_user_id=' . $info[0] . ';') or die("SQL Error:" . mysql_error() . " with param" . var_dump($info) . " <br>"); if (mysql_num_rows($result) > 0) { for ($i = 0; $i < mysql_num_rows($result); ++$i) { $ownContactIDs[] = mysql_result($result, $i, 0); } } } mysql_close($connection); return $ownContactIDs; }