Jump to content

cags

Staff Alumni
  • Posts

    3,217
  • Joined

  • Last visited

Everything posted by cags

  1. As I said you have 5 columns, but your only inserting 4 with your INSERT code. I'm assuming your `id` field is set to auto increment, so you don't need to explicitly insert it. If you are not inserting a value for every field you do need to inform MySQL which columns your updating. Hence the code I suggested. As far as putting the file in a folder, yes, definately the right thing to do. If you need to match it up with who uploaded it, You'd track it using a table in your database. Without knowing full project details it's hard to know the exact format. But you could have a table for users (which stores id, username, etc, etc) and a column for uploads which would have (id, uploader_id, file_uri). It all depends what your going for.
  2. Your problem is quite probably caused by backticks and a single quotes. You have... <?php $sql="INSERT INTO opportunities (opp_title, opp_link, opp_desc) VALUES(".$item['`title`']."`, `".$item['`link`']."`, `".$item['`description`']." ) "; ?> Try this... <?php $sql="INSERT INTO `opportunities` (`opp_title`, `opp_link`, `opp_desc`) VALUES('".$item['title']."', '".$item['link']."', '".$item['description']."') "; ?> Fieldnames can be surrounded by back ticks (it's not required but makes code easier to read), any value being entered into a database (unless it's an Integer) must be surrounded by single quote marks. To access a key in an array you should include single quotes (or double quotes, but unless your using a $variable your better sticking to single).
  3. That would be counter intuitive. The objective is to have a single rewrite rule that will pass the information to a PHP file. That PHP file will then dynamically do all the work. So once the htaccess file is created it shouldn't need editing. I wrote a fairly simplified tutorial on this sort of thing which you can view here, hopefully you'll find it usefull.
  4. No we mean your passing the mail function lots of different $variables that aren't applicable to it. PFMaBiSmAd has helpfully linked to the official documentation explaining all this. But as a simple breakdown, in it's simplest format the mail function should be of this format.... mail ( string $to , string $subject , string $message) I.e. in laymans terms, you must pass it a target email address, a subject and an actually message to send.
  5. You can't pass completely random information to the mail function and expect it to know what to do with it. You mail call should be of the form... <?php mail('liam@reloaddesign.co.uk', 'A Subject', $message); ?> Where $message is the string you created a few posts back. There is an optional 4th parameter but I recommend you ignore that untill you get everything else working. I suspect that the validation your doing on your form doesn't quite work exactly as you planned also, but thats another matter.
  6. If you have changed values inside the php.ini file you will need to restart Apache to get them to take effect. As you left the URL of your site in your image I took a look at the page, there is still code inside <? ?> short_code_tags, and that code is just being inserted into the HTML file as text (because your server doesn't know to process them). If you view source on your site, you'll see what I mean, that PHP code should never be visible to a visitor of your site.
  7. PHP variable names are case sensitive. You are setting $submit, but checking against the value of $Submit.
  8. This may not relate directly to PHP Coding (I'm not entirely sure), I really wasn't sure where to post it, so apologies if it's in the wrong area. I recently came across the Yslow plugin for Firefox, and have been using it to check out the 'performance' of a site I've been working on. There are a few parts of this that I'm not familiar with and was hoping somebody could shine some light on the matter. Pretty much all the low scores I recieved were in the 'SERVER' tab, which makes perfect sense as they are mainly the features I'm not familiar with. Use a Content Delivery Network (CDN) I'm not sure about the details of this, I'm guessing (and hoping) that this is only really important for Large websites that may have a lot of multimedia on them? Any clarifcation would be great. Add Expires headers I'm assuming this is refering to sending a specific header for the files, which I know can be done using the header function. Like so... <?php header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); ?> But the Yslow plugin is telling me that the files it has a problem with are the css, gif and jpg files, so how do we solve the problem with this? Apache .htaccess files perhaps? Compress components with gzip Not a clue about this one, I have a feeling this is going to be an Apache issue. Configure entity tags (ETags) Again not a clue. The further through this page I got the more I feel perhaps I should of posted under Apache or something? But I'm hoping the problems can be solved with PHP so I don't have to mess with too many Apache configuration settings (due to server restrictions).
  9. Well assumably your wanting to use the values you submitted from the form. So... <?php $submit = $_POST['submit']; $name = $_POST['name']; $last name = $_POST['lastname']; ... // etc ?> I'd also personallly recommend moving the whole block contained in the following to the top... if($submit) { }
  10. EDIT: Beaten to the punch... If you know it will be unique, use LIMIT 1, so that MySQL doesn't keep looking once it's found the answer. In order to access the date you will need to use mysql_fetch_assoc or mysql_fetch_array (or similar). <?php $query = "SELECT * FROM website WHERE title = 'main-topleft' LIMIT 1"; $results = mysql_query ($query); $row = mysql_fetch_assoc($results); echo $row['field_name_here']; ?>
  11. How about if you have this... <?php $h = "localhost"; $u = "username"; $p = "password"; $connection = mysql_connect($h,$u,$p) or die("Connection"); mysql_select_db("database", $connection) or die("Database"); echo "here"; ?>
  12. What do you get if you have just this on your page? <?php $h = "localhost"; $u = "username"; $p = "password"; $connection = mysql_connect($h,$u,$p) or die(mysql_error()); mysql_select_db("database", $connection) or die(mysql_error()); echo "here"; ?>
  13. Have you got an example query string (ie what $construct looks like) and an example output thats not in the order you expect?
  14. Any specific reason your specifying a port on the hostname? When you say blank page do you mean you don't even have the word "here" appear? How come you are trying to connect twice in your code?
  15. Erm.. why not? Did you try it?
  16. Sounds like the problem is due to your table having 5 columns and your VALUES () section only having 4, this is fine, but you need to specify which columns they are. <?php mysql_query("INSERT INTO `test` (`name`, `address`, `email`, `upload`) VALUES ('$name', '$address', '$email', '$upload')"); ?>
  17. If $time2 is not an integer (which it isn't looking at your error message) then it should have single quotes around it. <?php $query5= mysql_query("UPDATE castack SET recent='$time2' WHERE name='$stackname'")or die (mysql_error()); ?>
  18. You don't show any output code in the first example. Are you sure your not outputting a space accidently before the variable?
  19. Do you get an error message displayed, or does it just fail to insert into the db? Is the name of the table in your database test? How many columns are their in test, what are the column types? I highly recommend you edit that last post ASAP and remove your details from mysql_connect() and mysql_select_db
  20. It's quite difficult to see exactly what your objective is. To my knowledge, the only real requirement is that the opening curly bracket and the closing curly bracket of a language construct are in the same file. So you could possibly do something like this... File1.php <? for($i = 1; $i < 10; $i++){ include('File2.php'); } ?> But I'm assuming your saying that in your case this isn't suitable? File2.php echo $i; // or whatever code you want here
  21. At what point in your code are you setting the variables $submit, $name, $lastname, $email, $id?
  22. Yer, most of the nodes in RSS are not required, I found this out when making a dynamic RSS generator and was checking out the specs for RSS 2.0. Is your SQL still the same as it was before? You have 16 entries in both columns and your VALUES sections. So you shouldn't get that error...
  23. If it's xampp, in the xampp/php/php.ini file there is an option called short_open_tag, if that is set to Off your code will cause troubles, you can either change the property in the php.ini file to On. Or alternatively best practice would be to replace all <? with <?php (which I think you've already done), but another short tag style your using is <?= $whatever ?> you will need to change all instances like that to <?php echo $whatever; ?> (don't forget the semi colon).
  24. <?php if(isset($_GET['url'])) { $link = urldecode($_GET['url']); echo $link; } ?> <a href="?url=<?php echo urlencode("http://www.site.com/something-dynamic-changing-link") ?>" />Linkname</a>
  25. <?php if ( isset($_POST['validation']) ) { ?> This code checks if the $_POST array contains an element with the associative id of 'validation'. <?php if ( $_POST['validation'] ) { ?> This code checks if the value of $_POST['validation'] is equal to TRUE or FALSE. Because of the 'easy going nature' of PHP, if you make a boolean comparison of any variable (ie check if it is TRUE of FALSE), it will always return TRUE if it has a value and that value doesn't explicitly equal FALSE (ie 0). Otherwise it will return FALSE. As stated in my previous post, if 0 is ever an acceptable value and you don't use the isset() method, you can end up with a different result to what you wanted. As such you should alway use isset() for this type of check.
×
×
  • 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.