Jump to content

iNko

Members
  • Posts

    49
  • Joined

  • Last visited

Posts posted by iNko

  1. There is this url - http://xkcd.com/1110/ . It has an interactive image, witch is made out of 225 other images (its very big). I want to make a php script that would download all those 225 images. For example - http://imgs.xkcd.com/clickdrag/1n8w.png. 1n8w.png is one of those images, if i write 1n9w.png it would load another image.

     

    I think i do not explain myself well enough, so i am going to post how other ppl got the images but using other method:

     

    This is what I did:

    I figured out, that the map pieces follow the URL pattern

    http://imgs.xkcd.com/clickdrag/X[n|s]Y[e|w].png,

    where n, s, e, w are characters to select the quadrant, and X and Y are positive integers (>=1) with no zero padding. The images are each 2048×2048 pixels in size and are arranged in an orthogonal grid.

    The bounds can be found in the JavaScript file http://imgs.xkcd.com/clickdrag/1110.js:

    var size=[14, 48, 25, 33];

    These are the bounds of [n, e, s, w] respectively, however, I did only find images for [13, 48, 19, 33], a little bit less in the n-s direction, but maybe I was missing something.

    I did a brute force download of all the images (sorry Randall) using simple DOS shell commands like this for the s-e-quadrant:

    FOR /L %x IN (1,1,25) DO FOR /L %y IN (1,1,48) DO wget http://imgs.xkcd.com/clickdrag/%xs%ye.png

    I got 225 files that existed, all others are completely black or white and returned a 404-Not found.

     

    I do not know what DOS shell is, or what those command lines are, i do understand what that code does tho. Is it possible to make something like this but with php?

  2. cant edit..

    SELECT Table1.sukurimo_data, Table2.issiuntimo_data, Table3.issiuntimo_data

    FROM Table1, Table2, Table3

    WHERE Table1.table_id= Table2.table_id

    OR Table1.table_id= Table3.table_id

     

    This is how its displayed to me:

    fz12qg.png

     

     

    how can i do this??

     

    Edit: also when i try this:

     

    SELECT table1.number

    FROM table1

    INNER JOIN table2 USING(id)

    INNER JOIN table3 USING(id)

     

    It returns an empty result, no errors

  3. thx for the quick reply! i tried using ur code but its not working like i wanted :(

     

    Heres a better example of what i want to get:

     

    Table1

    id number

    1 1234

    2 4321

     

    Table2

    id username

    1 random_username

     

    Table3

    id password

    2 random_password

     

    What if i want to display all the numbers from table1, where id from table1 matches id from table2 AND table3?

    if it was only 2 tables, this would work:

    SELECT number

    FROM Table1, Table2

    WHERE Table1.ID = Table2.ID

     

    im getting always getthing this error - field list is ambiguous

  4. Got these tables:

     

    Table1

    ID USER

    1 User1

    2 User2

     

    Table2

    ID CAR

    1 Car1

    2 Car2

     

    Table3

    ID STREET

    1 Street1

    2 Street2

     

    If i wanned to display USER and CAR columns from Table1 and Table2, i would write:

    SELECT USER, CAR

    FROM Table1, Table2

    WHERE Table1.ID = Table2.ID

     

    What if i wanned to add a third table (Table3), how does the code change?

    SELECT USER, CAR, STREET

    FROM Table1, Table2, Table3

    WHERE ........

  5. made it work:

    
    private void whoslogedinLabel(){
    
       try {
           String sql = "SELECT vardas_pavarde FROM Vartotojas WHERE login='" + whosloggedin + "'"; 
          pst = conn.prepareStatement(sql);
          //pst.setString(1, whosloggedin);      
          rs = pst.executeQuery(sql);
          while (rs.next())
          {
              logininfoLabel.setText(rs.getString("vardas_pavarde"));   
          }
    
    }
       catch (Exception e){
           JOptionPane.showMessageDialog(null, e);
       } 
       }
    

    thx guys

  6. Hey, i need to take just one element from my database table. I have this table - Users. and it has ID, Login, Password and Surname. I want to take just surname from this table. Something like ("Select Surname from Users where login =")

     

    Im trying to use this, but it gives me errors saying this ("Unkown column 'Admin' in 'where clause'"):

    private void whoslogedinLabel(){
       String sql = "select Surname from Users where login = Admin";
    try {
    	pst = conn.prepareStatement(sql);
    	rs = pst.executeQuery();
           logininfoLabel.setText(sql);
    }
    catch (Exception e){
    	JOptionPane.showMessageDialog(null, e);
    }
    }
    

    logininfoLabel - is the label where i want the Surname to be displayed

  7. Hello, i have a problem fetching data from database, ill try explain what i need help with..

     

    I got a login frame, that has login textfield, password textfield and a submit button.

    When i press the submit button, if the login and password was correct, it switches to new frame, the login frame disappears.

     

    In the new frame, i want to put a label, that would take 1 specific data field from the database. Something like this - "Select Surname from Users where Loginid = login".

     

    How do i take the login textfield data from login frame, and display it in the new frame?

     

    After i do this, can i create a new method in the new frame like this, and then just call it? (i took this from a tutorial where instead of updating a label, it updates the whole table)

    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    private void whoslogedinLabel(){

    String sql = "select Surname from Users where Loginid = Login texfield";

    try {

    pst = conn.prepareStatement(sql);

    rs = pst.executeQuery();

    logininfoLabel.setText(sql);

    }

    catch (Exception e){

    JOptionPane.showMessageDialog(null, e);

    }

    }

    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    highlighted the red text where i think is the problem

  8. .. Cant edit my previous post, so making new one again.....

     

    Solved the jframe thingy with by making new method in the login JFrame:

    
      public void closeLogin() {
          WindowEvent winClosingEvent = new WindowEvent(this,WindowEvent.WINDOW_CLOSING);
          Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(winClosingEvent);
      } 
    

     

    And then called this method after the login button is pressed:

    
    try {
               pst = conn.prepareStatement(sql);
               pst.setString(1, txtusername.getText());
               pst.setString(2, txtpassword.getText());
               rs = pst.executeQuery();
               if (rs.next()){
                   closeLogin();
                   QueryJFrame s = new QueryJFrame();
                   s.setVisible(true);
    
               }
    

     

    Thx guys :)

  9. Hmm idk why i cant edit my earlier post twice, so making a new post now..

     

    Ok so i managed to get what i want with the info message windows by just adding a new label field into the GUI and changing:

     

    This

    //JOptionPane.showMessageDialog(null, "Prisijungimo duomenys teisingi"); 
    

     

    Into this

    logincheckLabel.setText("Prisijungimo duomenys teisingi");
    

     

    Still cant find anything with the JFrame..

  10. To answer questions 1, 2, & 3 when you create your GUI you should be creating a separate JPanel and adding it to your JFrame. You can update them dynamically in your Listener methods. If you want specifics post your code with the main JFrame container and where these methods reside.

     

    Thx for helping, i have only 2 jframes now, ill post both of their codes because im not sure witch one is the main one

     

    This is the one that opens after succesfull login:

    public class QueryJFrame extends javax.swing.JFrame {
    
    public QueryJFrame() {
    initComponents();
    }
    @SuppressWarnings("unchecked")
    
    private void initComponents() {
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    
    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGap(0, 400, Short.MAX_VALUE)
    );
    layout.setVerticalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    .addGap(0, 300, Short.MAX_VALUE)
    );
    pack();
    }
    public static void main(String args[]) {
    
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    new QueryJFrame().setVisible(true);
    }
    });
    }
    }
    
    

     

    And this is the code from the login frame

    
    import java.sql.*;
    import javax.swing.*;
    public class loginJFrame extends javax.swing.JFrame {
    Connection conn = null;
    ResultSet rs = null;
    PreparedStatement pst = null;
    
    
    public loginJFrame() {
    initComponents();
    }
    
    @SuppressWarnings("unchecked")
    
    
    private void formWindowOpened(java.awt.event.WindowEvent evt) {
    conn = mysqlconnect.ConnectDb();
    }
    
    private void cmdloginMouseClicked(java.awt.event.MouseEvent evt) {
    // TODO add your handling code here:
    String sql = "select * from Vartotojas where login = ? and password = ?";
    try {
    pst = conn.prepareStatement(sql);
    pst.setString(1, txtusername.getText());
    pst.setString(2, txtpassword.getText());
    rs = pst.executeQuery();
    if (rs.next()){
    JOptionPane.showMessageDialog(null, "Prisijungimo duomenys teisingi");
    QueryJFrame s = new QueryJFrame();
    s.setVisible(true);
    }
    else
    JOptionPane.showMessageDialog(null, "Prisijungimo duomenys neteisingi");
    }
    catch (Exception e){
    JOptionPane.showMessageDialog(null, e);
    }
    }
    
    public static void main(String args[]) {
    try {
    for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
    if ("Nimbus".equals(info.getName())) {
    javax.swing.UIManager.setLookAndFeel(info.getClassName());
    break;
    }
    }
    } catch (ClassNotFoundException ex) {
    java.util.logging.Logger.getLogger(loginJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
    java.util.logging.Logger.getLogger(loginJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
    java.util.logging.Logger.getLogger(loginJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
    java.util.logging.Logger.getLogger(loginJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
    
    
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    new loginJFrame().setVisible(true);
    }
    
    });
    }
    
    
    private javax.swing.JButton cmdlogin;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPasswordField txtpassword;
    private javax.swing.JTextField txtusername;
    }
    
    

     

    And this is connection to database file

    
    import java.sql.*;
    import javax.swing.*;
    public class mysqlconnect {
    Connection conn = null;
    public static Connection ConnectDb() {
    try{
    Class.forName("com.mysql.jdbc.Driver");
    Connection conn = DriverManager.getConnection("jdbc:mysql://database info");
    JOptionPane.showMessageDialog(null, "Prisijungimas pavyko");
    return conn;
    }catch (Exception e) {
    JOptionPane.showMessageDialog(null, e);
    return null;
    }
    }
    }
    

     

    This is my entire code, ill go look into that JPanel attachment to JFrame thing now.

  11. Hey, im using NetBeans to make a simple GUI, that would connect to a mysql database. I followed some guides and managed to make something, but now i want to change some features and i dont know what to look for on google/youtube.. Ill try to explain what i need, maybe someone can help me with it or point me in the right direction on what i should be looking for.

     

    So, when i press 'Run Project' in NetBeans, 1st i get this:

    2zre5bq.png

    1) I would like to put that info message window, where it says that connection to database is established, somewhere in the GUI, is that possible?

     

    After i press 'OK' on the info message window, i can then input my login/password and login into the databse, heres the screen:

    2d0jkfp.png

    2) Here the info message window says that the login information is correct, again, i would like to hide this info window so that it would display somewhere in the GUI and not as a pop-up window.

     

    After i press 'OK' on the login detail window, a new 'JFrame' opens up (witch i will fill in with other things that i need later), heres the screen:

    24ci711.png

    3) The old 'Login form' window didnt dissapear, can i make it so the new 'JFrame' opens up and the login frame dissapears, or can i make it so that the new JFrame window would replace the login frame?

     

     

    Heres the code just in case:

    Settings for database, shows the 1st info message window (if connection was succesfull):

    public class mysqlconnect {
    Connection conn = null;
    public static Connection ConnectDb() {
    try{
    Class.forName("com.mysql.jdbc.Driver");
    Connection conn = DriverManager.getConnection("jdbc:mysql://Database related stuff");
    JOptionPane.showMessageDialog(null, "Prisijungimas pavyko");
    return conn;
    }catch (Exception e) {
    JOptionPane.showMessageDialog(null, e);
    return null;
    }
    }
    }
    

     

    When i click the 'Login' button in the login frame, shows if login info was correct or not, also if correct opens new JFrame:

    
    private void cmdloginMouseClicked(java.awt.event.MouseEvent evt) {
    // TODO add your handling code here:
    String sql = "select * from Vartotojas where login = ? and password = ?";
    try {
    pst = conn.prepareStatement(sql);
    pst.setString(1, txtusername.getText());
    pst.setString(2, txtpassword.getText());
    rs = pst.executeQuery();
    if (rs.next()){
    JOptionPane.showMessageDialog(null, "Prisijungimo duomenys teisingi");
    QueryJFrame s = new QueryJFrame();
    s.setVisible(true);
    }
    else
    JOptionPane.showMessageDialog(null, "Prisijungimo duomenys neteisingi");
    }
    catch (Exception e){
    JOptionPane.showMessageDialog(null, e);
    }
    }
    

    So yeah, these are my main problems at the moment, i dont really know what to type into google for help, so hoping someone here will clear things for me..

     

    Also got some side questions:

    4) After im done with this project, can i make it so it would be installable program?

    5) If i can install it, can i make it start-up automatically every time i turn on the computer? (for example, like any antivirus program or even skype)

    6) If i can install it, can it have its own icon near the clock in the bottom right corner?

     

    Thx and sorry if this was posted in the wrong seciton.

  12. Got this code:

    <label>Current date :</label>
    <input name="current_date" type="date"/>
    
    
    if(isset($_POST['submitted'])){
    $error = FALSE;
    
    
    if (empty($_POST['current_date'])) {
    $error [] = 1;
    } else {
    $current_date= $_POST['current_date'];
    }
    
    
    if (!$error) {
    $sqlinsert = "INSERT INTO Date (current_date)
    VALUES ('$current_date')";
    mysql_query($sqlinsert);
    } else {
    
    }
    }
    

     

    How do i make it so it automatically isert current date into the database?

  13. I'm guessing you want something like this:

     

    if (empty($_POST['numbers']))
    {
    $error [] = 1;
    }
    elseif(!is_numeric($_POST['numbers']))
    {
    $error[] = 2;
    }
    else
    {
    $numbers= $_POST['numbers'];
    }

     

    Thank you, this works very well.

    Also as a side question, can i make this code without the 'elseif'? Something like this:

    if ((empty($_POST['numbers'])) OR (!is_numeric($_POST['numbers']))
    {
    $error [] = 1;
    }
    else
    {
    $numbers= $_POST['numbers'];
    

     

    also 'is_numeric' is for numbers, is there a name for 'is letters'?

  14. Yesterday i got help with checking if textfield is empty, now i also need to make it so only numbers can be inserted in a specific textfield.

    Heres the code that checks if field is empty:

    
    if (empty($_POST['numbers'])) {
    $error [] = 1;
    } else {
    $numbers= $_POST['numbers'];
    }
    

     

    Can i add another IF after the ELSE in this code that checks if its numbers?

  15. Re quoting my post (idk why but i cant find the edit button anymore)

    <?php
    session_start();
    require('config.php');
    if(!isset($_SESSION['login']))
    {
    header('location: login.php');
    }
    
    if(isset($_POST['submitted'])){
    $name= $_POST['name'];
    $surname= $_POST['surname'];
    $sqlinsert = "INSERT INTO Users (name, surname) VALUES ('$name', '$surname')";
    
    if(!mysql_query($sqlinsert)) {
    die('Couldnt create user');
    }
    $newrecord = "User created";
    }
    ?>
    
    <form action="newuser.php" method="POST">
    <input type="hidden" name="submitted" value="true" />
    <label>Name</label>
    <input type="text" name="name"/>
    <label>Surname</label>
    <input type="text" name="surname"/>
    <input name="" type="submit" value="Create user">
    </form>
    
    <?php
    echo $newrecord;
    ?>
    

    i added a 2nd textfield and i also found this validation code:

    
    $username = trim($_POST['username']); // cut spaces around
    
    if(!preg_match('/ {2,}/', $username) // check for more than one space in the middle
    {
    // Show some error message...
    }
    else if(!preg_match('/^[a-z0-9_ ]+$/', $username)) // check for valid characters
    {
    // Show some error message...
    }
    else
    {
    // Username is good.
    }
    

     

    so i was thinking, can i do something like:

    $name= trim($_POST['name']);
    $surname= trim($_POST['surname']);
    
    if(!preg_match('/ {2,}/', $name || $surname)
    {
    // Show some error message...
    }
    else if(!preg_match('/^[a-z0-9_ ]+$/', $name || $surname))
    {
    // Show some error message...
    }
    else
    {
    $sqlinsert = "INSERT INTO Users (name, surname) VALUES ('$name', '$surname')";
    
    if(!mysql_query($sqlinsert)) {
    die('Couldnt create user');
    }
    $newrecord = "User created";
    }
    }
    

     

    EDIT: thx floridaflatlander, ill check ur code right now

  16. Got this code for inserting data into my database:

    <?php
    session_start();
    require('config.php');
    if(!isset($_SESSION['login']))
    {
    header('location: login.php');
    }
    
    if(isset($_POST['submitted'])){
    $name= $_POST['name'];
    $sqlinsert = "INSERT INTO Users (name) VALUES ('$name')";
    
    if(!mysql_query($sqlinsert)) {
    die('Couldnt create name');
    }
    $newrecord = "Name created";
    }
    ?>
    
    <form action="newuser.php" method="POST">
    <input type="hidden" name="submitted" value="true" />
    <label>Name</label>
    <input type="text" name="name"/>
    <input name="" type="submit" value="Create name">
    </form>
    
    <?php
    echo $newrecord;
    ?>
    

    Im thinking i need to write something like if ( $name != ''){ //insert } else { //show that field is empty }

    But what if i have multiple fields? am i going in the right dirrection with this?

  17. Hi, i want to select data from a database and that it should be displayed in a select list

     

    i have this code:

    <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td>Name :</td>
    <td>
    <?php
    $query = mysql_query("SELECT * FROM `table_name`");
    while($row = mysql_fetch_assoc($query)){
    echo $row['table_row_name'];
    }
    ?>
    </td>
    </tr>
    

     

    Now it only gets me the data from a row in a table, and writes it in one line.

    How do i make it so all the data would go into select list and i could only pick one item?

  18. Hi, i uploaded my database to a server and now im just trying to connect to it

     

    this is my config file:

    <?php
    $con = mysql_connect ("my server details", "my server details", "my server details");
    if (!$con)
    {
    die('Message if connection was bad: ' . mysql_error());
    }
    mysql_select_db("my database name");
    ?>
    

     

    And this is my login form code:

    
    <?php
    require('connectdatabase.php'); //takes config file info
    
    if(isset($_POST['submit'])) {
    $login = mysql_escape_string($_POST['login']);
    $password = mysql_escape_string($_POST['password']);
    $sql = mysql_query("SELECT * FROM `Vartotojas` WHERE `login` = '$login' AND `password` = '$password'");
    
    if(mysql_num_rows($sql) > 0){
    include('index.php');
    
    exit();
    }else{
    echo "Bad login/password";
    }
    }else{
    
    ?>
    <form action="loginform.php" method="POST">
    Login: <input type="text" name="login" /> <br/>
    Password: <input type="text" name="password" /> <br/>
    <input type="submit" name="submit" value="Login" />
    </form>
    <?php
    }
    ?>
    

     

    This code works but i dont even need to login to connect to my index.php (i mean i can just type /index.php and it will go to that page bypassing the loginform.php)

    How do i make it so i could connect to index.php only when i go through loginform.php? (Do i need to add some code in my index.php so that it would check if im logged in?)

    Also, im not sure what this part does in this code :

    "if(mysql_num_rows($sql) > 0)"

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