Jump to content

MasterACE14

Members
  • Posts

    2,687
  • Joined

  • Last visited

Posts posted by MasterACE14

  1. never mind, I figured it out.

     

    #include <iostream>
    #include <string>
    using namespace std;
    
    int main()
    {
    
    string text = "I do like the seaside";
    cout << "Original: " << text << endl;
    cout << "Last character: " << text.at( text.size() - 1 ) << endl;
    
    cout << "Last 3 characters: " << text.substr( text.size() - 3 ) << endl;
    
    system("pause");
    return 0;   
    }

  2. I'm having trouble finding the last 3 characters of a string.

     

    I have the following:

        string something;
        char result;
        string last3;
        
        
                    something = "12345";
                    result = something.length()-3;     
                    last3 = something.substr(result, 0);  
       cout << last3 << endl;

    I want it to output '345', but I'm getting '2'.

     

    Any help is appreciated, thanks.

     

    Regards,

    Ace

     

  3. a better way would be

    <?php
    include("config.php");
    $content = $_POST['content'];
    $link = $_POST['link'];
    $title = $_POST['title'];
    $pass = $_POST['password'];
    $qry = "UPDATE sites SET content = '$content', link = '$link' WHERE title='$title' and password='$pass'";
    mysql_query($qry) or die (mysql_error());
    echo "Site Updated";
    mysql_close($con);
    ?> 

    with correct validation and filtering on those POST's of course.

  4. you could append time() to it, that's the easiest solution I can think of in the moment.

     

    Or the other way of going about this would be to check the file names of what you're uploading against what already exists, if it already exists regenerate a new random number to append to it and run the check again, keep looping until the file name isn't taken.

  5. I agree with litebearer's suggestion, your system does need to be slightly reworked.

     

    <?php
    include("config.php");
    
    mysql_query("UPDATE sites SET content = '$_POST[content]'
    WHERE title = '$_POST[title]' AND password = '$_POST[password]'");
    mysql_query("UPDATE sites SET link = '$_POST[link]'
    WHERE title = '$_POST[title]' AND password = '$_POST[password]'");
    echo "Site Updated";
    mysql_close($con);
    ?> 

    that's not a very good way to get the job done.

  6. <?php // it's best practice not to use short tags
    $qry = mysql_query(
    "SELECT * FROM tb_event ORDER BY `f_date` DESC LIMIT 1") or die(mysql_error()); // order by `f_date` or `id` in descending order, limit to 1 result
    while($res = mysql_fetch_array($qry))
    {
    if ($res[f_status] == "Published") { // changed '=' to '==', so it compares rather than assigns
    echo '
    <img src="images/uploads/'.$res[f_image].'" border="0" />
    '; 
    }
    else 
    {
    echo '
    ABCDE
    '; 
    }
    }
    ?>

  7. <?php
    include("config.php");
    
    $q = mysql_query("SELECT `title` FROM `site` WHERE `title`='".$_POST['title']."'");
    
    if(mysql_num_rows($q) == 0)
    {
    $sql="INSERT INTO sites (title, content, link, password)
    VALUES
    ('$_POST[title]','$_POST[content]','$_POST[link]','$_POST[password]')";
    if (!mysql_query($sql,$con))
    
      {
      die('Error: ' . mysql_error());
      }
    echo "Site has been registered. Please check the homepage.";
    } else {
       echo "A site with that title already exists.";
    }
    
    
    mysql_close($con)
    ?> 

     

    You need some validation and filtering, this is very insecure.

×
×
  • 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.