
Philip
Staff Alumni-
Posts
4,665 -
Joined
-
Last visited
-
Days Won
20
Everything posted by Philip
-
Is there a Easier way? Or more efficiant..
Philip replied to newman445617's topic in PHP Coding Help
And you're the type to come back in a few years and beg to have your profile & posts deleted for looking like an idiot. -
I like the last set the best - some of those are trippy
-
$hex = substr($hex, 1); That will remove the first character from the string, which is placed at the end of your while loop. So, 1e5a would become e5a after the first pass of the loop. Whenever you run the loop 4 times, you are left with an empty variable, not a variable with the value of a space character. When you had it while ($hex != ' ') it would run that loop until hex was just a ' ' which would never happen. And because it was empty, and your while loop looked for a space, when it came to the if statements, the empty $hex wasn't a character between 'a' and 'f' if (ord($char) >= ord('a') and ord($char) <= ord('f')) , and it wasn't a integer between '0' and '9'.... else if (ord($char) >= ord('0') and ord($char) <= ord('9')) so it fell back to the last else statement - return an invalid hex string. else return INVALID_HEX_STRING;
-
Is there a Easier way? Or more efficiant..
Philip replied to newman445617's topic in PHP Coding Help
I find it easier to do the following, especially when you have a lot of entries: <select name="skinstyle"> <?php $options = array( 'Default' => 0, 'Light Blue' => 1, 'Sunset' => 2, 'Beautiful Blue' => 3, ); foreach($options as $text => $value) { echo '<option value="'.$value.'"'; if($Profile['skinstyle'] == $value) echo ' selected="selected"'; echo '>'.$text.'</option>'; } ?> </select> Edit: quite similar to CV's, just with keys/values for the options. -
You used a double quote instead of a single quote on the first echo... <?php echo '<div id="copyright" style="position:absolute;left:55px;width:150px;height:44px;z-index:32'; if(isset($_SESSION['myusername'])) { echo 'top:628px;'; } else { echo 'top:588px;'; } echo '" align="left"> <font style="font-size:13px" color="#000000" face="Arial">Squiblo © 2009</font></div>'; ?> <div id="copyright" style="position:absolute;left:55px;top:588px;width:150px;height:44px;z-index:32" align="left"> <?php if(isset($_SESSION['myusername'])) echo '<font style="font-size:13px" color="#000000" face="Arial">Squiblo © 2009>'; ?> </font></div>
-
Which, technically could be shortened even more.. it just comes down to how readable you really want it. foreach(array('age', 'gender', 'rate', 'last_login') as $k) $data[$k] = (!empty($_GET[$k])) ? $_GET[$k] : ((isset($_POST[$k])) ? $_POST[$k] : ''); // or, with variable variables. foreach(array('age', 'gender', 'rate', 'last_login') as $k) $$k = (!empty($_GET[$k])) ? $_GET[$k] : ((isset($_POST[$k])) ? $_POST[$k] : '');
-
CAN SOMEONE CHECK THIS CODE TELL ME WHAT I MISSED PLZ
Philip replied to duffman014's topic in PHP Coding Help
You're going to want to put single quotes around the values ... VALUES ('$name', '$pass', '$email', '$ip') -
CAN SOMEONE CHECK THIS CODE TELL ME WHAT I MISSED PLZ
Philip replied to duffman014's topic in PHP Coding Help
$sql = "INSERT INTO user (username,password,email,ip) VALUES ($name, $pass, $email, $ip"); Should be $sql = "INSERT INTO user (username,password,email,ip) VALUES ($name, $pass, $email, $ip)"; -
I like the Head First series - well, at least I did when I was learning ajax methods a while back. That whole series draws things out, isn't as boring as a normal programming book, which for me led to learning the material faster
-
ccleaner has done the job for me in the past on cleaning family's/friend's computers.... you know how some people always click the banner ads because they really think they can win a free ipod with no hitches.
-
The following works: <?php define("INVALID_HEX_STRING", " Invalid hex string", true); echo hex_to_decimal('0xff').' :: '.hexdec('0xff'); echo "<br>\n"; echo hex_to_decimal('1e5a').' :: '.hexdec('1e5a'); function hex_to_decimal ($hex) { $hex = strtolower($hex); $hex = trim($hex); if (substr($hex, 0, 2) == '0x') $hex = substr($hex, 2); $result = 0; while ($hex != '') { $char = substr($hex, 0, 1); if (ord($char) >= ord('a') and ord($char) <= ord('f')) $val = 10 + (ord($char) - ord('a')); else if (ord($char) >= ord('0') and ord($char) <= ord('9')) $val = ord($char) - ord('0'); else return INVALID_HEX_STRING; $result = ($result * 16) + $val; $hex = substr($hex, 1); } return $result; } ?> while ($hex != ' ') should have been while($hex != '') otherwise after it checks the last digit there is nothing left of the string but the loop will run until it finds a space.... which it won't thus returning INVALID HEX STRING
-
Ummm.... that screenie doesn't have anything to do with php's config file. Just your setup on your server. Create a page with just: <?php phpinfo(); ?> and see if anything might be blocking you
-
Ohh thanks, looks interesting
-
Umm... that would just return true/false and wouldn't grab the letter the user wants.
-
That is the one thing I hate the most - the little tweaks and hacks to make it look/act the exact same in all the browsers (especially when I used to work with IE6 too.) But, I think jcombs hit it, front end is that instant satisfaction that you can go to sleep at night with a smile on, where as the backend you can brag about it saying "hey look, this site has 100k users using and MY code keeps them happy" Plus I like the logic side of coding.... at my full time job I don't require that much thinking, so I enjoy challenging myself to a good in-depth project from time to time.
-
You did it write, but seeing it in color always helps: $query = 'SELECT something FROM table WHERE var = '.$var.' AND another = 1'; Have you tried echo'ing $query to see if it's what you're looking for?
-
Is it solved or was that a mistake?
-
"Not working" isn't very descriptive. Are you sure the page with the validation is "contact_sucess.php"? Also, make sure to use full php tags (<?php) instead of short tags (<? ) as they are turned off by default
-
my thoughts.
-
That means $result isn't a valid mysql result resource, or in other words mysql_query(" SELECT games.Name2 FROM games WHERE Name2 = \"$search\" ORDER BY occurrences DESC "); failed. Place a echo mysql_error(); just after you run that query and it will you give the reason why its failing.
-
Try running this and see what you get: mysql_select_db("comics", $con); //Delete all existing entries $delete = "DELETE FROM lookup_comics WHERE UID = '$session->username'"; mysql_query($delete); if (!mysql_query($delete,$con)) { die('Error: ' . mysql_error()); } //Insert all new entries into table $sql = "INSERT INTO lookup_comics (UID, CID) VALUES "; $comics = $_POST["comics"]; $count = 0; // for debugging foreach ($comics as $cid) { $count++; // for debugging $sql .= "('$session->username', '$cid'),"; echo "Record Added: ".$session->username.", ".$cid."<br>"; } $sql = substr($sql, 0, -1); echo $sql."<br>"; mysql_query($sql); echo 'Rows we should have: ',$count,' actual rows inserted: ',mysql_affected_rows(),' and any errors: ',mysql_error(),'<br>';
-
Something like: <?php $error_message = array(); if(($_FILES['userfile']['size'] > $_POST['MAX_UPLOAD_SIZE']) || ($_FILES['userfile']['size'] > $max_size)) { $error_message['size'] = "Upload file size too large: (<b>{$_FILES['userfile']['size']}</b>). Must not exceed {$max_size}kb."; } $array = explode(".", $_FILES['userfile']['name']); $nr = count($array); $ext = $array[$nr-1]; // I condensed all 3 of the next if's into one... since they were checking for the same thing pretty much. if(($ext !="jpg") && ($ext !="jpeg") && ($ext !="png") && ($ext !="pjpeg") && ($_FILES['userfile']['type'] != "image/jpeg") && ($_FILES['userfile']['type'] != "image/pjpeg") && ($_FILES['userfile']['type'] != "image/png") && ($info['mime'] != "image/jpeg") && ($info['mime'] != "image/pjpeg") && ($info['mime'] != "image/png")) { $error_message['format'] = "Upload file type un-recognized. Only .JPG or .PNG images allowed."; } if(count($error_message)>0) { // we had errors: foreach($error_message as $message) { echo '<strong>ERROR:</strong> '.$message.'<br>'; } // die, exit, or show form again. whatever you want here. } else { // we didn't have errors, continue with uploading // ... } ?>
-
So, this query: INSERT INTO lookup_comics (UID, CID) VALUES ('admin', '1'),('admin', '4'),('admin', '8'),('admin', '9'),('admin', '10') Is inserting something like this in the database? : 'admin' '1' 'admin' '1' 'admin' '1' 'admin' '4' 'admin' '4' 'admin' '4' 'admin' '8' 'admin' '8' 'admin' '8' 'admin' '9' 'admin' '9' 'admin' '9' 'admin' '10' 'admin' '10' 'admin' '10'
-
Ahhh, yes, I remember seeing this on the local news a few months ago. Lives about 30 minutes away. Sucks when it rains and your car is outside though