premiso
Members-
Posts
6,951 -
Joined
-
Last visited
-
Days Won
2
Everything posted by premiso
-
preg_replace is much better suited for this. Just remember if any word containts the keywords, "onetime" "time" will still be bolded, if you do not like this or not want it that way let me know and I will show you the code to avoid this. <?php $_POST['search'] = "time dog"; $string = "Once upon a time there was a dog."; $words = explode(" ", $_POST['search']); foreach ($words as $word) { $string = preg_replace("~" . $word . "~i", "<strong>$0</strong>", $string); } echo $string; die(); ?>
-
[SOLVED] You have an error in your SQL syntax
premiso replied to almightyegg's topic in PHP Coding Help
It should have returned the sql statement with an error message, given that it only returned the "same" error, either means you did not make that change, save the change or upload the file with the new change. You should see something like: SQL Was: SELECT * FROM topics WHERE `pid` = '(iddata)' AND `fid` = '(fdata)' Error returned: sql error here. Given that, I do not think this is where the error is thrown either way the sql statement should be like sasa said if you have not made that change yet, do so. As for the $result3, you never posted that and you do not have an "or die(mysql_error())" so that would not throw the error, however. Try this: $sql = "SELECT * FROM topics WHERE fid = '$f' AND pinned = 'Yes' AND rid = '0' AND deleted = 'No' order by updatetimestamp desc"; $result3 = mysql_query($sql) or die("SQL Was(result3): {$sql}<br />Error returned: " . mysql_error()); And see if that returns anything. Just as a reminder the first sql posted should be: $sql = "SELECT * FROM topics WHERE `pid` = '$id' AND`fid` = '$f'"; $balala = mysql_query($sql) or die("SQL Was(balala): " . $sql . "<br />Error returned: " . mysql_error()); -
If you are not writing to the log use file then rsort to reverse the order of the array, then you can implode using "\n" at the glue and it should work fine. (Or use a foreach to display the results.
-
AJAX would be my way. Then you can use the same PHP functions when you are posting the data, redundant but if you want easy error display so they can fix it without a page reload that is the way to do it. Take a look into that, that way you code the PHP functions use AJAX to call those functions then on the posting PHP portion you can re-validate the data easily. Server load will not be an issue at all, so do not even worry about that.
-
[SOLVED] You have an error in your SQL syntax
premiso replied to almightyegg's topic in PHP Coding Help
My bet is, you have an unescaped ' in your data. Give this a try: [code=php:0]$sql = "SELECT * FROM topics WHERE `pid` = '$id',`fid` = '$f'"; $balala = mysql_query($sql) or die("SQL Was: " . $sql . "<br />Error returned: " . mysql_error()); And see what that returns.[/code] -
No, they have different session mechanics and I doubt M$ wanted to play nice with PHP. The only way that may work is doing a common DB that each side can check to verify if a user is logged in. I doubt they are on the same server, so doing this call to authenticate them for the different domain may take a couple seconds longer, but you only have to do that call each time they switch.
-
This sounds like Yahoo Q&A, this is a forum more than a Q&A. There is actually a "community" here. I think it is perfect how it is
-
imo, google phpGMailer then signup for a gmail account and use that. Much easier for testing locally. Limited to sending 100 emails per day, as a warning.
-
Yep no clue. Given that people took the time to write it, there probably is not an easier or better way, unfortunately. It would be nice if they had a toArray feature in the simplexml object, but oh well
-
"1" is not considered an int. is_int. Thus you are sent into an infinite loop. is_numeric would be a better choice, but would allow for doubles etc. You can always make the get variable an int statically. function generatecontent($var) { if(is_numeric($var)) { echo 'content generated'; $var = (int) $var; // convert it to int. } else { generatecontent(1); } } generatecontent($_GET['id']); The above may work for you, or may not. But yea. At least you now know why it was not working. (sort of). But that would also defeat the purposes of checking if it is an int, as will be converted to an int.
-
Corbin is the real reason why. If this was implemented, we would never hear the end of how great he is ^.- As for me, I am against it. People looking for the answer will read through each posts and figure it out. That or they will do like most of them do, ignore searching and just post a similar question.
-
<?php function xml2array($url, $get_attributes = 1, $priority = 'tag') { $contents = ""; if (!function_exists('xml_parser_create')) { return array (); } $parser = xml_parser_create(''); if (!($fp = @ fopen($url, 'rb'))) { return array (); } while (!feof($fp)) { $contents .= fread($fp, 8192); } fclose($fp); xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, "UTF-8"); xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); xml_parse_into_struct($parser, trim($contents), $xml_values); xml_parser_free($parser); if (!$xml_values) return; //Hmm... $xml_array = array (); $parents = array (); $opened_tags = array (); $arr = array (); $current = & $xml_array; $repeated_tag_index = array (); foreach ($xml_values as $data) { unset ($attributes, $value); extract($data); $result = array (); $attributes_data = array (); if (isset ($value)) { if ($priority == 'tag') $result = $value; else $result['value'] = $value; } if (isset ($attributes) and $get_attributes) { foreach ($attributes as $attr => $val) { if ($priority == 'tag') $attributes_data[$attr] = $val; else $result['attr'][$attr] = $val; //Set all the attributes in a array called 'attr' } } if ($type == "open") { $parent[$level -1] = & $current; if (!is_array($current) or (!in_array($tag, array_keys($current)))) { $current[$tag] = $result; if ($attributes_data) $current[$tag . '_attr'] = $attributes_data; $repeated_tag_index[$tag . '_' . $level] = 1; $current = & $current[$tag]; } else { if (isset ($current[$tag][0])) { $current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result; $repeated_tag_index[$tag . '_' . $level]++; } else { $current[$tag] = array ( $current[$tag], $result ); $repeated_tag_index[$tag . '_' . $level] = 2; if (isset ($current[$tag . '_attr'])) { $current[$tag]['0_attr'] = $current[$tag . '_attr']; unset ($current[$tag . '_attr']); } } $last_item_index = $repeated_tag_index[$tag . '_' . $level] - 1; $current = & $current[$tag][$last_item_index]; } } elseif ($type == "complete") { if (!isset ($current[$tag])) { $current[$tag] = $result; $repeated_tag_index[$tag . '_' . $level] = 1; if ($priority == 'tag' and $attributes_data) $current[$tag . '_attr'] = $attributes_data; } else { if (isset ($current[$tag][0]) and is_array($current[$tag])) { $current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result; if ($priority == 'tag' and $get_attributes and $attributes_data) { $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data; } $repeated_tag_index[$tag . '_' . $level]++; } else { $current[$tag] = array ( $current[$tag], $result ); $repeated_tag_index[$tag . '_' . $level] = 1; if ($priority == 'tag' and $get_attributes) { if (isset ($current[$tag . '_attr'])) { $current[$tag]['0_attr'] = $current[$tag . '_attr']; unset ($current[$tag . '_attr']); } if ($attributes_data) { $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data; } } $repeated_tag_index[$tag . '_' . $level]++; //0 and 1 index is already taken } } } elseif ($type == 'close') { $current = & $parent[$level -1]; } } return ($xml_array); } ?> Found at xml_parse in the user comments. Perhaps that will help you? EDIT: Also found this on the simplexml load file page: <?php function object2array($object) { $return = NULL; if(is_array($object)) { foreach($object as $key => $value) $return[$key] = object2array($value); } else { $var = get_object_vars($object); if($var) { foreach($var as $key => $value) $return[$key] = ($key && !$value) ? NULL : object2array($value); } else return $object; } return $return; } ?> http://us2.php.net/manual/en/function.simplexml-load-file.php#56691
-
parse_str "may" help given that it is a string returned
-
[SOLVED] inserting data into mysql with php
premiso replied to big-dog1965's topic in PHP Coding Help
Just fyi, mysql "should" be case insensitive on that kind of stuff -
[SOLVED] inserting data into mysql with php
premiso replied to big-dog1965's topic in PHP Coding Help
<?php echo '<p>Creating table login'; $result = mysql_query('CREATE TABLE IF NOT Exists login ( userid int(35) NOT NULL auto_increment , user_name varchar(50) NOT NULL , user_pass varchar(255) NOT NULL , user_level varchar(50) NOT NULL , `date` varchar(20) default NULL , user_email varchar(50) NOT NULL , user_ip varchar(50) NOT NULL , PRIMARY KEY (userid) )') or die(mysql_error()); echo '<p>Inserting admin data into table Login'; mysql_query("INSERT INTO Login VALUES ('','admin','21232f297a57a5a743894a0e4a801fc3','4','02-19-2009','Admin@bigtop.com','' )") or die(mysql_error()); A: mysql uses single quotes not double quotes (your query had double quotes.) B: use the die(mysql_error()) to spit out "decent" error messages upon an error (since I take it this is an install script that should be fine.). -
HTTP_POST has been depreciated use $_POST instead. On the login verification page do you set enabled to be 0? If not that is your problem. To me it does not seem like that is what you are doing. From this code, given what you stated it "should" work. But yea, without seeing where the register information is entered, it is hard to say. Also you should set member_password to be = not like, this can be a security risk/vunerability. Same with the member email.
-
What is the "actual" string that get's returned? And can you convert it to an array on your own? Show us the raw text, at least the item portion of the raw text that is returned.
-
You would just use: $contents = file_get_contents("filename.php"); echo '<textarea name=file rows=30 cols=70>' . $contents . '</textarea>';
-
MySQL has its own charset, as well as the html that may have been used to post it to. What is the charset your MySQL database is set to run?
-
foreach ($_POST as $key => $val) { echo $key . " => " . $val . "<br />"; }
-
Yes and no. You can do this with PHP but the file has to be put into a textarea on the webpage and you would have to manually copy then paste back then click "Save". If anyone else accesses this file while you are working on it, their's or your changes will be overwritten. Perhaps you are looking for a Subversion server (which you can setup for free on any windows machine and give access to anyone with username/password authentication). This keeps a log of any/all files changed and lets you know if a file was changed while you were working on it/allows you to lock that file you are working on.