Jump to content

darbok

Members
  • Posts

    29
  • Joined

  • Last visited

Posts posted by darbok

  1. On 5/15/2017 at 3:32 PM, justsomeguy said:

    It's best to list the fields.  You can leave out the field list and just have the values in the insert query, but if you ever modify the table it's going to break the code.  It's always best to list out what you're doing to avoid issues like that.

    So it's best to just it up and list all the fields?

  2. On 5/11/2017 at 9:15 PM, niche said:

    The answer to your specific question is you'd use a $_GET or $_POST method.

    I think i explained myself wrong possibly. I understand about submitting to mysql from php... but from what iv'e seen you need to list all the columns in the sql tables that the info has to go in from the php form. I was wondering if there was some way to do this without having to list all 30 fields  that the php/sql connect statement has to post to individual.

  3. <?php

    $con = mysqli_connect("localhost","mark","library","markdb");


    // Check connection

    if (mysqli_connect_errno())

    {

    echo "Failed to connect to MySQL: " . mysqli_connect_error();

    }

    $sql = "INSERT INTO UserNames (FirstName, LastName)

    VALUES ('John', 'Doe')";


    if ($conn->query($sql) === TRUE) {

    echo "New record created successfully";

    } else {

    echo "Error: " . $sql . "<br>" . $conn->error;

    }


    $conn->close();



    ?>



    i have my table set to varchar (16)

  4. Looking at how form items are put into a mysql table, the part that seems daunting is if ones form has like 50 items... having to list all those IDs with their variables makes me wonder if there is a better way or if its just " it up buttercup.".

  5. "request" is not an HTTP method. GET appends data to the URL and has a size limit, POST does not put the data in the URL and can send about as much data as the server will allow.

    As far as the database is concerned, it doesn't really matter how the data got there.

     

    GET requests are usually used for reading data without changing anything on the server while POST is used to give data to the server, so for a database-driven application the most common approach is to use POST to put the data in and GET to pull the data out.

     

     

    Thank you!

  6. I'm getting a resource #4 error, not sure how to fix it, but i bet its an easy fix that i'm not seeing.

     

    <?php
    $result=mysql_query("SELECT * FROM topdata a, venuetop b, stats c, mid_data d, influence e, botdata f, accounts g WHERE (a.char_name=b.char_name) AND (b.char_name=c.char_name) AND (c.char_name=d.char_name) AND (d.char_name=e.char_name) AND (e.char_name=f.char_name) AND (f.char_name=g.log_name) AND (a.char_name="$_POST[char_name]")")
    or die ("Couldn't get character data.<br>".mysql_error()."<br>Please contact Savvannis with your login name, character name, the above error and the page address above.");
    $row=mysql_fetch_array($result);
    echo $result;
    ?>
  7. thanks for the help, much appreciated, the hints and such were a good deal. To make it work I turned it into two files, one for the form and one for the php, I also changed the SQL column names to be one word all lower case instead of two words uppercase. I also took the single quote marks out of my column names.

  8. this is the error I get now. Parse error: syntax error, unexpected ';' in C:xampphtdocspracticeformspracticeforms.php on line 24 though i think it's gotten better.

     

     

    <!doctype html>

    <html>
    <head>
    <link rel="stylesheet" href="style.css">
    <meta charset="utf-8">
    <title> My Practice Page </title>
    </head>
    <body>
    <?php
    $first_name = $_POST["firstname"];
    $last_name = $_POST["lastname"];
    $city = $_POST["city"];
    $db = MYSQLI_CONNECT('localhost','root','','practiceforms');
    if (!$db) {
    die("Connection failed: " . mysqli_connect_error());
    }
    echo 'Connected successfully';
    if(isset($_POST['first_name']) && isset($_POST['last_name']) &&(isset($_POST['city']));
    {
    $sql = "INSERT INTO users ('FIRST NAME', 'LAST NAME', 'CITY') VALUES
    ('$first_name','$last_name','$city')";
    }
    mysqli_query($db, $sql);
    mysqli_close($db);
    ?>
    <form method="post" action="">
    First Name:<br>
    <input type="text" name="firstname" value=""> <br>
    Last Name:<br>
    <input type="text" name="lastname" value =""><br>
    City:<br>
    <input type ="text" name="city" value=""> <br>
    <input type="submit" name="submit" value="submit">
    </form>
    </body>
    </html>
  9. yes I do.

     

     

    I get this error.

     

    Notice: Undefined index: first name in C:xampphtdocspracticeformspracticeforms.php on line 11Notice: Undefined index: last name in C:xampphtdocspracticeformspracticeforms.php on line 12Notice: Undefined index: city in C:xampphtdocspracticeformspracticeforms.php on line 13

  10. So, I've revised the code to this, I get no more error messages, but my input is still not going into the table.

     

     

    <!doctype html>
    <html>
    <head>
    <link rel="stylesheet" href="style.css">
    <meta charset="utf-8">
    <title> My Practice Page </title>
    </head>
    <body>
    <?php
    $first_name = $_POST['first name'];
    $last_name = $_POST['last name'];
    $city = $_POST['city'];
    $db = MYSQLI_CONNECT('localhost','root','','practiceforms');
    if (!$db) {
    die("Connection failed: " . mysqli_connect_error());
    }
    $sql = "INSERT INTO users (first name, last name, city) VALUES ('$first_name','$last_name','$city')";
    mysqli_query($db, $sql);
    mysqli_close($db);
    ?>
    <form method="post" action="">
    First Name:<br>
    <input type="text" name="First Name" value=""> <br>
    Last Name:<br>
    <input type="text" name="Last Name" value =""><br>
    City:<br>
    <input type ="text" name="city" value=""> <br>
    <input type="submit" name="submit" value="submit">
    </body>
    </html>
  11. <!doctype html>
    <html>
    <head>
    <link rel="stylesheet" href="style.css">
    <meta charset="utf-8">
    <title> My Practice Page </title>
    </head>
    <body>
    <?
    $first_name = '';
    $last_name ='';
    $city ='';
    ?>
    $db = MYSQLI_CONNECT('localhost','root','','practiceforms');
    $sql = "INSERT INTO users (first name, last name, city) VALUES
    ('$first_name', '$last_name', '$city')";
    mysqli_query($db, $sql);
    mysqli_close($db);
    echo '<p> User added. </p>';
    <form method="post" action="">
    First Name: <input type="text" name="First Name" value="<?php $first_name;?>" <br>
    Last Name: <input type="text" name="Last Name" value ="<?php $last_name;?>"<br>
    City: <input type ="text" name="city" value=<?php $city; ?>" <br>
    <input type="submit" name="submit" value="submit">
    </body>
    </html>
  12. So i'm studying javascript, learning the different parts etc... but none of the training shows how to use it in a practical way in a webpage, thus far its all been academic, is there anywhere that I see practical ways to use it? or get examples.

    • Like 1
  13. var numapples = 0;
    if (numapples >= 4) {
    document.write("I'm apple rich!");
    }
    else if (numapples > 1 < 4) { <------- this is the part i'm unsure of, how to make sometthing more then one number but less then another.
    document.write("I have some apples");
    }
    else {
    document.write("I'm apple poor!");
    }
×
×
  • Create New...