variable not defined.

 

Results 1 to 7 of 7
I found a tutorial that I was messing around with while trying to learn php ...
  1. #1
    captchadreams's Avatar
    captchadreams is offline Regular Member
    Join Date
    Sep 2008
    Posts
    489
    Thanks
    320
    Thanked 123 Times in 92 Posts

    Default variable not defined.

    I found a tutorial that I was messing around with while trying to learn php and mysql and I've received an error on the last part of the script where it's suppose to update some table data. The error said that the variable wasn't defined.. when looking at the last script file.. it looks like he really didn't define the variable in his tutorial.. but I'm also new and could be wrong.

    here it is:
    Code:
    <?php
    $host="localhost"; // Host name 
    $username=""; // Mysql username 
    $password=""; // Mysql password 
    $db_name="test"; // Database name 
    $tbl_name="test_mysql"; // Table name 
    
    // Connect to server and select database.
    mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
    mysql_select_db("$db_name")or die("cannot select DB");
    
    // update data in mysql database 
    $sql="UPDATE $tbl_name SET name='$name', lastname='$lastname', email='$email' WHERE id='$id'";
    $result=mysql_query($sql);
    
    // if successfully updated. 
    if($result){
    echo "Successful";
    echo "<BR>";
    echo "<a href='list_records.php'>View result</a>";
    }
    
    else {
    echo "ERROR";
    }
    
    ?>
    this is the part where I get the error from: $sql="UPDATE $tbl_name SET name='$name', lastname='$lastname', email='$email' WHERE id='$id'";

    I'm wondering if someone can take a look at this tutorial and see if he actually didn't define the variable himself.

    http://www.phpeasystep.com/mysql/9.html

    if so.. if anyone would be willing to rewrite the end of that code for me, it would be much appreciated.




  2. #2
    captchadreams's Avatar
    captchadreams is offline Regular Member
    Join Date
    Sep 2008
    Posts
    489
    Thanks
    320
    Thanked 123 Times in 92 Posts

    Default Re: variable not defined.

    nevermind I figured it out.. I looked up the right way to send variables via post method and just created the variables at the beginning of the code.

    $id=$_POST["id"];

    etc

  3. #3
    Zapdos's Avatar
    Zapdos is offline Power Member
    Join Date
    Oct 2011
    Location
    Eastern North Carolina
    Posts
    596
    Thanks
    78
    Thanked 688 Times in 411 Posts

    Default Re: variable not defined.

    Two things:

    1) Do not use MySQL queries like that otherwise you should expect someone to delete or modify your database. Also, it's going to be removed in the next PHP version. Look at using phps MySQLI interface and prepared statements. Tons more secure.
    2) Consider trying to put the actual image of Ducreux in your sig. Lulz to be had.

  4. The Following User Says Thank You to Zapdos For This Useful Post:

    captchadreams (01-11-2013)

  5. #4
    captchadreams's Avatar
    captchadreams is offline Regular Member
    Join Date
    Sep 2008
    Posts
    489
    Thanks
    320
    Thanked 123 Times in 92 Posts

    Default Re: variable not defined.

    Yeah I've noticed a lot of the tutorials I attempt searching on google and finding seem to be outdated.. which is very frustrating. I've been looking at random courses online like (udemy.com). I want to learn PHP/MySQL and gain a better understanding of HTML/CSS. I'm wondering if you or anyone else has any suggestions of where I could learn this online. Through courses/tutorials/etc.

    2) lol.. yeah, that meme is great.. but I hate large sigs.

  6. #5
    Zapdos's Avatar
    Zapdos is offline Power Member
    Join Date
    Oct 2011
    Location
    Eastern North Carolina
    Posts
    596
    Thanks
    78
    Thanked 688 Times in 411 Posts

    Default Re: variable not defined.

    nettuts+ is a decent place to learn. Tutorials on many different things.

    Usually if I need to brush up on something I just google for it and do the first page of results. But the best way to learn is to do. Decide on a project and make it. Then once you're done do another or redo it again with better methods. Once you think you're good enough you can do work on open source platforms (ex: SMF, vbulletin, wordpress, joomla, prestashop, opencart) and release mods for it for review.

  7. The Following 2 Users Say Thank You to Zapdos For This Useful Post:

    captchadreams (01-11-2013), gheli (01-11-2013)

  8. #6
    alias_unknown is offline Newbies
    Join Date
    Dec 2012
    Posts
    40
    Thanks
    3
    Thanked 4 Times in 4 Posts

    Default Re: variable not defined.

    Yes if working with databases in PHP, it's now best practice to use PDO, otherwise you risk SQL injection.

    When looking for PHP tutorials, search in Google and then use an advanced search to show recent pages, his way you can find tutorials that are up to date and use the latest practices.

  9. The Following User Says Thank You to alias_unknown For This Useful Post:

    captchadreams (01-11-2013)

  10. #7
    digitaluser is offline Junior Member
    Join Date
    Apr 2012
    Posts
    116
    Thanks
    1
    Thanked 2 Times in 2 Posts

    Default Re: variable not defined.

    You can use even isset function to check whether variable is set or not it might be help you to get better idea of the variable values


Similar Threads

  1. Blogging Terms and Phrases Defined for Newbies
    By Diamond Damien in forum White Hat SEO
    Replies: 23
    Last Post: 08-19-2013, 02:57 PM
  2. Scraping Defined
    By deezydiamonds in forum Black Hat SEO
    Replies: 0
    Last Post: 12-03-2010, 10:10 AM
  3. 13 Components That Defined a Great Website... in 1998
    By tacopalypse in forum BlackHat Lounge
    Replies: 19
    Last Post: 05-17-2010, 04:39 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




BlackHatWorld on Twitter BlackHatWorld on FaceBook


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108