mikeb2017 Posted May 1, 2017 Share Posted May 1, 2017 Hello there, I like to start with sorry i'm new and i have an issue related to old php and the new PHP. I made this coding in dreamweaver years ago and now after the php update i does not work anymore. and i just cannot figure out why. i hope somebody can help me rewrite this ?.. many thanks <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $colname_rsDate = "-1"; if (isset($_POST['date1'])) { $colname_rsDate = $_POST['date1']; } mysql_select_db($database_bowlingl, $connbowling); $query_rsDate = sprintf("SELECT * FROM FILES WHERE DATUM = %s", GetSQLValueString($colname_rsDate, "date")); $rsDate = mysql_query($query_rsDate, $connbowling) or die(mysql_error()); $row_rsDate = mysql_fetch_assoc($rsDate); $totalRows_rsDate = mysql_num_rows($rsDate); ?> Quote Link to comment Share on other sites More sharing options...
ginerjm Posted May 1, 2017 Share Posted May 1, 2017 You need to make a bunch of changes. Turn on error checking and follow the hints that the errors give you. Quote Link to comment Share on other sites More sharing options...
benanamen Posted May 1, 2017 Share Posted May 1, 2017 Actually, none if this code is any good. It is obsolete and has been completely removed from Php. Study this PDO tutorial and write your new code from what you learn here. https://phpdelusions.net/pdo Quote Link to comment Share on other sites More sharing options...
mikeb2017 Posted May 1, 2017 Author Share Posted May 1, 2017 ah great :-( thanks for the answers. I think i give up as i'm a newby with this and cannot understand this PDO. regards Quote Link to comment Share on other sites More sharing options...
ginerjm Posted May 1, 2017 Share Posted May 1, 2017 (edited) PDO? You are worried about the use of PDO in place of mysql_* functions? You are seriously mis-informed. Using PDO is pretty much no different than using some string related functions or some File upload functions or some file-read-write ones. It's just a set of functions! To be using the switch to pdo as your excuse to hang it up is just plain wrong. The biggest problem you have is re-writing your long, way too elaborate code using some smarts and the more current functions available. That's where you need to knuckle down. PDO is like switching from chocolate to vanilla. Jeez!! This is pdo in a snap! $q = "some query statement using substitute parameters for a prepared query"; $qst = $pdo->prepare($q); $parms = array(':fld1'=> $value1, ':fld2'=> $value2, ':fld3'=> $value3); $result = $qst->execute($parms); if (!$result) { (some code to recognize the error occurred and end gracefully - same as with mysql_* functions) } // check if any rows were found? if ($qst->rowCount() ==0) { (some code to run if there are no results - same as with mysql_* functions) } else { while($row = $qst->fetch(PDO::FETCH_ASSOC)) // same as using mysql_* functions { (do things with the query results - same as with mysql_* functions) } } And That's PDO. You might want to read up on what are prepared queries are and why you should get used to using them and using named substitute parms instead of the ? ones. (edit - I hate when the forum changes what I typed with extra blank lines in my post. Why oh why?) Edited May 1, 2017 by ginerjm Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.