narutofan Posted October 27, 2018 Share Posted October 27, 2018 Hi, i'm currently facing a problem of php script not running to the finish point of the script. the code actually tries to find tags preceded either with "!" or "@" and if it doesn't match it outputs user input data in to a update query at the end and this is where the script isn't behaving properly it tries to match the tags but it is not updating in to DB i don't know where i'm going wrong.The code might be long but that is all there is to it. include_once '../includes/dbconfig.inc.php'; if(strlen(htmlentities($_POST['data']))<1){ echo "Data empty!"; exit(); } #clean all the post vars that will interact with the DB. #ideal for search results page $u_id=(int)$_POST['id']; $type=htmlentities($_POST['type']); $account_name= htmlentities($_SESSION['uname']); $data= htmlentities($_POST['data']); $tit= htmlentities($_POST['title']); $sess_id=(int)$_SESSION['id']; $title= stripslashes($tit); $sql="select count(user_id) from user where uname=:account_name and activated='1' limit 1"; $stmth=$conn->prepare($sql); $stmth->bindparam(":account_name",$account_name); $stmth->execute(); $row=$stmth->rowCount(); if ($row<1) { echo "Account doesn't exist"; exit(); } $dat= explode(" ", $data);//names are exploded in to array $data1=""; foreach($dat as $d){ if(strpos($d ,'!') !== FALSE ){ $d_p=""; $i=0; $tag=""; $d2=count($dat); while ($i<$d2) { $d_w=$dat[$i]; $regex="/!+([a-zA-z0-9._-]+)/"; $regex1="/(?:\s|^)![A-Za-z0-9\-\.\_]+(?:\s|$)/"; $d1=preg_match_all($regex, $dat[$i],$output_preg,PREG_PATTERN_ORDER); function check_regex($data){ if ($data=="/(?:\s|^)![A-Za-z0-9\-\.\_]+(?:\s|$)/") { return $data; } } $i++; $d_p= array_column($dat,$output_preg[0][0],$regex1); $d_f= preg_grep($regex1, $d_p); $d_c= array_count_values($d_f); //print_r($d_c); foreach ($d_c as $d2) { if ($d2>=2) { $tag=1; } } } if($tag==1){ echo 1; exit(); } else { echo 0; } } elseif (strpos($d ,'@') !== FALSE) { $d1=str_replace("@", "", $d); //check if the user exists $stmt= $conn->prepare("select count(uname) from user where uname=:d1 and activated='1'"); $stmt->bindValue(":d1",$d1); $stmt->execute(); $count=$stmt->rowCount(); if($count>0){ $data1=str_replace("@$d1", "<a href='home.php?u={$d1}'>@$d1</a>", $data); $app = "Status post"; $note = $_SESSION['uname'].' Mentioned you in a Post: <br /><a href="home.php?u='.$_SESSION['uname'].'">'.$_SESSION['uname'].''s Profile</a><br><hr>'; $stmth= $conn->prepare("insert into notifications (username, initiator, app, note, date_time,user_id_n) values(:friend,:session,:app,:note,now(),:sess_id)"); $stmth->bindparam(":friend",$d1); $stmth->bindparam(":session",$_SESSION['uname']); $stmth->bindparam(":sess_id",$sess_id); $stmth->bindparam(":app",$app); $stmth->bindparam(":note",$note); $stmth->execute(); } } else { $data1=$data; } } #insert in to DB try { $stmt=$conn->prepare("update updates set account_name=:account_name,author=:session, title=:title ,update_body=:data1,time=now() where update_id=:u_id"); $stmt->bindparam(":account_name",$account_name); $stmt->bindparam(":session",$account_name); $stmt->bindparam(":title",$title); $stmt->bindparam(":data1",$data1); $stmt->bindparam(":u_id",$u_id); $stmt->execute(); }catch (PDOException $ex) { echo $ex->getMessage(); } echo 2; Link to comment Share on other sites More sharing options...
narutofan Posted October 27, 2018 Author Share Posted October 27, 2018 and it is not catching any error at the end Link to comment Share on other sites More sharing options...
narutofan Posted October 27, 2018 Author Share Posted October 27, 2018 finally found the solution i deleted the check_regex function i intended it for array_filter function and now it works fine thanks for your patience all. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.