Philip
Staff Alumni-
Posts
4,665 -
Joined
-
Last visited
-
Days Won
20
Everything posted by Philip
-
[SOLVED] Re: Novice Help needed in php Arrays
Philip replied to edster1980's topic in PHP Coding Help
Maybe it's just me, but I'm not sure what you're trying to hit at here: <?php if($q2 == $number2[2] . $number2[1]) ?> -
You can have 2 sets of curly braces without an else clause? I'm 99.9% sure this isn't legit coding: <?php if($var) { echo $var; } { echo $var2; } ?>
-
From the sun boards, seems they got it solved - however it looks to be the same thing you are doing (on the PHP side anyways).... http://forums.sun.com/thread.jspa?threadID=780050
-
Sorry, I just realized I overlooked some of my mistakes in my first reply, which now is tested and works in all cases (well, almost... not "+1 - not correct", how you see that is really different from "1" I'm not sure.): <?php if(!is_int($quantity) || $quantity<0) { $quantity = 0; } ?>] However, btherl, I ran your preg with the test cases and they failed. Still allows the decimals/negatives
-
Why not just use is_int? http://us3.php.net/manual/en/function.is-int.php <?php $quantity = 2; if(is_int($quantity) && $quantity>0) { $quantity = 0; } ?>
-
SELECT * FROM `phones` WHERE `network` IN($network)
-
[SOLVED] Disabling HTML in INPUT and TEXTAREA
Philip replied to tomcommathe's topic in PHP Coding Help
You echo'd something before you put your header output echo $bar; ... header('Location:http://mopedstl.com/phpTest/newsUpdate/'); I would just comment out the header line, for now. -
Oops, didn't see there were 2 more $POST's.... they must be $_POST['varname'], not $POST['varname']
-
<?php // $networks is the array of marked checkboxes, after cleanup of course $var = '\''.explode('\', ', $networks).'\''; $query = "SELECT * FROM `phones` WHERE `network` IN($var)"; // continue query ?>
-
<?php if(!isset($POST['name']) || !isset($POST['email']) || !isset($POST['subject']) || !isset($POST['body'])) ?> Should really be: <?php if(empty($_POST['name']) || empty($_POST['email']) || empty($_POST['subject']) || empty($_POST['body'])) ?> Isset is great for checking to make sure a variable was set, but will still return true in all of those cases. However empty will check to make sure something was actually filled.
-
I'll give it a shot: 1. if (isset($item1))... will always happen, because you have initialized the variable $item1 in the statement above it. You need to check the return value, see if it's false or not. 2. Use the IN( ) command. $result = mysql_query("SELECT * FROM `menus_show` WHERE `id` IN('$meal1', '$meal2')"); That way, lets say if you have 3 as meal id #1, the query will show: However, with using this, you need to make sure $meal1 and $meal2 are both sanitized, and initialized (if it's not, you can set it to ''). Also, this would combine the results, and I'm not sure if you wanted to keep it separated.
-
[SOLVED] Query multiple choices within one field?
Philip replied to limitphp's topic in PHP Coding Help
You said the form name is "genre[]", but you're still putting in $_POST['genres']... or is that just a typo in your post? -
Okay, I've been playing around with MySQLi for a few days now - as I needed a more OOP way of reaching the DB. However, I want to be able to be given what columns to select via function parameter, and then run a prepared query like that. I've been able to do that, however I cannot for the life of me figure out how to get the results, since it you have bind the variables. Here's an example of what I'm trying to do (eventually to switch to full OOP and throw this into a class): <?php function getRow($TABLE, $ID, $COLS) { global $mysqli; // get mysqli for($i=0, $col='';$i<count($COLS);$i++) { // loop to grab the column names (these will be safe as they are internal vars) if($i!=0) { $col.=' ,'; } $col.='`'.$COLS[$i].'`'; } // Create query: $query = 'SELECT '.$col.' FROM `'.$TABLE.'` WHERE `id`=?'; if($dbh = $mysqli->prepare($query)) { // SQL is prepped -> lets add the value in now $dbh->bind_param("d", $ID); // Execute it $dbh->execute(); // we can add more executions here if needed later // Store the result, for num_rows $dbh->store_result(); if($dbh->num_rows()>0) { $r = ''; // to suppress any warnings from php // If there were rows found, then we're in business while($dbh->fetch() as $k => $v) { // return value array $r[$k] = $v; } // mysqli fetch array/assoc/row didn't work here either =( // we must find a way to bind_results with variable amounts of variables } else { // otherwise we need to display a warning. addError(WARNING, "No results were found"); // return value $r = false; } // Free the memory $dbh->free_result(); // close this connection, $mysqli will stay open still $dbh->close(); } else { // oops, error! addError(ERROR, "<strong>MySQLi:</strong> ".$mysqli->error); // return value $r = false; } return $r; } ?> I'll get: Now, I'm thinking it is possible with variable variables (it's been a long time since I've worked with those though), however I'm not sure. Any suggestions?
-
For domains they don't suck... but hosting, yes. For someone used to cPanel, and having a client insist on using GoDaddy (what they were previously using) it's a lot different. Oh, and their site navigation sucks IMO (although they are starting to upgrade it all)
-
Or how about those people who don't use the preview button an misspell [tags]? Love them too
-
[qoute]Lengthy problems, that have no question that the person wants answered. Haha, thats one of my favorites. I'm glad you took the time to explain everything, but what can we help you with? My other favorite: -Can you test this site?..... and they forget to put in the URL or expect us to know it was the one in their sig. It does bug me when people don't even try to research their problem. You can typically find things on a search engine within a matter of minutes. Oh well, people are lazy.
-
Yeah, you have "'...$w5a', '$w5a', '$w6a',..."
-
[SOLVED] parse error, unexpected T_STRING (im sure its something stupid)
Philip replied to jhath's topic in PHP Coding Help
<?php //... $sql="INSERT INTO `care` (`First_Name`, `Last_Name`, `Group_ID`, `Home_Phone`, `Cell_Phone`, `Work_Phone`, `Address`, `City`, `State`, `Zip`, `Email`, `Birthday`, `Anniversiary`, `Spouse`, `Child1`, `Child1_DOB`, `Child2`, `Child2_DOB`, `Child3`, `Child3_DOB`, `Child4`, `Child4_DOB`, `Child5`, `Child5_DOB`, `Child6`, `Child6_DOB`, `Extra`) VALUES ('$First_Name', '$Last_Name', '$Group_ID', '$Home_Phone', '$Cell_Phone', '$Work_Phone', '$Address', '$City', '$State', '$Zip', '$Email', '$Birthday', '$Anniversiary', '$Spouse', '$Child1', '$Child1_DOB', '$Child2', '$Child2_DOB', '$Child3', '$Child3_DOB', '$Child4', '$Child4_DOB', '$Child5', '$Child5_DOB', '$Child6', '$Child6_DOB', '$Extra')"; echo $sql."<br />"; $result=mysql_query($sql) or die(mysql_error()); //... ?> Please post what it prints [the query]... and you're 100% sure you have a column 'Child6_DOB' in the DB? -
Well, actually, if you look at the PHP manual for magic_quotes: Reasons: Maybe I'm wrong because I still see so many people here using that, but I still use addslashes/stripslashes
-
[SOLVED] parse error, unexpected T_STRING (im sure its something stupid)
Philip replied to jhath's topic in PHP Coding Help
$result=mysql_query($sql); add an "or die" statement: $result=mysql_query($sql) or die(mysql_error()); this always helps when testing out code. -
You would use the GET to find out how to sort: <?php $sortby = $_GET['sortby']; //Don't forget to clean the variable! $okay_values = array("publisher", "title", "author", "copyrightdate"); //Check to make sure value is okay & legal. if (in_array($sortby, $okay_values)) { //if its in the array, great! we can continue $sql = "SELECT * FROM `stories` ORDER BY ".$sortby; //You could also do more with ASC/DESC keys } ?> Just a rough outline of what you would do