Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Not getting data (PDO)

$
0
0
So I have a form and a span element with an id that needs to be updated but isn't getting updated with the value from the database - it just gets the default rate value instead of getting the actual rate value from the db. Am I not doing something here? Here's the PHP:

<?php

	/*==============================================================================================================================
	   CONFIGURATION
	==============================================================================================================================*/
	$dbHost = 'omit';
	$dbName = 'omit';
	$dbUser = 'omit';
	$dbPass = 'omit';
	
	$table = 'r_avg';
	$field = 'rate';
	$param = 'profession';
	
	/*==============================================================================================================================
	   DEFAULT RATE
	==============================================================================================================================*/
	$rate = 0;
	
	/*==============================================================================================================================
	   REQUEST HANDLER
	==============================================================================================================================*/
	if (isset ($_POST['enc'])) {
		/*=====================================================================================================================
		   NORMALIZE REQUESTS
		=====================================================================================================================*/
		$enc = $_POST['enc'];
		foreach ($_POST as $key => $value) {
			if (!is_array ($key) && !is_array ($value)) {
				$_POST[$key] = ($enc == 'base64_encode') ? urldecode (base64_decode ($value)) : urldecode ($value);
			}
		}
		unset ($_POST['enc']);
		
		/*=====================================================================================================================
		   CAPTURE PARAMETER
		=====================================================================================================================*/
		$profession = $_POST['profession'];
		
		/*=====================================================================================================================
		   DATABASE HANDLER
		=====================================================================================================================*/
		if ($dbHost != '' && $dbName != '' && $dbUser != '' && $dbPass != '') {
			
			$query = "SELECT " . $field . " FROM " . $table . " WHERE " . $param . " = '" . $profession . "' LIMIT 1";
			
			try {
				$dbh = new PDO ('mysql:host=' . $dbHost . ';dbname=' . $dbName, $dbUser, $dbPass, array (PDO::ATTR_PERSISTENT => true));
				$dbh->setAttribute (PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
				
				if (isset ($dbh)) {
					$pdo = $dbh->prepare ($query);
					$pdo->execute ();
					
					$r = $pdo->fetch (PDO::FETCH_NUM);
					$rate = (!empty ($r)) ? stripslashes ($r[0]) : $rate;
					
					$pdo->closeCursor ();
					$dbh = null;
				}
			} catch (PDOException $e) {
				echo $e->getMessage ();
			}
		}
		
		/*=====================================================================================================================
		   SEND TO BROWSER
		=====================================================================================================================*/
		echo $rate;
	}

?>


Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>