double values in table
Hello,
since 5 days I'm using cpanel.domain.net.
I'm using a php (code see below) to store (maximum) 100 values in a table. If I write
a value I'm using...
mySubdomainName.domain.net/test.php?action=write&wert=72
-When I call the table using...
mySubdomainName.domain.net/test.php?action=read
I notice each value in the databeas is double
sample for a table with double values:
-Is there an error on the domain server or why are the values double ? Table :
PHP :
POS WERT ZEIT
1 72 2014-11-03 01:19:49
2 72 2014-11-03 01:19:49
3 70 2014-11-03 01:06:34
4 70 2014-11-03 01:06:33-Is there an error on the domain server or why are the values double ? Table :
CREATE TABLE IF NOT EXISTS `wertetabelle` (
`ID` bigint(20) NOT NULL AUTO_INCREMENT,
`wert` bigint(20) NOT NULL,
`zeit` datetime NOT NULL,
PRIMARY KEY (`ID`)
) DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;PHP :
) && $_GET['action"> != "") ? $_GET['action"> : '';
$wert = (isset($_GET['wert">) && $_GET['wert"> != "")? $_GET['wert"> : '';
// different 'action'-URL Parameters
switch($action){
// add Variable to data base
case 'write':
// if value is not EMPTY
if ($wert != ''){
// store the time
$zeit = date("Y-m-d H:i:s");
try{
//connect to database
$db = connect_db();
//SQL Insert-Call
$proc = $db->prepare("INSERT INTO wertetabelle(wert,zeit) Values(?,?)");
//give the values as a parameter to the calling routine and process it
$count = $proc->execute(array($wert,$zeit));
if ($count > 0){
//if entry was made show a text phrase
echo "Value '$wert' and time '$zeit' added to database";
}
}catch (PDOException $ex) {
echo "error on calling the data: " . $ex;
}
}else{
// value was empty, show error phrase
echo "There was no value";
}
break;
// read data from database
case 'read':
try{
//connect to data base
$db = connect_db();
//Counter for table
$cnt = 1;
$rows = '';
// read Data from DB (line by line)
foreach($db->query("SELECT * FROM wertetabelle ORDER BY zeit DESC LIMIT 100") as $row){
$rows .= '
' . $cnt++ . "
" . $row['wert"> . "
" . $row['zeit"> ."
\n";
}
//echo the table
echo '';
echo $rows;
echo '
POS
WERT
ZEIT
';
}catch (PDOException $ex) {
echo "error reading Database values: " . $ex;
}
break;
// invalid parameters received
default:
echo 'there was no action defined!';
break;
}
// Function to connect the database
function connect_db(){
$DB_HOST = '127.0.0.1';
$DB_NAME = 'NAMEDEINERDATENBANK';
$DB_USER = 'DBBENUTZER';
$DB_PASSWORD = 'GEHEIM';
$db = new PDO('mysql:host='.$DB_HOST .';dbname='.$DB_NAME.';charset=utf8', $DB_USER, $DB_PASSWORD,array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
return $db;
}
?>-
Hello :) You will likely receive more feedback on this type of question at a forum dedicated to discussions of PHP/MySQL programming. The forums here are primarily intended for discussions of the cPanel/WHM software itself. Thank you. 0
Please sign in to leave a comment.
Comments
1 comment