kratsg
-
Posts
898 -
Joined
-
Last visited
Never
Posts posted by kratsg
-
-
Hey,
I'm having an issue with using Wikipedia's OpenSearch API - it sometimes gives me characters in a unicode format: "\u00f1" and I would like to convert back into a correctly displayed format (in this case, n-tilde; spanish n).
Any suggestions?
-
If you know it is the form of an array, might as well use the empty() function.
if(empty($_POST['menuitem']) && is_array($_POST['menuitem']))
-
I like to point out the function of "foreach" from php.net/foreach
"Unless the array is referenced, foreach operates on a copy of the specified array and not the array itself. foreach has some side effects on the array pointer. Don't rely on the array pointer during or after the foreach without resetting it. "
IE: you'll want to pass by reference if you wish to change the original array.
Edit: It might help to notice that your echo statement is WITHIN a foreach loop (so it references the copy of the array). You should be able to fix this by changing the one line:
foreach ($siteList as $sitePrefix => &$siteAttributes) {
This should pass the reference of siteAttributes without making a copy.
-
Thanks Thorpe.
In retrospect, that seemed fairly stupid of me. "Only" mysql had to have the 'real' part.
-
Let me better phrase this question...
Let's say I focus on some of the more commonly used functions in mysql:
mysql_connect, mysql_select_db, mysql_query, mysql_fetch_result/array, mysql_real_escape_string, mysql_free_result...
It appears that almost all of these exist, except for the "pg"_real_escape_string. Is there a replacement for this or a way to prevent SQL Injection similarly with postgres?
-
Hey guys,
This is probably the best board I can seem to find for this question. Given the whole slew of mysql_xxxxx() functions, can I replace "mysql" with "pg" and expect it to work properly with a Postgres DB?
~kratsg
-
Hey,
So I've tried moving the files into the same directory and still can't get it to work. I'm completely baffled.
-
Hey Guys,
I'm having a problem with a really basic script... it's so basic that I can't imagine what's going wrong at all:
$filename = "ip.address"; chdir('../'); $file = fopen($filename,"a+");
The directory looks something like this:
-svn/
-public/
--ip.address
--html/
---MYPHPSCRIPT.php
I use the chdir('../') to go up one directory (into public/ directory). Inside that is a file called ip.address. Now, I can't even open that file (I can obviously read it as file_get_contents works but I can't write to it).
Going with file permissions - I set it to 0777 for the file and it still doesn't work. I'm at a loss.
Edit: To clarify, it gives me a "Permission denied in (this php script file) error.
Edit 2: allow_url_fopen is set to on for both Global and Local
-
Hey,
I don't particularly have a problem. It was just interesting when I dumped the object to see exactly what happened with the stored values (since I did use a join) and I was wondering if the periods also carried over in the property names:
$statement_paginate = "SELECT perms.pid, perms.description, user_perms.expires FROM perms, user_perms WHERE user_perms.fk_uid = '$user_id' AND perms.pid = user_perms.fk_pid ORDER BY perms.pid ASC";
They appear not to. No problem here.
Thanks!
-
Just a quick question for anyone who knows:
Does mysql_fetch_*****() always return values from the database in the form of strings (regardless of what data type it is set in the database?)
The reason I ask is I did something like the following:
while($row = mysql_fetch_object($curr_data)){ var_dump($row); //.... //.... }
Which outputted
object(stdClass)#1 (3) { ["pid"]=> string(1) "1" ["description"]=> string(35) "Allows user to view survey results." ["expires"]=> string(1) "0" }
Now, 'pid' and 'expires' are both set as integers in the database. There's nothing wrong with the values, but rather the type of values they are.
~kratsg.
-
Can you do the following? After the appropriate variable, write
var_dump($friend_statuses)
Copy and paste the query that is outputted on the page, go to phpMyAdmin (or whatever you have), run the query, and view the outputted results.
-
Put single quotes around $phone:
$sql = "INSERT INTO $database.`service` (`customer_no`, `serial`, `phone`) VALUES ($customer_no, $serial, '$phone')";
-
My initial guess is this portion:
preg_match_all("/(?:[^\\]|^)(?:\[link:([a-zA-Z0-9=,]*)\])/",stripslashes($_GET['d']),$matches);
I believe you need 3 or 4 backslashes (I saw this before) to get a literal backslash. Let me find that post. Edit: Here it is
http://www.phpfreaks.com/forums/index.php/topic,301552.msg1427102.html#msg1427102
It's not a bug, you firstly need to account for what PHP thinks is an backslash escape sequence, you then need to account for what PCRE considers an escape sequence. You are using a double quote inside a double quoted string, thus meaning it needs to be escaped, there's one backslash. You then wish to match a backslash in your input string. In order to do this let's say we place a single quote in the string. PHP will see this as escaping the backslash which is supposed to be escaping the double quote, thus you need to escape it to prevent that happening. At this point we have 3 backslashes in our patterns. Out of these 3 only one will survive the PHP interpolation. Meaning the Regex pattern contains a single slash. The PCRE engine will assume this backslash is an escape sequence. In order to counter that we need to make sure 2 make it through the the PCRE engine, the only way to do this is add another 2 into the string. That's 5 backslashes.
-
The JavaScript help section.
-
Well, while this "isn't" the board for it... here's a shot...
You can create two checkbox groups and show one or the other:
<script type='text/javascript'> function getCheckboxes(target){ var x = document.getElementsByClassName("checkboxes"); for(i=0;i<x.length;i++){ if(x[i].getAttribute('rel') == target){ x[i].style.display = 'inline'; } else { x[i].style.display = 'none'; } } } </script> <a href="#" onclick="getCheckboxes('patent');return false;">Patents</a> | <a href="#" onclick="getCheckboxes('manufacturer');return false;">Manufacturer</a> <form name="some_form"> <input type="checkbox" class="checkboxes" rel="patent" value="1" /> <input type="checkbox" class="checkboxes" rel="patent" value="2" /> <input type="checkbox" class="checkboxes" rel="patent" value="3" /> <input type="checkbox" class="checkboxes" rel="patent" value="4" /> <input type="checkbox" class="checkboxes" rel="patent" value="5" /> <input type="checkbox" class="checkboxes" rel="manufacturer" value="1" /> <input type="checkbox" class="checkboxes" rel="manufacturer" value="2" /> <input type="checkbox" class="checkboxes" rel="manufacturer" value="3" /> <input type="checkbox" class="checkboxes" rel="manufacturer" value="4" /> <input type="checkbox" class="checkboxes" rel="manufacturer" value="5" /> </form> <script type='text/javascript'> getCheckboxes("patent"); </script>
Edit: Two typos, the above code works perfectly now.
-
It sounds to me like you want to use JavaScript+AJAX(for calling the checkboxes dynamically).
-
Actually, you don't need to check if it's set if you're only looking for ONE specific value of it...
<form action="calculator.php" method="post"> <p>Quantity: <select name="quantity"> <option value= "100" <?php echo ($_POST['quantity'] == 100)?'selected="selected"':''; ?>>100</option> <option value= "250" <?php echo ($_POST['quantity'] == 250)?'selected="selected"':''; ?>>250</option> <option value= "500" <?php echo ($_POST['quantity'] == 500)?'selected="selected"':''; ?>>500</option> </select> </p> <p>Double sided <INPUT TYPE="radio" NAME="q1" VALUE="yes"> Single Sided <INPUT TYPE="radio" NAME="q1" VALUE="no"> <p>Total: £<?php echo $sum?></p> <p><input type="submit" name="submit" value="Calculate!" /></p> <input type="hidden" name="submitted" value="TRUE" /> </form>
Or better yet, if there's a lot of values:
<form action="calculator.php" method="post"> <p>Quantity: <select name="quantity"> <?php $possible_vals = array(100,250,500); foreach($possible_vals as $value){ echo "<option value= '$value'"; if($value == $_POST['quantity']){ echo ' selected=\'selected\''; } echo ">$value</option>"; } ?> </select> </p> <p>Double sided <INPUT TYPE="radio" NAME="q1" VALUE="yes"> Single Sided <INPUT TYPE="radio" NAME="q1" VALUE="no"> <p>Total: £<?php echo $sum?></p> <p><input type="submit" name="submit" value="Calculate!" /></p> <input type="hidden" name="submitted" value="TRUE" /> </form>
-
There are two ways:
1.) Just retrieve your own status regardless and just add that to the list.
2.) Re-write the query to be something like...
$friend_statuses = "SELECT status.*, friends2.user1 FROM status, friends2 WHERE status.byuser IN (friends2.user1,'myself') AND friends2.user2='$username' ORDER BY status.dtime DESC";
-
PHP.net:
ob_start — Turn on output buffering
Report a bug
Description
bool ob_start ([ callback $output_callback [, int $chunk_size [, bool $erase ]]] )
This function will turn output buffering on. While output buffering is active no output is sent from the script (other than headers), instead the output is stored in an internal buffer.
-
And example of a join query:
$friend_statuses = "SELECT status.*, friends2.user1 FROM status, friends2 WHERE byuser=user1 AND user2='$username' ORDER BY status.dtime DESC";
-
He's going to need quotes for states like "New York" that have a space in them. Here's the appropriate query:
<?php $query = "SELECT * FROM `table_suburbs` WHERE `state`='$state' "; if(mysql_num_rows($query)==0){ die('No results returned!'); } echo "<table><tr><td>Suburb</td><td># Nurses</td><td>Suburb</td><td># Nurses</td></tr>"; $i = 0;//indexing variable while($row = mysql_fetch_array($query)){ if($i%2){echo "</tr>";}else{echo "<tr>";} echo "<td>{$row['suburb']}</td><td>{$row['nurses']}</td>"; $i++; } if($i%2){echo "<td> </td><td> </td>";} echo "</tr></table>"; ?>
I have an indexing variable which keeps track of which column you are in (left column = even; $i%2=0.... right column = odd; $i%2=1). See if it makes sense?
No qutoes!
select * from table_suburbs where state=ohio
You can do this by putting foreach in foreach. Please explain it so it would be understandable, I don't get what do you want.
-
At the very top of the page, place
<?php session_start(); require_once('connectvars.php'); //... //... ?>
-
For XSS, the htmlentities() function should do the trick.
-
http://www.javascript-coder.com/window-popup/javascript-window-open.phtml
Change Height and Width by: (example)
window.open ("http://www.javascript-coder.com", "mywindow","menubar=1,resizable=1,width=350,height=250");
To get height and width of image, you can use the getimagesize() function in PHP:
PHP Character Coding
in PHP Coding Help
Posted
So, i guess nobody knows? That sucks.