-
Posts
4,704 -
Joined
-
Last visited
-
Days Won
179
Everything posted by kicken
-
If the query only returns one result, there is no need for the loop. Also, as suggested, make the status values an associative array for easy looping and comparing. $query = mysqli_query($mysqli, "SELECT status From referrals WHERE id = '".$edit."';"); list($editstatus) = mysqli_fetch_array($query, MYSQLI_NUM); $statusList=array( 'N' => 'N/A' , 'I' => 'Installation Comp' //, add the rest here ); ?> <div class="status"><label for="edit_status">Edit Status</label> <select id="edit_status" name="edit_status"> <?php foreach($statusList as $statusCode=>$statusLabel){ ?> <option <?php echo $statusCode == $editstatus?'selected="selected"':''; ?> value="<?php echo $statusCode; ?>"><?php echo $statusLabel; ?></option> <?php } ?> </select> </div>
-
My best guess would be that you have incorrect connection details (hostname in particular). Check with your host to find out what your connection settings should be and make sure you are using those.
-
No, there isn't. Just learn to live with the fact that the user can open your site in however many tabs they want. Why are you trying to prevent such a thing anyway? I'd just be pissed off and never visit the site again if it was preventing me from using tabs
-
I don't really do design work, but I imagine if I did and such a thing happened, I'd put all the files into an archive somewhere and forget about them. Perhaps it (or bits of it) could be used in another probject, or if the original client comes back. I'm somewhat of a digital pack rat anyway though, I rarely delete anything.
-
The main idea is that your average user/script-kiddy isn't going to either be able to, or take the time to try and extract the key/salt from your software. Someone who does decide to try and extract the key/salt from the program could continue to generate their own requests.
-
Which API are you using to interact with the DB? sqlsrv_* functions, mssql_* functions, PDO w/ sqlsrv driver? Using PDO, the following has always worked for me: $stmt = $db->prepare($sql); if (!$stmt){ throw new SQLException($db, $sql); } $stmt->bindParam(':content', $content, PDO::PARAM_STR, null, PDO::SQLSRV_ENCODING_UTF8); if (!$stmt->execute()){ throw new DatabaseException($db, $stmt, $sql); }
-
You don't need (or want) to do stripslashes unless your PHP setup is configured with magic_quotes_gpc = on. You can check for that at runtime using get_magic_quotes_gpc. As for preventing cross-site scripting, all you need to do is use htmlentities on the input. I would prefer that over strip_tags. For SQL Injection, since you are using prepared statements with parameters for the values, you are fine on that end.
-
Seems to work fine for me. One thing you could change is to ensure $i is an int. $i=12345; while($i>0) { $j=$i%10; $i=intval($i/10); $sum=$sum+$j; } var_dump($sum);
-
Look at that closely. lName is not the same as lname.
-
The browser has to wait for the PHP script to complete. If you're not seeing an image, then either the PHP script is incorrect and returning bad data, or your browser is somehow incorrectly processing the data being returned. Use the browser's debug tools to see what is going on and if there are any errors being reported. Looking at the requests being made would be a good place to start, to see if the browser is 1) requesting the PHP script and 2) following that with a request for the twitter image. If your browser doesn't have such a tool, you can use something like Fiddler
- 15 replies
-
- php
- twitterapi
-
(and 1 more)
Tagged with:
-
Are you talking about something like the 'Duplicate tab' option in chrome where it opens the same page in another tab? You can't prevent that. People opening your site in multiple tabs is, for the most part, just something you have to accept, there isn't much you can do to control things like that.
-
There are already threads about this: Which PHP Editor do you think is the best v2 Editors
-
You'd group things in a multi-dimensional array as you read the result set from the database. Something like: $wineList=array(); while ($row=mysql_fetch_assoc($result)){ $regionId = $row['RID']; $wineryId = $row['WID']; $productId = $row['PID']; if (!isset($wineList[$regionId])){ $wineList[$regionId] = $row; } if (!isset($wineList[$regionId]['wineries'][$wineryId])){ $wineList[$regionId]['wineries'][$wineryId] = $row; } $wineList[$regionId]['wineries'][$wineryId]['products'][$productId] = $row; } Then you just loop through the levels of $wineList to output the information. foreach ($wineList as $regionId=>$regionInfo){ //output region title foreach ($regionInfo['wineries'] as $wineryId=>$wineryInfo){ //output winery title foreach ($wineryInfo['products'] as $productId=>$productInfo){ //Output product information } } } That way you only have one query to the DB to request the master un-grouped list. Much more efficient that way than sending a bunch of requests to the DB.
-
filter_has_var does not check if the given field has been filled in, it merely checks if it was included with the submission. A field with an empty value is still posted to the server, so it passes that test. The isset() function works the same way. If you want to check for an empty field, compare the value against the empty string ('') if (!filter_has_var(INPUT_POST, 'fName') || $_POST['fName'] == ''){ echo " please hit the back arrow and enter your name "; $chkErrors= TRUE; } Note that you can use empty(), mentioned above which is similar to the above. The main issue there is that an input of 0 would be considered empty. As such, any fields in which 0 is a valid input need to be processed as above, not using empty().
-
Socket can not be created while accessing PHP file
kicken replied to Ritesh_Prajapati's topic in PHP Coding Help
First, a couple of things: 1) If you post code, wrap it in tags (the <> button on the editor toolbar). This makes it much easier for people to read 2) You posted in the incorrect forum. The forum you posted in is for questions/comments about the PHP Freaks website, not for code help. I've moved the thread. As for your issue, which call specifically is failing? What is the exact error you are getting? Do some debugging to narrow down the problem area to within just a few lines. Are you positive that you do not have SELinux enabled? Your symptoms sound like a SELinux problem. The ability for apache to create sockets is generally revoked in the few SELinux environments I've encountered. -
Stupid forum and it's B) emoticon
-
If you're talking about how google has you upload a file of a specific name to your website in order to validate your ownership, then that is relatively easy. a) You generate a unique token and use it as part of the file name. uniqid can generate the token, md5 or sha1 can be used to hash it, making it more user friendly. You could use any other method you want too. B) Tell the end user what the token is and what to do, ie 'Create a file named "verify_XXXXX.html" in the root' where XXXXX is the token. c) Have your server make a http request to their site for the file. curl can be used to make this easy. If the file exists then consider them validated.
-
Question about a query I thought would be a lot simpler!
kicken replied to jbradley04's topic in MySQL Help
After you query for possible matches, do a little post processing to ensure that letters are not used more than they are allowed. Create a function that given a word and list of letters will return true/false depending on if the word can be created with those letters. Then, as you loop the results, check each word: function IsValidWord($word, $letters){ //...Implement this function //...array_count_values and str_split may be helpful } $validWords=array(); while ($row=$query->fetch()){ if (IsValidWord($row['word'], $searchLetters)){ $validWords[] = $row; } } -
Please use tags when posting your code. Also I moved your topic as you posted in the MS SQL server forum, which is not what you are using. The way you access an array element is using square-brackets ([]), not curly's ({}) so the above line should be: echo "Name: " . $row['name'] . ":::::Class:" .$row['class']. ":::::Number:" .$row['number'] . "<br>"; Lastly, add error checking to your query so you can see if it is failing or not: $result = mysql_query("SELECT * from student"); if (!$result){ die('Could not run query: '.mysql_error()); }
-
MP3 files - selecting a start and end point using PHP
kicken replied to willothewisp's topic in PHP Coding Help
Use exec() rather than shell_exec, then you can get back the return code from ffmpeg and check for success. You could also test for the output file using file_exists to make sure it was created. -
Randomly pick element in array then remove from the array
kicken replied to ttmt_73's topic in PHP Coding Help
It's generally easier to just randomize the array and then start take what you want off the top. Since you seem to be using all the array entries, just foreach the randomized array. $phrases = array('Hello Sailor','Acid Test','Bear Garden','Botch A Job','Dark Horse', 'In The Red','Man Up','Pan Out','Quid Pro Quo','Rub It In','Turncoat', 'Yes Man','All Wet','Bag Lady','Bean Feast','Big Wig'); shuffle($phrases); foreach ($phrases as $p){ echo $p, '<br>'; } -
Where to store sensitive client details (MYSQL DB credentials)
kicken replied to Neji's topic in PHP Coding Help
It refers the the way mysql handles user accounts/access, ie the Username/Password you use to access mysql. Pretty much the only thing that the PASSWORD function is intended to be used for is changing your mysql login password using a query like: SET PASSWORD=PASSWORD('YourNewPassword'); -
Where to store sensitive client details (MYSQL DB credentials)
kicken replied to Neji's topic in PHP Coding Help
You can encrypt it, you just need to use something that is reversible and keep the decryption key somewhere. Depending on how complex you want to get there are various ways you can go about this. On the basic level, just define the decryption key inside a PHP file somewhere that you include into your app. When you need to access the details you'd pull the encrypted values from the DB, include the key and decrypt them. Pros: Easy to setup and use. If your DB is leaked, the key is not leaked as well since it is stored separate. Cons: If the server itself is compromised, the attacker will get both the key and the database, enabling them to decrypt the details On a more advanced level, you'd set something up to store the key in memory, and have your app access the key that way. You'd have to input the key manually whenever you restart your server. Pros: The key is not physically stored anywhere, thus simple filesystem hacks or DB dumps will not reveal it. Cons: Takes a bit more effort to setup properly, and requires someone to manually enter the key after a reboot. Regardless of which way you end up going, you also need to ensure that you use a strong algorithm and key size. If your DB gets leaked and you use a weak algorithm or key the attacker could just brute-force decrypt the data given a bit of time.