PHP - Like Comparison From Form Difficulty
Hi guys.
I have tried implementing PDO in my php. Basically, I have created a form, which will take a letter, and then pass it to the php file.
My hope was, whatever was entered by the user, whether that was in the guise of being manually entered by them or chosen by a dropbox etc, this would then be able to be used within the LIKE comparison. When I run my file however, I get the following message: Error: SQLSTATE[HY093]: Invalid parameter number: no parameters were bound. I am a little confused by this. I have used $_POST with the HTML form element, and have specified it in the SQL syntax. Can anyone please advise me as to where I am going wrong? 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 Hi, I have a form that I want to allow users to be able to add specific links, some are set types (domains) and just require the iser to enter the link, however, one is for whatever they wish and they must enter a name to describe it. Now im going to enter it into a database with the following columns: USER_ID || LINK_URL || LINK_TYPE || LINK_NAME Link name is optional (only needed if the link type is their own custom one), the link types are ID's related to a table of link types (facebook, twitter etc). Now I'm assuming that to differentiate the form elements for insertion into the database I would need to have a hidden form element with the type ID inside? However I don't really know how to go on from here. A small version of the form would be <input type="text" name="facebook_link" /> <input type="hidden" name="facebook_id value="1" /> <input type="text" name="twitter_link" /> <input type="hidden" name="twitter_id value="2" /> <input type="text" name="own_site" /> <input type="text" name="own_site_description" /> <input type="hidden name="own_site_id" value="3" /> However, I'm assuming this is wrong because I'll need to enter everything into an array won't I? I just can't get my head round it to out put thi results into a foreach statement. Can anybody help me please? Hi All. I am new to PHP, but am learning. I have set myself a mini project to learn some new php and to have some fun! I was hoping that someone would be kind enough to tell me how difficult this would be to achieve, and how they would best suggest to approach it. I want to create a 'availability checker'. I want to create a field where I can input a date. If the date exists in my mysql database then it returns NO, if the date isn't in the database it returns YES. For a admin area I want to have a place to add dates, and maybe some details about these dates. I don't think its overly complicated, but it should still be quite a challenge for me. Any guidance would be greatly appreciated. Thanks Hello everyone. Before I start, I'm relivily new to PHP but have been doing it for a few weeks or so, my latest problem that i've been trying to crack for a few days now is using the "imagecopy" command in php, I'm working on an avatar script that lets users design there own avatar, selecting clothes, hair, eyes, etc. I've only just started and i've ran into a rather large problem so don't seem to be able to move any further, This is the code i have Quote <?php ob_start (); /* background */ $bg = imagecreatefrompng('bg.png'); /* foreground */ $fg = imagecreatefrompng('fg.png'); /* frontground */ $fgg = imagecreatefrompng('fgg.png'); $x = imagesx($bg); $y = imagesy($bg); imagecopy($bg, $fg, $fgg, $x, $y); header('Content-Type: image/png'); imagepng($bg); imagedestroy($bg); imagedestroy($fg); imagedestroy($fgg); ?> However for some reason, probably a simple fault, it's just giving me a broken image link? I'm not sure why it's doing this if you want to see exactly what it's doing please look at http://chat.blastgames.org/index.php Like i say i'm clueless so any help would be much appreciated, Also if anyone knows of any downloadable php avatar scripts that lets you customize things like hair, clothes etc. please tell me, I've been searching for one for a while, Thanks for reading , Any help will be much appreciated. Hi, I have an interface where the user picks an image to upload, it then uploads the original (big) image. That same image then appears but at a reduced size of 150px max height or width, the size is defined in the img tag using height="XX" width ="XX", so it is the same image file, just with its dimensions set in the html. The user then drags a div over the image to crop it. The problem I am having is getting the reference image crop dimensions to translate to the actual full size image. Have attached an image of what the result is. What formula do I need to get it to translate to the bigger image properly? Here is my code: if($_GET['mode'] == 'imageupload') { $imgNumber = $_GET['img'] ; $fileName = strtolower($_FILES["setFile$imgNumber"]['name']) ; $ext = explode('.', $fileName) ; if($ext[1] != 'jpg' && $ext[1] != 'JPG' && $ext[1] != 'jpeg') { echo "<span class='iFOutput'>Can only accept JPG images.<br /><br /> The image you tried to upload was '" . $ext[1] . "'.</span>" ; exit() ; } $tmpName = $_FILES["setFile$imgNumber"]['tmp_name'] ; move_uploaded_file($tmpName, '../uploads/' . $fileName) ; $sizeInfo = getimagesize('../uploads/' . $fileName) ; $resizedArray = imageResize($sizeInfo[0], $sizeInfo[1], 204) ; $finalImageSrc = '../uploads/' . $fileName ; echo '<img id="image' . $imgNumber . '" src="' . $finalImageSrc . '" width="' . $resizedArray[0] . '" height="' . $resizedArray[1] . '" />' ; // SCALED IMAGE FOR CROPPING INTERFACE } elseif($_GET['mode'] == 'imagecrop') { $imgSrc = $_POST['imagePath'.$_GET['img']] ; $thisX1 = $_POST['image' . $_GET['img'] . 'X1'] ; $thisY1 = $_POST['image' . $_GET['img'] . 'Y1'] ; $thisX2 = $_POST['image' . $_GET['img'] . 'X2'] ; $thisY2 = $_POST['image' . $_GET['img'] . 'Y2'] ; $original = imagecreatefromjpeg($imgSrc) ; list($width, $height) = getimagesize($imgSrc) ; if ($width > $height) { $ratio = (150 / $width); } else { $ratio = (150 / $height); } echo $ratio ; $thumbCanvas = imagecreatetruecolor(150, 150) ; $thisX1 = round($thisX1/$ratio) ; $thisY1 = round($thisY1/$ratio) ; imagecopyresampled($thumbCanvas, $original, 0, 0, $thisX1, $thisY1, 150, 150, $width, $height) ; imagejpeg($thumbCanvas, '../uploads/thumbnail.jpg') ; echo '<img id="image' . $_GET['img'] . '" src="' . '../uploads/thumbnail.jpg' . '" />' ; } Hello! I'm having trouble with a class that extends another, and I don't think I understand the 'extends' concept properly. I've had my nose in various manuals, but I haven't had any luck figuring it out. Here's a simplified version of my code: Code: [Select] class Position { private $latitude = 0; private $longitude = 0; public function getLatitude(){ return $this->latitude; } public function getLongitude(){ return $this->longitude; } } class Coordinates extends Position { function __construct($nlat, $nlong){ $this->latitude = $nlat; $this->longitude = $nlong; } } $lat = -123; $long = 44; $coordFirst = new Coordinates($lat,$long); print($coordFirst->getLatitude()); I expect -123 to be printed, but I always get 0 instead. Could someone let me in on what I'm missing here? Thanks a bunch! How hard would it be to build a basic Online Forum using PHP? (Yes, I know there are open-source versions out there a plenty, but what fun is that?!) I have a book by Larry Ullman that describes how to do it, but I don't have the book with me and have never programmed such a thing - obviously - so I'm not sure how hard it would be and what you would get for the effort?! Thanks, Debbie I have a couple of loops that are supposed to 1) list all the values of one table as check boxes then 2)compare them to the values of another table. If they match that checkbox is supposed to be pre-checked. I have some code but it is not working just right yet and I was hoping someone could help me. Code: [Select] <?php include("../../../cart/includes/openDbConn.php"); $sql = "SELECT Name FROM FabricType"; $dogettype = 'SELECT Type FROM FabricsTypes WHERE SKU = "'.$sku.'";'; $result = mysql_query($sql); while($results = mysql_fetch_array($result)) { if( $i % 3 == 0 ) { echo '</tr><tr>'; } $result2 = mysql_query($dogettype); while($results2 = mysql_fetch_array($result2)) { if(trim($results2['Type']) == trim($results['Name'])) { $ischecked = 'checked="checked"'; $value = 1; } else { $ischecked = ''; $value = 0; } } $i++; $tn = trim(ucfirst($results["Name"])); echo '<td> <label> <input type="checkbox" name="typeGroup1[]" '.$ischecked.' value="'.$results['Name'].'"> '.$tn.' </label> </td>'; } ?> With this code it echoes the check boxes correctly but only checks it if it is the last value in $results2. If I move the second while loop like so: Code: [Select] <?php include("../../../cart/includes/openDbConn.php"); $sql = "SELECT Name FROM FabricType"; $dogettype = 'SELECT Type FROM FabricsTypes WHERE SKU = "'.$sku.'";'; $result = mysql_query($sql); while($results = mysql_fetch_array($result)) { if( $i % 3 == 0 ) { echo '</tr><tr>'; } $result2 = mysql_query($dogettype); while($results2 = mysql_fetch_array($result2)) { if(trim($results2['Type']) == trim($results['Name'])) { $ischecked = 'checked="checked"'; $value = 1; } else { $ischecked = ''; $value = 0; } $i++; $tn = trim(ucfirst($results["Name"])); echo '<td> <label> <input type="checkbox" name="typeGroup1[]" '.$ischecked.' value="'.$results['Name'].'"> '.$tn.' </label> </td>'; } } ?> It only echoes out the first results of $results for however many values there are in $results2. Thanks for any help. Hi, its me again! So i have this function which gets all the events in my db according to its mall_id and a date (year-month). I merged the $month and $year so i can compare it to the date field in my table. I used DATE_FORMAT to modify my date field so i can compare them but it doesn't seem to work perfectly, Code: [Select] function select_all_events($mall_id, $month, $year, $public) { global $connection; $monthname = $month; $monthnum = date("n", strtotime("01-".$monthname."-2011 00:00:00")); if($monthnum < 10) { $monthnum = "0" . $monthnum; } $selected_date = $year . "-" . $monthnum; $query = "SELECT *, DATE_FORMAT(date ,'%Y-%m' ) AS date "; $query .= "FROM table "; $query .= "WHERE malls_id=" . $mall_id; $query .=" AND date =" . $selected_date; if($public == true) { $query .= " AND visible = 1"; } $query .= " ORDER BY date DESC"; $result_set = mysql_query($query, $connection); confirm_query($result_set); return $result_set; } I tried echoing $selected_date, the format is correct, the problem seems to be the comparison.. Also i tried doing it like this: Code: [Select] $query = "SELECT * "; $query .= "FROM table "; $query .= "WHERE malls_id=" . $mall_id; $query .=" AND DATE_FORMAT(date ,'%Y-%m' ) =" . $selected_date; but the results are mismatched, like when i choose 2012 January it display's 2011 December ... This dates are making my head dizzy and costing me time..lol Any ideas? Thanks in advance! 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! Hi Everyone. I am new to SQL and trying to write a query against the following results table that would allow me to list the subjects where the student Mary has got a higher score than Tom.
Subject
Student
Teacher
Score
Maths
Tom
Anderson
67
Maths
Mary
Anderson
68
English
Tom
Lewis
55
English
Mary
Lewis
44
French
Tom
Joubert
87
French
Mary
Joubert
76
Geography
Tom
Arnold
76
Geography
Mary
Arnold
82
I believe I should be using the join clause but am unable to get this to work.
Thanks
Hi guys I am looking for a loop which will run untill there is a difference of 10 minutes. The timestamp I wish to use is "ISO 8601 date (added in PHP 5)" [ date("c")] If anyone know some code for this it would be much appreicated. I can do the loop its just the comparison between the two timestamps as part of the loop I have no idea where to start on. Cheers, and thanks in advance. I need some idea of why my code works on 2 servers except the one that it needs to work on. Below is the code including the sites where the phpinfo is loaded. Please help me figure this one out, it's probably simple but I don't see it. phpinfo of the one not working as expected phpinfo of the one that works as expected The problem is here I think? Quote $insertGoTo = SITE_URL."?pg=registered&addr=".$myid; header('Location:'.$insertGoTo); The code is too long to be posted... in reply... all my dates I'm reading from a database are formatted mm/dd/yyyy and I want to find the number of days difference from the duedate and the datepaid (dayslate) . ? I'm having a problem with (what I'm almost certain is) variable scope, maybe you can help... So I've got a parent class that, among other things, gets the name of the filepath, explodes this filepath, checks for files with names that mirror that filepath (without the slashes of course), and includes them if they exist: class ParentClass { public $RootFolder; public $PageSections; function __construct() { global $root_folder; $this->RootFolder = $root_folder; //get all directory names... $cleanse = $this->RootFolder; $pagepath = str_replace($cleanse, '', dirname($_SERVER['PHP_SELF'])); $this->PageSections = explode('/', $pagepath); } function RequireIfExists ($sections, $root_folder, $file_name, $file_type) { foreach ($sections as $i){ if (isset($o)) { $i = $o."/".$i; } $file = $root_folder.$i."/".$file_name.$file_type; if (file_exists($_SERVER['DOCUMENT_ROOT'].$file)) { require ($_SERVER['DOCUMENT_ROOT'].$file); echo "<!--".$file." included -->"; //temporary measure to ensure that the file is at least being called. } $o = $i; } } // so, excuting the function // $this->RequireIfExists($this->PageSections, $this->RootFolder, "sectionvars", ".php"); // on some/sub/folder/index.php // will look for somesectionvars.php, somesubsecitonvars.php & somesubfoldersectionvars.php // and include whichever ones exist. } Then there is a child class that utilizes this function, and successfully requires the file. I know the file is coming through because the echo statement on the page shows up in the code, but I cannot get the variables to pass through? <?php class HtmlHead extends PageBlock{ public $PageKeywords; public $PageDescription; public $PageStyles; public $PageScripts; //------------------------ public $SectionKeywords; public $SectionDescription; //------------------------ public $SiteKeywords; public $SiteDescription; public $SiteStyles; public $SiteScripts; //------------------------ public $CatchAll; function __construct() { parent::__construct(); //$this->RequireIfExists($this->PageSections, $this->RootFolder, "sectionvars", ".php"); //I have tried calling the function here with no luck global $site_description, $site_keywords, $section_description, $section_keywords, $xyz; //also made sure to global the variables from the required page $this->SiteDescription = $site_description; $this->SiteKeywords = $site_keywords; $this->SectionDescription = $section_description; $this->SectionKeywords = $section_keywords; $this->PageDescription = $page_description; $this->PageKeywords = $page_keywords; } function Constructor() { $this->RequireIfExists($this->PageSections, $this->RootFolder, "sectionvars", ".php"); //Tried calling the function here as well, no luck global $xyz; //global'd the var i want echo "\n<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />"; echo "\n<!--Sec Keywords are".$xyz."-->"; //Tried to echo the var... //------------------------Rest of code... } } And here is the page that is being required... <?php echo "<!-- 1234 1234 1234 1234 -->"; //test measure to see if/where file is including $section_keywords = "red, secondary"; $section_description = "this is the red section description"; $xyz = "1234"; //test Var to see if there was a naming conflict with the above two.. ?> What am I overlooking this time? 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 |