Thursday, 15 May 2014

Writing a Select Where statement in PHP and MySQL -



Writing a Select Where statement in PHP and MySQL -

would please me code below, inexperienced in area , class in sql "a long time ago in galaxy far, far away..." know connection string works because have used in other functions app. have used code below retrieving *rows table in function, part, except didn't utilize clause.

first, able store ip addresses in table using function , working well. want check see if given 1 exist in table. partial code given below.

what seems homecoming 0 rows. have set in test info table , hard-coded $ipa, still 0 rows return. please help if possible , effort spent.

function checkdb($ipa) { require_once('connection.inc.php'); $resultans = ""; //create db connection $conn = dbconnect(); //init prepared stmt $stmt = $conn->stmt_init(); //set sql query ipaddress search //prepare sql query $sql = 'select * ipaddress ipa = ?'; //submit query , capture result if ($stmt->prepare($sql)) { $stmt->bind_param('s', $ipa); $stmt = $stmt->execute(); //if qry triggers error affeted_rows value becomes -1 & //php treats -1 true; test greater 0 $numrows = $stmt->num_rows; //not sure syntax here } // want know if query brought or not, don't // know what, found match or did not find match. // echos testing purposes show me landing. if ($numrows == 0) { echo '<script type="text/javascript">window.alert("numrows = 0")</script>'; $resultans = 0; } elseif ($numrows == 1) { echo '<script type="text/javascript">window.alert("numrows = 1")</script>'; $resultans = 1; } homecoming $resultans;

}

try storing result after execute

$stmt->store_result();

php mysql select where

No comments:

Post a Comment