Jump to content

Mr_CHISOL

Members
  • Posts

    404
  • Joined

  • Last visited

Everything posted by Mr_CHISOL

  1. Hi!What code do you have that handles the "call" (updates the db)?You need something that updates the info in the database using an UPDATE-statement.smething like this: if (isset($_GET['a'])) { if ($_GET['a'] == 'approve_listing') { $SQL = 'UPDATE table SET approved = 1 WHERE id='.$_GET['lid']: } else if ($_GET['a'] == 'deny_listing') { $SQL = 'DELETE * FROM table WHERE id='.$_GET['lid']: } else exit(); mysql_query( $SQL ) or die('Error: '.mysql_error() );} Hope that helped.Good Luck and Don't Panic!
  2. This is a long shot, and it's getting late but try the following:View the source of the site in the browser (i.e. Ctrl+U in FF)Change <?PHP (uppercase) to <?php (lowercase)That's all for now, and to all a good night... :?)
  3. Well, you can't expect perfect code at 00.20 in the morning... :?)
  4. In PHP now() is called date() (which take's a formatstring) or time() which returns the current UNIX timestamp.But in SQL you have a function called NOW() that you can use.try $q = "select sum(in) as tin, sum(out) as tout from traffic where listing_id = ".$row['id']. " and date + interval ".$settings['traffic_count_days']. " day > NOW()"; wrote now() in uppercase to let it stand out... Moved the quot from before now() to after...Good Luck and Don't Panic!
  5. Hi!You could use explode() (or split() if you want regular expessions), which splits the string into an array, and then add the info into an db.Example: // Connecting, selecting database$link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password') or die('Could not connect: ' . mysql_error());mysql_select_db('my_database') or die('Could not select database');$text = file_get_contents( 'file.txt' );$info = explode( ',', $text );// Performing SQL query$query = "INSERT INTO my_table (field1,field2,field3) VALUES('".$info[0]."','".$info[1]."','".$info[2]."')";mysql_query($query) or die('Query failed: ' . mysql_error());// Closing connectionmysql_close($link); If the info also is seperated by newlines (or such), you could do like this: // Connecting, selecting database$link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password') or die('Could not connect: ' . mysql_error());mysql_select_db('my_database') or die('Could not select database');$text = file_get_contents( 'file.txt' );$lines = explode( "\n", $text );foreach ( $lines as $line ) { $info = explode( ',', $line ); // Performing SQL query $query = "INSERT INTO my_table (field1,field2,field3) VALUES('".$info[0]."','".$info[1]."','".$info[2]."')"; mysql_query($query) or die('Query failed: ' . mysql_error());}// Closing connectionmysql_close($link); In the last example you could use file() instead of file_get_contents() and explode(), as file() returns an array with the lines. Please note that in the case of file() you also get the newline at the end of each line/string, which you don't get from explode.Hope that helped.Good Luck and Don't Panic!
  6. HiHere's two ways you can do this:Instead of printing them out directly, store them in an array, then make sure that the array is sorted using sort( $files ).Then, unless there's a file called site2_link.jpg or somthing like that, the filenames site2_large.jpg and site2_small.jpg lies after eachother and you can use something like this for( $i = 2; $i < count($files); $i+=2 ) { echo "<li><a href=\"/images/websites/".$files[$i+1]."\"><img src=\"/images/websites/" . $files[$i] . "\" alt=\"desription\" /></a></li>"; } Or you can check if the file contains small or large in the loop that gets the files and store them in two different arrays.For the description you can use a db (but that's not an easy way), you can use a text-file that contains each site (site1, site2 etc) on a line (or for example comma seperated) followed by the description or you can create one file for each site that has the decription. If you choose the last one you need to create a second (or third) array for those files, pref. using hash ($desc_files[$site] = $desc_file, where $site contains site1 etc) and then get the descriptions from each file using the filenames in $desc_files.Hope that helped..Good Luck and Don't Panic!
  7. Mr_CHISOL

    Php MyAdmin

    Add a echo mysql_error(); somewhere after the query and see if that gives you any info.Can't figure anything else out right now...
  8. Mr_CHISOL

    Php MyAdmin

    Hi!That code isn't correct. The squery-string isn't terminated and you need single-quotes around $strdomain as Domain and $stdomains are string.Try this code, I use mysql_num_rows to see if the query returned something.If the result is empty mysql_fetch_object() returns FALSE and then you try to get the member Domain from FALSE, which shouldn't be valid.... $strdomain = strtolower($Domain);//$Domain, user input from form$q2 = mysql_query("SELECT * FROM `Profile` WHERE `Domain` = '$strdomain'");if ((mysql_num_rows($q2) == FALSE)||(mysql_num_rows($q2) > 0)) { die('<br />This domain name entered as "'.$Domain.'" is already in our system.');} (Always use small letters in tags and end "empty tags", such as br and img, with a slash)Hope that helped!Good Luck and Don't Panic!
  9. You could use SimpleXML (http://php.net/manual/en/ref.simplexml.php) to extract the information from the structure.How exactly to do this is hard to tell without the complete structure (as it the part you gave us doesn't seam to be "alone", if it is so you need to add a root element).Here's an example using the info you gave (with a "unknown root", you don't need to know it's name using SimpleXML as this): <?php$xml = new SimpleXML( $structure ); // Can parse a string or open a file, see the manualecho '<a href="'.$xml->link.'" target="_blank">'.$xml->title.'</a>';?> to get the three first you can use a for-loop: <?php$xml = new SimpleXML( $structure ); // Can parse a string or open a file, see the manualfor ($i = 0; $i < 3; $++) { echo '<a href="'.$xml->post[$i]->link.'" target="_blank">'.$xml->post[$i]->title.'</a>';}?> This will work if the structure looks something like this (But it'snt hard to adapt to another structure) <root> <post> <title>...</title> <description>...</description> <link>...</link> </post> <post> <title>...</title> <description>...</description> <link>...</link> </post> <post>.....</root> Hope that helped.Good Luck and Don't Panic!
  10. Oh, missed the new question.It should work, it should change the value and keep it until the end of the script or the object is removed.To save it in the file you can use ->asXML (http://php.net/manual/en/function.simplexml-element-asXML.php): $xml->asXML( 'filename.xml' );
  11. Well, sorry if I hurt your feelings.. ;?)I just like to be clear in my explanations, besides it can be helpfull for some beginner...
  12. Hi!I've read an article on that subject a while ago, in a swedish magazine. But can't say I now that much about it.But I found this link (right at the top) when I googled for "php flash integration": http://www.kirupa.com/developer/actionscri...integration.htmseams to be a good article to start with..Good Luck and Don't Panic!
  13. Mr_CHISOL

    include

    There's no difference. But this looks better: include( 'somfile.php' ); There's a difference between ' and ". if you use double-quots you can include varibales dirrectly in the string and you can use espaces (\n \t etc), if you use single-quots you can't do that and you can only escape other single-quots. $Hello = 'Hey';echo '$Hello, who\tare you? I\'m called joe'; // I'm not...echo "\n"; // Added a newline...echo "$Hello, who\tare you? I'm called joe"; // I'm not...echo "\n"; // Added a newline...---This will echo:$Hello, who\tare you? I'm called joeHey, who are you? I'm called joe When it comes to the rest, I didn't follow you completely, so I can't help you with that at the moment..Hoep that helped...Good Luck and Don't Panic!
  14. Well, you learn something new every day... :?)The difference isn't that big in time any way. :?)I haven't read so much about the "internals "in PHP, used my own script-interpreter as "reference"..Thanks guy for the info.
  15. Hi!You can use it as a class/structure (as shown in the examples here: http://php.net/manual/en/ref.simplexml.php): $poster = $xml->post[0]->poster;$content = $xml->post[0]->content; If you want to display all posts you can do something like this: foreach ($xml->post as $post) { echo '<div class="post>'."\n"; echo '<p>'.$post->content."</p>\n"; echo '<span class="postedby">Posted By:<span class="name">'.$post->poster."</span></span>\n"; echo "</div>\n";} Hope that helped..Good Luck and Don't Panic!
  16. Try this instead: <?phpif (isset($_GET['view'])){ if (isset($_GET['userid'])){ include "http://www.webdkp.com/remote.php?view=" . $_REQUEST['view'] . "&id=8559&tableid=1&userid=" . $_REQUEST['userid']; } else { include "http://www.webdkp.com/remote.php?view=" . $_REQUEST['view'] . "&id=8559&tableid=1"; }}?> Added quotes in the $_GET[..] and removed a quote on the end of first include...
  17. Hi!When i have functions that I use, or may want to use, in different files I prefer to put them in a seperate file (such as functions.php), as it gets a lot easier to reuse them...To use functions to seperate for example different parts of the layout and/or data collection is a good way to get cleaner, and easier maintained, code. But be aware to not use too many functions as it then can be a nightmare to maintain...The use of functions shouldn't slow down the execution (as it's just another block of code, much like an if-statement), but what might slow things down is if you open and close the connection to the database many times (like once in every function), it's simpler and better to open the connection in the beginning of the file/script, use it in the functions and then close it...Hope that helped.Good Luck and Don't Panic!
  18. Mr_CHISOL

    Database Error

    Hi!It may simply be so that you're not allowed to create a database. Quite often it's only the root and some admin that have permission to create databases, so unless you are an admin/root (which shouldn't be used for websites, only maintenance) you can't create a new table, and in most cases you don' t need to. It's sufficiant to just create new tables...Good Luck and Don't Panic!Edit:Ok, guy was a bit faster.. :?)ps use the (without spaces), to display your code, it becomes more readable... ds
  19. Forgot of that function...But instead of using 0777 (full permission to all) I would recommend 0775 (only read and execute to others, and read, write and execute to group and owner [you]). Use the chgrp to change the group <?phpchgrp( 'upload/', 'www-data' );chmod( 'upload/', 0775 );?> PLEASE Note that this is the most "secure" way, but it may not work (Only the superuser may change the group of a file arbitrarily; other users may change the group of a file to any group of which that user is a member.)...
  20. Hi!You have just put the var. names in a string so PHP ignores them, and treats them simply as a string (that sounded fuzzy), so the output will look like this: <img src=" $base_img_dir . "{$row[image]}" " /> There are two ways to do what you want:Use single quotes and "concat" the string: echo '<img src="' . $base_img_dir . $row[image].'" />'; // No need for the curly brackets Or you can use double quotes (which I don't prefer in this case): echo "<img src=\"$base_img_dir{$row[image]}\ " />"; Here we could put the variables directly in the string, but we neede to escape the quotes (\")..Hope that helped.Good Luck and Don't Panic!
  21. The folder exists, but what's wron is stated quite clear in the error: "Permission denied".Simply you (or more correct php/the server) hasn't permission to write in that dir.I guess you have "shell-access" (judging from the path), so login (via SSH) or open a terminal and write this: chmod -R g+w ~/public_htmlchgrp -R www-data ~/public_html If it's on your computer you may do this thru the gui (the file-explorer such as nautilus), but then you may loose the recursive feature and need to do it on the sub-dirs (upload etc) as well..If you don't have shell-access if it's at an commercial host you may be able to it thru a control panel or FTP.If none of the above works you need to contact the host to let them do it, but the user/group www-data (or the one php is run as) needs write permission in the directory.Hope that helped.Good Luck and Don't Panic!
  22. Mr_CHISOL

    Forms

    But you don't need a button, you can use onchange="document.forms[0].submit()" on the first selection-list (I think that's the right JS..)
  23. Mr_CHISOL

    Php help

    Hi!You can use preg_replace, which uses regular expressions (perl style) for that: $patterns = array( '/(http[s]?:\/\/[^\s,]*)/' );$replaces = array( '[ Code]$1[/Code ]' );// Replace in $txt$txt = preg_replace( $patterns, $replaces, $txt );[/code]The code above will replace all links with [ Code]link[/ Code] in the variable $txt, it will replace both http://url.com and https://url.com.The first array contains the patterns to look for (starts with http:// or https:// and then goes one to next space or comma) and the second array contains what the patterns should be replace with. The $1 means that the link found (the pattern between the first parantheses) should be inserted there.You can easily expand the code by adding patterns and "replace text" to the arrays.Hope that helped!Good Luck and Don't Panic
  24. Mr_CHISOL

    Forms

    Hi!Please note that mailto: in an action doesn't always work (i.e. the visitor may use a public computer, or only use webmail and has not configured a mail-client to send mail...), a better solution would be to send it to a php-script that sends the mail instead.Information about the mail function can be found here: http://php.net/manual/en/function.mail.phpThe script that sends the mail could look something like this: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>CompuDeal</title></head><body> <h1>CompuDeal</h1> <p />Welcome to CompuDeal! Please fill out the form below to order a computer product. Our form is simple and fool proof to use. <?php if ($_POST["selectbox1"] != "") $action = "mailingscript.php'"; else $action= $_SERVER['PHP_SELF']; ?> <form action="<?php ehco $action ?> method='POST'> <br />Computer: <select name="selectbox1" id="selectbox1" onchange="document.getElementById('selectbox2').selectedIndex='0'"> <option value='c1'>PC</option> <option value='c2'>Notebook</option> <option value='c3'>Workstation</option> </select> <br />Speed: <select name='selectbox2' id='selectbox2'> <?php $a188 = 'AMD Athlon 1.88GHz'; $a200 = 'AMD Athlon 2.00GHz'; $t220 = 'AMD Turion 2.20GHz'; $o188 = 'AMD Opteron 1.88GHz'; $o200 = 'AMD Opteron 2.00GHz'; if(isset($_POST["selectbox1"])) { echo "<option value=''>Speed:</option>"; switch ($_POST["selectbox1"]) { case 'c1': echo "<option value='c1speed1'>", $a188, "</option>"; echo "<option value='c1speed2'>", $a200, "</option>"; echo "<option value='c1speed3'>", $t220, "</option>"; break; case 'c2': echo "<option value='c2speed1'>", $t220, "</option>"; echo "<option value='c2speed2'>", $o188, "</option>"; echo "<option value='c2speed3'>", $o200, "</option>"; break; case 'c3': echo "<option value='c3speed1'>", $t220, "</option>"; echo "<option value='c3speed2'>", $t220, "</option>"; echo "<option value='c3speed3'>", $t220, "</option>"; break; } } ?> </select> <br />Memory: <select name='memory'>"; <option value='m1'>512MB</option> <option value='m2'>1GB</option> <option value='m3'>2GB</option> </select> <br />Space: <select name='space'> <option value='h1'>80GB</option> <option value='h2'>160GB</option> <option value='h3'>320GB</option> </select><br /> Name: <input type="text" name="name" /><br /> Email: <input type="text" name="email" /><br /> Address: <input type="text" name="address" title="Street Address" /><br /> <input type="text" name="zip" title="Zip/Postal-Code" size="5" maxlength="6" /> <input type="text" name="city" title="City" /><br /> <p>All computers are fully loaded and have NVIDIA 7900 GS 256MB graphic cards.</p> <input type='submit' value='<? if(!isset($_POST["selectbox1"])) echo "Select speed"; else echo "Submit order"; ?>'> </form> </body></html> Hope that helped (There may be some error in the form-code, but I don't think so).Good Luck and Don't Panic!
  25. Sorry, to fast on the spacekey i guess... :?)
×
×
  • Create New...