dharm Posted September 15, 2006 Share Posted September 15, 2006 I have written this code but im having trouble making it work. This code is to check weather a part of a needle is present within haystack. I think the problem maybe when thrs more then one mysql result checked. This code is to help prevent inserting data into the database more then once if the refresh button is pressed. Here is the code:[code]<?php // check discription string within $basevar if is present in database $query2 = "Select * from ".$DBprefix."protable where client_id='$cid' and off_date='0'";$result2 = mysql_query($query2); $pos[] = array();while($row1 = mysql_fetch_array($result2)){$discription = $row1["discription"];$mystring = $basevars;$pos[] = strpos($mystring, $discription);}$num = count($pos);for ($i=0;$i<$num;$i++) {if ($pos[$i] === false ){} else{echo $pos[1]; // checkin outputecho"<h1>Data Already complete</h1>;include("../../includes/footer.php"); exit();}} ?> [/code]Any help will be much appreciated! Thxs dharm Quote Link to comment Share on other sites More sharing options...
448191 Posted September 15, 2006 Share Posted September 15, 2006 Don't you have any indexes on the table other than the id? That would cause failure.Otherwise a simple way would to be store the action in session variable, and preventing repeating it when the same action is requested twice.You store your values in the table, upon sucess you write a value, say the uri or something else describing the action just performed. On every page request you simply check if that session variable is set, and skip the storing part if it is. At some point you will of course have to either unset or overwrtie it, unless you want the action to become unavailable for the duration of the session.If you want to ensure a database field has a unique value, use a UNIQUE index in it.Oh I almost forgot, your code has a parse error:echo"<h1>Data Already complete</h1>[i][b]"[/b][/i]; Quote Link to comment Share on other sites More sharing options...
dharm Posted September 15, 2006 Author Share Posted September 15, 2006 thank you for ur reply.. Sry..yes thr is also a unique id called project_id. But i will try putting a value within sessions sounds simpler!!. Thx! 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.