Jump to content

JD*

Members
  • Posts

    230
  • Joined

  • Last visited

Everything posted by JD*

  1. So you want to have the literal words in there? Use the html characters instead <?php $edit_content_de = "<textarea>Text</textarea>asd"; ?> <p><?php echo '<textarea name="content" id="codeTextarea" style="width:90%; height:500px;">'.$edit_content_de.'</textarea>'; ?></p>
  2. Thanks for all of the helpful answers. I guess that I'm going to go with my first instinct to make my own class that wraps around the existing functions. This way I can sell it as "Hey, just replace mysql_num_rows with $db->num_rows() and we'll never have to update that line again, we just make sure the num_rows function inside of db.php returns what we want." As for using an existing product, I would love to, but this place has gotten burned one too many times by adopting frameworks that have suddenly gone out of style. It's like a Murphy's Law thing: once they adopt it, the project implodes, so we don't want to jinx it.
  3. Hello all, I am trying to make a determination about the best way to move forward with my database code for both personal projects and for the company I work for. For my own projects, I used to use mysql functions but have started to switch over to PDO. The company I work for is still using mysql functions and they are a bit wary about switching over to either mysqli or pdo, as they have a lot of code to go through and they don't want to make a bad decision. So I started working on a database class that would replicate all of the mysql functions they were used to (fetch_assoc, fetch_array, num_rows, etc) and decided to make it so that, via a config, you could use mysqli OR pdo and then, in each function, it would do it's best to get the expected result. This way, the code for the company would only ever have to do something like: $db->query($sql); if($db->num_rows() > 0) etc... But the more I read up on PDO (which I have been using in a more proceedural way), it seems like this is already a wrapper, so in effect I'm wrapping a wrapper. So, bottom line, what are others doing to future proff their database code? I like the idea of a class with generic function names, because if there is ever another style to use (mysqlii?) we can just write up the proper functions inside of the existing class and they'll work without a hitch. But is this something that pdo already delivers? I know it's good for dealing with multiple types of databases (mysql, mssql, oracle) but this company will only ever be working with mysql, so I don't have to go overboard with considerations for that. Thanks for any help/advice! JD
  4. Just to tack on, make sure that you escape anything that comes from a user/form or else you'll get an SQL injection attack $varAssign = mysqli_real_escape_string($_POST['formAssign1']); $varDue = mysqli_real_escape_string($_POST['formDue1']); $varLink = mysqli_real_escape_string($_POST['formLink1']); $sql = "INSERT INTO table (assign, due, link) VALUES ('$varAssign','$varDue','$varLink')";
  5. This is a bit more jquery than php, but here's what wrong. First, in your javascript, you need a closing ); and you need to pass your object inside some type of POST variable and stringify it, like this: $.post("save.inc.php", "stuff=" + JSON.stringify(jsonList), function(res) { alert(res); } ); Then, in your PHP, do the following: $array = json_decode($_POST['stuff'], TRUE); print_r($array); That should get you where you want to go
  6. I think the question is, to what end do you want to store the data? Is it for archival purposes? or is it something that is going to be added to all the time. If you're going to have different xml files for each listing, that might be fine, but you're still going to have a lot of parsing to do to get your data. As for speed, here is some reading to do: https://www.google.com/search?q=php+xml+vs+database&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a
  7. Do you want to make it automatically detect the serial number? Or is it a form that the person fills out? If it's the former, you'll need to involve some javascript. If it's the latter, you can grab the last four digits of the submitted serial number and then do a query. Try looking at substr. You can tell it to start at the strlen($serial) - 4 and then use that to query your database.
  8. It seems pretty good, but if you want to try something a little easier you can look into the phpmailer class, which allows for attachments, connection to smtp and a lot of other stuff. Check it out here: phpmailer
  9. Try this: Echo out your SQL statement to the page, then do a die(); Then execute your SQL statement directly into the database (MySQL Workbench is good for this) and see if you get the error there. ////////////////////////////////////Check Phone Exist function phoneNoExist($phoneExist) { $sql = "SELECT * FROM table WHERE homenumber='".$phoneExist."'"; die($sql); $rs = executeSql($sql); if(mysql_num_rows($rs) == 1) { return true; } else { return false; } }
  10. Just to add on to Christian, you don't necessarily need to store the timestamp in a database. Since these files are created new on the server, their modify date will be the date they were uploaded. Assuming they don't change once uploaded/virus scanned/moved to download folder, you can just run a script that loops through your directory and checks that date. This can be done multiple ways, too. If you want to make it a little more universal, make a perl/cgi script or a php script and have your cron job execute that. At my last place I would run a nightly php script that would do stuff like this and I would have it email me a report of what was done. It was really easy to maintain and add on to.
  11. Are you looking to have a negative number return? If not, you may want to change the order of your equation. Here it is cleaned up a bit. Also, per Andy123, you really don't need the substring calls, and you should have your numbers as numbers, without quotes: $deposit = 300; $full_price = 1000; $extra_cost = 10; $remaining_balance = ($full_price - $deposit) + $extra_cost; echo $remaining_balance;
  12. Do you want your program to automatically create thumbnails from your original image? Is this a one-time only thing, or will you be uploading pictures via a page and need it to automatically do this?
  13. If you don't want the page to reload, you'll need to use some javascript to make an ajax request. It would go something like this: On click, make an ajax request to a php file with the "href" of the link In the PHP file, open the requested file and read the contents. Return the requested array, which the ajax handler will be listening for Update the text area with the return. Sound like what you're looking for?
  14. Ok, so it looks like your variables are empty. Can you post the rest of your code?
  15. Ok, so your next step(s) is to put in a die() ( like die("Got Here"); ) statement in side your post block and make sure that your code is being executed properly. If everything is looking good, echo out your sql query and make sure that it's set up properly: die($sql1); The die statement prevents the rest of the page from finishing and helps you track down what's going on.
  16. Put this on the line above your mysql query: die('INSERT INTO `'. $db .'`.`votes` (`ip`, `serverId`, `ownerId`, `date`) VALUES ('. $ip .', '. $serverId .', '. $ownerId .', now())'); And then reload the page. It should print out your query with the variables replaced with their values and you can see what looks incorrect, or post the results here and we'll take a look
  17. Also, from the code above, you're executing a SQL statement, but not doing anything with the results. Try putting in a looping condition like this (After your current last line): for($i=0; $i < mysql_num_rows($result); $i++) { echo 'row '.$i.': '.mysql_result($result, $i, "FIELD_NAME").'<br />'; } Just replace the FIELD_NAME with the name of a field from your database
  18. What kind of notifications? Are you talking a pop-up (like the You've Got Mail type) or just regular messages?
  19. http://apiwiki.twitter.com/w/page/22554755/Twitter-REST-API-Method:-users%C2%A0show
  20. Try starting here: http://www.phpfreaks.com/tutorial/php-basic-database-handling
  21. You cannot do anything with the header once you echo text out to the page (IE all of your form code) Put all of your if($_POST)... code at the top of your page and you should be fine
  22. Hey everyone, mod_rewrite is definitely something I am very weak with, so I'm hoping someone here can help me. What I'm trying to do on my test site (test.site.com:81) is rewrite anything with a ?, so http://test.site.com:81/?latest should rewrite to http://test.site.com:81/index.php?action=latest I thought I had it working, but I don't get the correct rewrite and now I'm seeing error in my log for my /javascript directory, my /includes, my /images, etc, so I'm not sure if it's my programming or if it's my rewrite. here is my current rewrite code: RewriteEngine On RewriteRule ^\?([^/]*)$ /index.php?action=$1 [L] Any help would be greatly appreciated
  23. Hi, and welcome to programming in PHP. You're going to want to do something more like this: <html> <body> <?php $characters = array('Peter'=>32,'Quagmire'=>30,'Joe'=>34); $rand_character = array_rand($characters); echo "$rand_character is $characters[$rand_character] years old"; ?> </body> </html>
  24. You could also use javascript to do this: http://www.w3schools.com/js/js_browser.asp
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.