PHP - Sql String Comparison / Sql Sting Variables To Array
I have an audit trail that record users ids and a copy of the sql string for any updates they make to my application. This is very easy for me to follow to find exactly where changes happened but do end users it is a bit of a challenge.
Has anyone seen or made a script that can either compare two sql strings to see what fields have different values or a script that takes an SQL string and outputs its field names and values to an array that I can use for comparisons? Example being the look at a update made by user X, the database pulls the sql for that change then looks for the previous change up any user before (update sql should have a value for all fields) then compares to see what user X changed. If not im thinking of case statement to divide sql request between inserts and update then writing a script to split the strings based on where the commas were. Any thoughts? Similar TutorialsHi guys I was just wondering if there is some date combination for which this type of comparisons will not work. var_dump("2010-15-1">"2010-4-01"); Provided the date is always in the YYYY-mm-dd format with optional preceding 0 . Thanks I have an array $array_1 Code: [Select] ARRAY( [0] => info 1 [1] => info 2 [2] => info 3 ) and I have another array $array_2 Code: [Select] ARRAY( [0] =>thank you and welcome to what ever [1] =>the info you added * thanks for entering your info ) I want to loop though the first array and place the values into the [1] of the second array. But the tricky thing is I want it to insert were the * is. Code: [Select] foreach ($array_1 as $key => $val) { //not sure about this insert into ($array_2[1],after *, $val); } any help would be awesome. Hi! gud pm guys! I have a simple problem which i can't seem to workout so i kinda need your expert help! I'm trying to compare a variable to a string in my db, the variable and the entry on my db has a format of (car - branch), I made this simple function to do that but it doesn't seem to compare properly.. Code: [Select] function get_car_code($branch) { global $connection; $query = "SELECT code "; $query .= "FROM car_code "; $query .= "WHERE branch =" . '"$branch"'; $query .= " LIMIT 1"; $result_set = mysql_query($query, $connection); confirm_query($result_set); return $result_set; } when its called back it doesn't return anything.. I'm thinking its the white spaces (or I'm wrong) but i needed them so i cant removed them.. Any suggestions? Thanks in advance! I'm compiling and running C++ applications from PHP. I'm using backticks to capture the output of the applications ran. The output is just some simple text. In my case "Miles per gallon = x" where x is just a number. I cannot for the life of me get the comparison to return true. For example Code: [Select] $command1="./a.out1 <input1"; $a = `$command1`; $command2="./a.out2 <input2"; $b = `$command2`; if(strcmp($a,$b)==0){ ... } else{ // this is always executing ... } The two strings $a and $b are both "Miles per gallon = 10". I have checked both variables using var_dump(bin2hex($a)) and get dump1= string(42) "4d696c6573207065722067616c6c6f6e203d203130" dump2= string(42) "4d696c6573207065722067616c6c6f6e203d203130" Any idea on what's happening? I have this $str variable which say holds "String" and in my comparison I'm checking if it's content is "string" and it is supposed to return true but it isnt because of the case, how do I compare them without the case being an issue ? Hi
i am trying to compare to arrays
$a = Array ( [q1] => no [q3] => yes [q2] => yes );
$b = Array ( [q1] => no [q3] => yes [q2] => yes );
But when i intersect them it results in one element only, dont know why???
$c = array_intersect($a,$b);
print_r($c);
output -
Array ( [q1] => no )
Hi guys ,
Again i facing array comparison problem
i got this after var_dump() $a and $b
array(4) { ["q1"]=> string(3) "yes" ["q4"]=> string(2) "no" ["q3"]=> string(2) "no" ["q2"]=> string(2) "no" } array(4) { ["q1"]=> string(2) "no" ["q4"]=> string(3) "yes" ["q3"]=> string(3) "yes" ["q2"]=> string(3) "yes" } But when i use array_intersect($a,$b).. it results this array(4) { ["q1"]=> string(3) "yes" ["q4"]=> string(2) "no" ["q3"]=> string(2) "no" ["q2"]=> string(2) "no" } Don't know why, but there is no same value in both I have a string that looks like /index.php?g1=111&g2=222&g3=333. How can I obtain the value of g1 (i.e. 111)? It does not represent the current state of the server thus I cannot just use $_GET. It also is not necessarily the first item. The script below appears to work, however, http://php.net/manua...n.parse-url.php states This function is intended specifically for the purpose of parsing URLs and not URIs. However, to comply with PHP's backwards compatibility requirements it makes an exception for the file:// scheme where triple slashes (file:///...) are allowed. For any other scheme this is invalid. It appears that my string is a URI and not a URL, but I might be wrong. How should this be accomplished <?php $str='/index.php?g1=111&g2=222&g3=333'; $array=parse_url($str); parse_str($array['query'],$get); echo("<p>{$get['g1']}</p>"); ?> I have the following code which has deliimiters of |||| and I need to break it apart into three strings and have a variable assigned to each string. I've tried exploding it but won't dynamically increase the variable. I know at one point about a year ago I used something like $var.=$foo and the $var would increase $var1, $var2, etc... Here's the string I need to break.j (And the string will be different every time, and some will have 2 string delimited some will have 20, and some inbetween. The rich contemporary style of the "Theo" Counter Height Table combines faux marble and a warm finish to create dining room furniture that adds an exciting style to the decor of any home. The thick polyurethane coated faux marble table top perfectly accentuates the warm brown finish flowing over the straight-lined contemporary design of the apron and legs to help create an exceptional dining experience. With the beautiful stitching and button tufting details of the faux leather upholstered bar stools, the "Theo" Counter Height Table is a refreshing addition to any home.||||Table top made with polyurethane coated print marble. Aprons and legs made from select veneer and solids with a warm brown finish. Chair is upholstered in a brown PVC with accent top stitching. D158-233 bar stool dimension: 18"W x 21"D x 40"H.||||Click here for complete image download listing for series D158. In a perfect world it would be: Code: [Select] $desription1="The rich contemporary style of the "Theo" Counter Height Table combines faux marble and a warm finish to create dining room furniture that adds an exciting style to the decor of any home. The thick polyurethane coated faux marble table top perfectly accentuates the warm brown finish flowing over the straight-lined contemporary design of the apron and legs to help create an exceptional dining experience. With the beautiful stitching and button tufting details of the faux leather upholstered bar stools, the "Theo" Counter Height Table is a refreshing addition to any home."; $description2="Table top made with polyurethane coated print marble. Aprons and legs made from select veneer and solids with a warm brown finish. Chair is upholstered in a brown PVC with accent top stitching. D158-233 bar stool dimension: 18"W x 21"D x 40"H.": $description3="Click here for complete image download listing for series D158."; $id[] = 12345; $id[] = 12345; $id[] = 12345; $id[] = 12345; $id[] = 12345; how would I combine these into a string "12345,12345,12345,12345,12345" hello, im wondering how to properly code the following. Code: [Select] $stdate = date( 'Ymd', strtotime($pdate) ); $sttime = date( 'His', strtotime($tstart1) ); $dtStart = ".$stdate.'T'.$sttime.'Z'"; echo "$dtStart"; i would like the echo to read 20110309T050000Z Hi, I have a string with the value of { "success": true, "delivered": true, "contactDetailsRequired": false, "message": "Signed For by: D ANDERSON ", "signature": "https://webservices.thedx.co.uk/PodImage/ImageHandler.ashx?tn=906732192165", "date": "21-07-2020", "serviceLevelName": "Consigned", "time": "13:33:19", "trackedProductName": "DataExchange" } How do i go about placing the values into variables so for example: $success = "true"; $delivered = "true"; $message = "Signed for by: D ANDERSON"; etc.... My mind has gone blank and im having one of those days, any help would be greatly appreciated. Thanks Hi I am trying to get all variables passed in a url string and wondered how would i do it? I dont know what they are yet and i need to set key as value. Any help? Hi Guys and Girls, Long time lurker, first time poster! I am usually able to read through the forums and find and answer without having to start a new thread but I've tried my best to no avail. I am having trouble with the following code: $afname="Gareth"; $alname="B"; $awayoption.="<OPTION VALUE=\"".$afname." \"".$alname."\">".$afname." ".$alname; I would want that to produce the following: Code: [Select] <OPTION VALUE=Gareth B">Gareth B The actual result at the moment is: Code: [Select] <OPTION VALUE="Gareth "B">Gareth B It has an extra " in the middle. Any ides or help would be great! Cheers I need to echo out some string variables in a form. I also want to add some validation for Name, email etc. I think I have the code right or close, but I can an error on the index.php page which is. "Fatal error: Call to undefined function form_row_class() in index.php on line 14" here is the code for the form <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>String Tester</title> <link rel="stylesheet" type="text/css" href="main.css"/> </head> <body> <div id="content"> <h1>String Tester</h1> <form action="submit.php" method="post"> <table> <tr class="<?php echo form_row_class("name") ?>" > <th><label for="first_name">Name</label></th> <td> <input name="first_name" id="first_name" type="text" value="<?php echo h($_POST['name']); ?>" /> <?php echo error_for('name') ?> </td> </tr> <tr class="<?php echo form_row_class("email") ?>"> <th><label for="email">Email Address</label></th> <td> <input name="email" id="email" type="text" value="<?php echo h($_POST['email']); ?>" /> <?php echo error_for('email') ?> </td> </tr> <tr> <th></th> <td><input type="submit" value="submit" /></td> </tr> </table> </form> <h2>Message:</h2> <?php echo "<table>"; echo "<tr><td>"; echo $name; echo "</td></tr>"; echo "<tr><td>"; echo $email; echo "</td></tr>"; echo "<tr><td>"; echo $phone; echo "</td></tr>"; echo "</table>"; ?> </div> </body> </html> and the submit portion <?php // If request is a form submission if($_SERVER['REQUEST_METHOD'] == 'POST'){ // Validation // Check first_name is non-blank if(0 === preg_match("/\S+/", $_POST['name'])){ $errors['name'] = "Please enter a name."; } // Check email is valid (enough) if(0 === preg_match("/.+@.+\..+/", $_POST['email'])){ $errors['email'] = "Please enter a valid email address."; } // validate a phone number if( !preg_match("/^([1]-)?[0-9]{3}-[0-9]{3}-[0-9]{4}$/i", $phone) ) { echo 'Please enter a valid phone number'; } // If no validation errors if(0 === count($errors)){ // Sanitize first, last, and email $name = mysql_real_escape_string($_POST['name']); $email= mysql_real_escape_string($_POST['email']); $email= mysql_real_escape_string($_POST['phone']); } // Helpers function form_row_class($name){ global $errors; return $errors[$name] ? "form_error_row" : ""; } function error_for($name){ global $errors; if($errors[$name]){ return "<div class='form_error'>" . $errors[$name] . "</div>"; } function h($string){ return htmlspecialchars($string); } ?> probably something simple I am missing. Pretty simple I would think but I'm unsure on the syntax. I have a variable, $ename. It's actually data from a form that I pass to said variable. What I want is to then in turn use this string in a mkdir() function. Something like Code: [Select] mkdir("dir/folder/$ename/"); Obviously that doesn't work. I'd imagine I have to use some sort of . syntax. So I'm trying to create an Array from a comma separated string containing array{s}. How can I take a string full of comma separated hex values such as : <?php $myStr = ( "00ffff", "00cccc", "009999", "007777", "004444", "001111", "01ffff", "01cccc", "019999" ); ?> & turn it into 3 separated arrays like : <?php $myNewArrs = [ Array1 ( 3 ), Array2 ( 3 ), Array3 ( 3 ), ]; ?> which REALLY looks like : <?php $myNewArrs = [ Array ( "00ffff", "00cccc", "009999" ), Array ( "007777", "004444", "001111" ), Array ( "01ffff", "01cccc", "019999" ), ]; ?>
? Thank you & have a great afternoon!
Edited May 27 by AquariaXI Code: [Select] $query = "SELECT content FROM license WHERE serial = '".$serial."'"; Hey everyone... Been over a year or more since I have had seek help here but I have something that I just do not understand. I am submitting a from from one domain - www.mydomain.com - to a form handler on another domain - www.theirdomain.com all under https. The form data is getting to theridomain.com just fine, the other side is handling it properly and all is well there. The issue is they are taking the response they generate and shipping it out via cURL using the below (they were nice enough to share this with me). Code: [Select] $url = $_SESSION['request']['retUrl']; $fields = array( 'hash'=>rawurlencode($hash), 'responseText'=>rawurlencode($_SESSION['response']['responseText']), 'cid'=>rawurlencode($_SESSION['request']['cid']), 'name'=>rawurlencode($_SESSION['request']['name']), 'actCode'=>rawurlencode($_SESSION['response']['actCode']), 'apprCode'=>rawurlencode($_SESSION['response']['applCode']), 'Token'=>rawurlencode($_SESSION['response']['token']), 'req_number'=>rawurlencode($_SESSION['request']['req_number']), ); foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; } rtrim($fields_string,'&'); if (isset($_SESSION['request']['Address1'])) { $Address = array( 'Address1'=>rawurlencode($_SESSION['request']['Address1']), 'Address2'=>rawurlencode($_SESSION['request']['Address2']), 'City'=>rawurlencode($_SESSION['request'][City']), 'State'=>rawurlencode($_SESSION['request'][State']), 'Zip'=>rawurlencode($_SESSION['request']['Zip']), 'Country'=>rawurlencode($_SESSION['request']['Country']), ); foreach($Address as $key=>$value) { $Address_string .= $key.'='.$value.'&'; } rtrim($Address_string,'&'); } $end = array( 'END'=>"END" ); foreach($end as $key=>$value) { $end_string .=$key.'='.$value; } rtrim($end_string,'&'); I have worked for almost a week and I CANNOT snag the incoming data! All I am trying to do is collect this and convert it into $_SESSION data for use on a success page. If any one has any thoughts or in site, please.... |