Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ini_set("display_errors", "on");
- error_reporting(E_ALL + E_DEPRECATED);
- session_start();
- $username = $_POST['username'];
- $password = $_POST['password'];
- $created = '2010-11-30 15:17:44';
- $orgType = $_POST['orgType'];
- $orgName = $_POST['orgName'];
- $streetAddress = $_POST['streetAddress'];
- $suiteApt = $_POST['suiteApt'];
- $city = $_POST['city'];
- $state = $_POST['state'];
- $zipcode = $_POST['zipcode'];
- $phone = $_POST['phone'];
- $extension = $_POST['extension'];
- $fax = $_POST['fax'];
- $website = $_POST['website'];
- $contactFullName = $_POST['contactFullName'];
- $contactEmail = $_POST['contactEmail'];
- $contactPhone = $_POST['contactPhone'];
- $contactExtension = $_POST['contactExtension'];
- var_dump($_POST); //Used for troubleshooting, post was successful.
- // Require the file which contains the database credentials.
- require('db.inc.php');
- // Create a new database connection.
- $dbc = new mysqli($server, $db_user, $db_pass, $db);
- if (mysqli_connect_errno()) {
- printf("Connect failed: %s\n", mysqli_connect_error());
- exit();
- }
- // Was having a hard time executing the query, decided to hard-code the values in.
- //$stmt = $mysqli->prepare("INSERT INTO CountryLanguage VALUES (?, ?, ?, ?)");
- $stmt = $dbc->prepare("INSERT INTO organization (username, password, created, orgType, orgName,
- streetAddress, city, state, zipcode, phone,
- contactFullName, contactEmail, contactPhone)
- VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?);"
- );
- if (!$stmt) {
- echo "Error: ".$dbc->error;
- exit;
- }
- $stmt->bind_param('sssssssssssss',$username,$password,$created,$orgType,$orgName,$streetAddress,$city,
- $state,$zipcode,$phone,$contactFullName,$contactEmail,$contactPhone);
- //VALUES ('user','test',now(),'s','testCo','1234 mockingbird lane',
- // 'madison','WI','55555','1234567890','test user',
- // 'user@test.com','1234567890');");
- //INSERT INTO organization (username, password,created,orgType,orgName,streetAddress,city,state,zipcode,phone,contactFullName,contactEmail, contactPhone, contactExtension)
- //VALUES (?,?,now(),?,?,?,?,?,?,?,?,?,?);";
- //VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?);");
- // After all the trouble I had with the bind parameters, I ended up hard-coding values in for the "prepare" function. It worked.
- // Am now going to try using variables now. Success/fail notes to follow.
- // Using the $_POST variables did indeed work. Proved by viewing the table, it showed the incorrect time ($created = '2010-11-30 15:17:44';).
- // Will now try binding parameters once more, using "now()" first.
- // Turns out that I had completely forgotten to assign the data types as the first parameter in bind_param().
- // Changing bind_param() to remove $created (was hard-coded) and use now() in the VALUES portion of the prepare() method.
- // Didn't work. Needed $created to be hard-coded...stumped. Moving on.
- $executedQuery = $stmt->execute();
- if(!$executedQuery){
- echo "Error: ".$dbc->error;
- //die(mysqli_connect_error());
- exit;
- }
- ?>
Add Comment
Please, Sign In to add comment