I am now getting this message at the top of my form screen," Success... mysql.hosting.zymic.com via TCP/IP NULL" and nothing in my database. Not sure what I am doing wrong.
<?php
require_once('config1.php');
function connect() { $sql = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if ($sql->connect_error) {
die('Connect Error (' . $sql->connect_errno . ') '
. $sql->connect_error);
}echo 'Success... ' . mysqli_get_host_info($link) . "\n";
return $sql;
}
function insert($type){
$sql=connect();
/* Set our params */
$fname = $_POST["fname"];
$lname = $_POST["lname"];
$phone = $_POST["phone"];
$address = $_POST["address"];
$department = $_POST["department"];
$email = $_POST["email"];
$level = $_POST["level"];
$query=("INSERT INTO Oktoberfest2013 (First_Name, Last_Name, Phone, Address, Department, Email_Address, Level_of_Traning) values (?, ?, ?, ?, ?, ?, ?)");
/* Create the prepared statement */
if ($stmt = $sql->prepare($query));
var_dump($qSelect);
if ( !$sql->query($query) ) {
return "Errormessage: $mysqli->error";
/* Bind our params */
$stmt->bind_param('sssssss', $fname, $lname, $phone, $address, $department, $email, $level);
/* Execute the prepared Statement */
$stmt->execute();
}
}
function select($query) {
$sql = connect();
$result = $sql->query($query);
while ( $obj = $result->fetch_object() ) {
$return[] = $obj;
}
}
?>
form info
<?php
require_once('class-db.php');
/**
* function to check the validity of the given string
* $what = what you are checking (phone, email, etc)
* $data = the string you want to check
*/
function isValid( $what, $data ) {
switch( $what ) {
// validate a phone number
case 'phone':
$pattern = "/^([1]-)?[0-9]{3}-[0-9]{3}-[0-9]{4}$/i";
break;
// validate email address
case 'email':
$pattern = "/^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$/i";
break;
default:
return false;
break;
}
return preg_match($pattern, $data) ? true : false;
}
$errors = array();
if( isset($_POST['btn_submit']) ) {
if( !isValid( 'phone', $_POST['phone'] ) ) {
$errors[] = 'Please enter a valid phone number';
}
if( !isValid( 'email', $_POST['email'] ) ) {
$errors[] = 'Please enter a valid email address';
}
}
if( !empty($errors) ) {
foreach( $errors as $e ) echo "$e <br />";
}
if ( !empty ( $_POST ) ) {
$type = 'post';
$insert = insert($type, $values);
}
?>
<html>
<head>
<title>Registration form for Octoberfest With O-G EMS 2013</title>
</head>
<body>
<form action="" method="post">
<p Registration />
<p>First Name:<input type="text" name="fname" > </p>
<p>Last Name:<input type="text" name="lname" > </p>
<p>Phone Number:<input type="text" name="phone" ></p>
<p>Address:<input type="text" name="address" ></p>
<p>Department:<input type="text" name="department" ></p>
<p>Email Address:<input type="text" name="email" ></p>
<p>Level of Training:<input type="text" name="level" ></p>
<input type="submit" name="btn_submit" value="Register">
</form>
</body>
</html>
Thanks for any help.