1. OCAU Merchandise is available! Check out our 20th Anniversary Mugs, Classic Logo Shirts and much more! Discussion in this thread.
    Dismiss Notice

php & sql insert

Discussion in 'Programming & Software Development' started by TehCamel, Aug 22, 2017.

(追記) (追記ここまで)
  1. TehCamel Member

    Joined:
    Oct 8, 2006
    Messages:
    4,226
    Location:
    Melbourne
    I feel like I'm super close on this but can't quite crack it

    index.php:
    Code:
    <form action="auth.php" method=POST>
    E-Mail: <input type="text" name="email" /><br /> 
    <input type=hidden name=mac value=<?php echo $id; ?> />
    <input type=hidden name=ap value=<?php echo $ap; ?> />
    <input type=hidden name=url value=<?php echo $url; ?> />
    <input type=submit value="Log In" />
    
    auth.php:
    Code:
     require_once 'config.php.inc';
     $email = trim($_POST['email']);
     $mac = trim($_POST['mac']);
     $ap = trim($_POST['ap']);
     $url = trim($_POST['url']);
     $auth = auth_user($email,$table);
     echo $url;
     if($auth) {
     //Minutes to authorize, change to suit your needs
     $minutes = 10080;
     sendAuthorization($mac,$ap,$minutes,$url);
     }
    
    config.inc:
    Code:
    $mysql_db variables, bla (defined db, host,user, pass,)
    $table = "creds";
    $mysql = mysqli_connect($mysql_host,$mysql_user,$mysql_pass,$mysql_db);
    function auth_user($email, $table) {
    $query = "INSERT into creds (email) VALUES ($email)";
    mysqli_query($mysql,$query)
    echo "true";
    return true;
    }
    
    there's a bit more in there, but this is the relevant part. Basically, I want to take "email" from index.php
    submit it to auth.php
    which calls config.inc.php and then uses the function to write it into a sql database


    the Mysql database is basically:

    create table 'creds'
    id int(6) autoincrement
    email varchar(30) notnull

    and that's it.
  2. Splade Member

    Joined:
    Jan 13, 2002
    Messages:
    1,699
    Location:
    Sydney 2127
    Looks like it should work.

    Got any logfile output?

    edit: Have you got config.inc.php and config.php.inc transposed on your site like you do in your post?

    Also, no sem colon after "mysqli_query($mysql,$query)"
    Last edited: Aug 27, 2017

Share This Page

Advertisement:
(追記) (追記ここまで)

AltStyle によって変換されたページ (->オリジナル) /