This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
Upload doesn't work right when the file is too big
(4 answers)
Display error message PHP Mysql
(6 answers)
Closed 4 years ago.
I'm trying to create a custom blog system for a website I am working on, I have created all of the systems however when I try to insert the form to the database, the script executes however the data is not saved to the database. Some of the fields do contain large amounts of text and formatting using TinyMCE could this be the problem? When I test it with smaller amounts of text it works fine.
PHP script:
$conn = connect();
$action = $_GET['a'];
$id = $_GET['id'];
switch($action) {
case 'delete':
$sql = "DELETE FROM articles WHERE id='$id'";
if(mysql_query($sql)) {
echo "<script type='text/javascript'> alert('Article Deleted'); </script>";
header("Location: manage.php");
}
break;
case 'add':
if(isset($_POST['submit'])) {
$slug = $_POST['slug'];
$datecreated = $_POST['datecreated'];
$datepublish = $_POST['datepublish'];
$author = $_POST['author'];
$status = $_POST['status'];
$title = $_POST['title'];
$miniexcerpt = $_POST['miniexcerpt'];
$teaser = $_POST['teaser'];
$body = $_POST['body'];
$sql = "INSERT INTO articles (slug,datecreated,datepublish,author,status,title,miniexcerpt,teaser,body) values ('$slug','$datecreated','$datepublish','$author','$status','$title','$miniexcerpt','$teaser','$body')";
if(mysql_query($sql)) {
echo "<script type='text/javascript'> alert('Article Added'); </script>";
header("Location: manage.php");
}
}
break;
case 'edit':
if(isset($_POST['submit'])) {
$slug = $_POST['slug'];
$datecreated = $_POST['datecreated'];
$datepublish = $_POST['datepublish'];
$author = $_POST['author'];
$status = $_POST['status'];
$title = $_POST['title'];
$miniexcerpt = $_POST['miniexcerpt'];
$teaser = $_POST['teaser'];
$body = $_POST['body'];
$sql = "UPDATE articles SET slug='$slug',datecreated='$datecreated',datepublish='$datepublish',author='$author',status='$status',title='$title',miniexcerpt='$miniexcerpt',teaser='$teaser',body='$body' WHERE id='$id'";
if(mysql_query($sql)) {
echo "<script type='text/javascript'> alert('Article Updated'); </script>";
header("Location: manage.php");
}
}
break;
}
$conn = connect();
$action = $_GET['a'];
$id = $_GET['id'];
switch($action) {
case 'publish':
$sql = "UPDATE articles SET status='published' WHERE id='$id'";
if(mysql_query($sql)) {
echo "<script type='text/javascript'> alert('Article Published'); </script>";
header("Location: manage.php");
}
break;
}
HTML Form:
<form id="form" name="form" action="articlefunctions.php?a=add" method="post">
<div class="form-group row">
<label for="title" class="col-sm-2 col-form-label">Article Title</label>
<div class="col-sm-10">
<input name="title" type="text" id="title" class="form-control" placeholder="Article Title" />
</div>
</div>
<div class="form-group row">
<label for="slug" class="col-sm-2 col-form-label">Article URL (Slug)</label>
<div class="col-sm-10">
<input name="slug" type="text" id="slug" class="form-control" placeholder="Article URL - Must NOT include spaces - use '-' instead" />
</div>
</div>
<div class="form-group row">
<label for="teaser" class="col-sm-2 col-form-label">Article Excerpt</label>
<div class="col-sm-10">
<textarea name="teaser" id="teaser" placeholder="Article Excerpt" rows="4"></textarea>
</div>
</div>
<div class="form-group row">
<label for="miniexcerpt" class="col-sm-2 col-form-label">Homepage Excerpt</label>
<div class="col-sm-10">
<textarea name="miniexcerpt" id="miniexcerpt" maxlength="180" placeholder="Snippet from excerpt to go on homepage" rows="4"></textarea>
<span id='remainingC' class="pull-right"></span>
</div>
</div>
<div class="form-group row">
<label for="body" class="col-sm-2 col-form-label">Article Content</label>
<div class="col-sm-10">
<textarea name="body" id="body" rows="8"></textarea>
</div>
</div>
<div class="form-group row">
<label for="author" class="col-sm-2 col-form-label">Article Author</label>
<div class="col-sm-10">
<input name="author" type="text" id="author" readonly class="form-control" value="<?php echo $_SESSION['user_name'];?>" />
</div>
</div>
<div class="form-group row">
<label for="status" class="col-sm-2 col-form-label">Article Status</label>
<div class="col-sm-10">
<select name="status" id="status" class="form-control" />
<option value="draft" selected>draft</option>
<option value="published">published</option>
</select>
</div>
</div>
<input name="datecreated" type="hidden" id="datecreated" value="<?php echo date('Y-m-d'); ?>" class="form-control" />
<div class="form-group row">
<label for="datepublish" class="col-sm-2 col-form-label">Publish Date</label>
<div class="col-sm-10">
<input name="datepublish" type="date" id="datepublish" class="form-control" />
</div>
</div>
<div class="form-group row">
<input type="submit" value="Save" id="submit" name="submit" class="btn btn-primary"/>
</div>
</form>
Check your php.ini. Some parameters affect POST payload size.
post_max_size integer
Sets max size of post data allowed. This setting also affects file upload. To upload large files, this value must be larger than upload_max_filesize. Generally speaking, memory_limit should be larger than post_max_size. When an integer is used, the value is measured in bytes. Shorthand notation, as described in this FAQ, may also be used. If the size of post data is greater than post_max_size, the $_POST and $_FILES superglobals are empty. This can be tracked in various ways, e.g. by passing the $_GET variable to the script processing the data, i.e. , and then checking if $_GET['processed'] is set.
source
Related
I'm working on this feature in my project where I want to add three(3) images along side other details into my database row and I want this images to be in separate columns in one row.... So far below is my code. the code is not working yet... The images and texts are not uploading to the database....
Please help me out guys. What am I doing wrong. Thanks.
Below is my code sample:
//THE PHP SECTION//
<?php
session_start();
include 'includes/config.php';
if (isset($_POST['post']) && isset($_POST['itemtype'])) {
$title = mysqli_real_escape_string($link, $_POST['title']);
$itemtype = mysqli_real_escape_string($link, $_POST['itemtype']);
$description = mysqli_real_escape_string($link, $_POST['description']);
$image1 = $_FILES['image1']['name'];
$image1_tmp_name = $_FILES['image1']['tmp_name'];
$image2 = $_FILES['image2']['name'];
$image2_tmp_name = $_FILES['image2']['tmp_name'];
$image3 = $_FILES['image3']['name'];
$image3_tmp_name = $_FILES['image3']['tmp_name'];
$price = mysqli_real_escape_string($link, $_POST['price']);
$category = mysqli_real_escape_string($link, $_POST['category']);
$name = mysqli_real_escape_string($link, $_POST['name']);
//image file directory
$target1 = 'images/user_ads/'.basename($image1);
$target2 = 'images/user_ads/'.basename($image2);
$target3 = 'images/user_ads/'.basename($image3);
if (move_uploaded_file($_FILES['image1_tmp_name'], $target1)) {
}
if (move_uploaded_file($_FILES['image2_tmp_name'], $target2)) {
}
if (move_uploaded_file($_FILES['image3_tmp_name'], $target3)) {
}
//insert into ost database
$insert = "INSERT INTO products(Title,Product_Type,Description,Image1,Image2,Image3,Price,Category,Name,PostedDate)VALUES('$title','$itemtype','$description','$target1','$target2','$target3','$price','$category','$name',NOW())";
$insertKwary = mysqli_query($link, $insert);
if ($insertKwary) {
$msg = "<div class='alert alert-danger alert-success'>Product Submitted</div>";
}else{
$msg = "<div class='alert alert-danger alert-success'>Product Not Submitted...Try again</div>";
}
}
?>
//THE HTML SECTION//
<div class="col-md-8 col-md-offset-2">
<?php if(isset($msg)) { echo $msg; } ?>
<form action="" method="POST" enctype="multipart/form-data" class="postAdForm" id="postAdForm">
<div class="form-group">
<label for="Ad_title">Item Title</label>
<input type="text" name="title" class="form-control title" id="title" required=""/>
</div>
<div class="form-group">
<label for="itemtype">Item Type</label>
<select class="form-control" name="itemtype" id="itemtype">
<option>Sale</option>
<option>Request</option>
</select>
</div>
<div class="form-group">
<label for="description">Item Description</label>
<textarea name="description" class="form-control description" id="description" rows="7" required=""></textarea>
</div>
<div class="form-group">
<label for="price">First Image</label>
<input type="file" name="image1" class="form-control image1" id="image1" required="" />
</div>
<div class="form-group">
<label for="price">Second Image</label>
<input type="file" name="image2" class="form-control image2" id="image2" required="" />
</div>
<div class="form-group">
<label for="price">Third Image</label>
<input type="file" name="image3" class="form-control image3" id="image3" required="" />
</div>
<div class="form-group">
<label for="price">Price</label>
<input type="text" name="price" class="form-control price" id="price" required="" />
</div>
<div class="form-group">
<label for="category">Item Category</label>
<select class="form-control" name="category" id="category">
<option>Sale</option>
<option>Request</option>
</select>
</div>
<div class="form-group">
<label for="price">Name</label>
<input type="text" name="name" class="form-control name" id="name" required="" readonly="" />
</div>
<div class="form-group">
<input type="submit" name="post" class="btn btn-post post" id="post" value="POST AD" />
</div>
</form>
</div>
I've also attached an image of the error i'm getting..
image of web page showing thee errors i get..error gotten
The error is due to these lines:
if (move_uploaded_file($_FILES['image1_tmp_name'], $target1)) {
}
if (move_uploaded_file($_FILES['image2_tmp_name'], $target2)) {
}
if (move_uploaded_file($_FILES['image3_tmp_name'], $target3)) {
}
You're setting $image1_tmp_name, not $_FILES['image1_tmp_name'].
Try this:
if (move_uploaded_file($image1_tmp_name, $target1)) {
}
if (move_uploaded_file($image2_tmp_name, $target2)) {
}
if (move_uploaded_file($image3_tmp_name, $target3)) {
}
Edit: Using mysqli_error() to print the error helped solve additional issues (Mentioned in comments)
A value is being stored in the database but it is not the one i am expecting. I tried many methods before but this one kind of seems to work but the file name is not being stored and when I try to download the file directly from the database, it downloads a .bin file format which looks something like table_Name-column_Name.bin. The file name being stored is BLOB - ## B.
My Form
<form class="form-horizontal" method="post" action="productsValidate.php" name="myForm" enctype="multipart/form-data">
<fieldset>
<legend>Add Product</legend>
<div class="form-group">
<label for="Product_Name" class="col-lg-2 control-label">Product Name</label>
<div class="col-lg-10">
<input type="text" class="form-control" id="Product_Name" placeholder="Name" required="required" name="Product_Name">
</div>
</div>
<div class="form-group">
<label for="Size" class="col-lg-2 control-label">Size</label>
<div class="col-lg-10">
<input type="text" class="form-control" id="Size" placeholder="Size" required="required" name="Size">
</div>
</div>
<div class="form-group">
<label for="Color" class="col-lg-2 control-label">Color</label>
<div class="col-lg-10">
<input type="text" class="form-control" id="Color" placeholder="Size" required="required" name="Color">
</div>
</div>
<div class="form-group">
<label for="price" class="col-lg-2 control-label">Price</label>
<div class="col-lg-10">
<input type="number" class="form-control" id="price" placeholder="price" required="required" name="price">
</div>
</div>
<div class="form-group">
<label for="image" class="col-lg-2 control-label">Select Image</label>
<div class="col-lg-10">
<input type="file" name="image" id="image">
</div>
</div>
<div class="form-group">
<label for="categoryId" class="col-lg-2 control-label">Category Id</label>
<div class="col-lg-10">
<?php
//your connection to the db and query would go here
include "../include/settings.php";
$conn = new mysqli($host, $user, $pwd, $sql_db);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT distinct Category_Id FROM products";
$result = mysqli_query($conn, $sql);
?>
<select id="categoryId" name="categoryId">
<option value = ""></option>
<?php
while($row = mysqli_fetch_array($result)) {
echo '<option value='.$row['Category_Id'].'>'.$row['Category_Id'].'</option>';
}
?>
</select>
</div>
</div>
<div class="form-group">
<label for="description" class="col-lg-2 control-label">Description</label>
<div class="col-lg-10">
<textarea type="text" class="form-control" id="description" placeholder="Description" required="required" name="description" pattern="[\sA-Za-z]+"></textarea>
</div>
</div>
<div class="form-group">
<div class="col-lg-6 col-lg-offset-2">
<button type="submit" class="btn btn-primary">Add Product</button>
</div>
</div>
</fieldset>
</form>
My Form validation
<?php
$name = $_POST["Product_Name"];
$size = $_POST["Size"];
$color = $_POST["Color"];
$price = $_POST["price"];
$image = addslashes($_FILES['image']['tmp_name']);
$image = file_get_contents($image);
$image = base64_encode($image);
$image=basename( $_FILES["image"]["tmp_name"],".jpg");
$category = $_POST['categoryId'];
$description = $_POST['description'];
insertProduct($name, $size, $color, $price, $image, $category, $description);
function insertProduct($name, $size, $color, $price, $image, $category, $description){
require_once ("../include/settings.php"); // Load MySQL log in credentials
$conn = #mysqli_connect ($host,$user,$pwd,$sql_db); // Log in and use database
if ($conn) { // check is database is avialable for use
$query = "INSERT INTO products
(Product_Id, Product_Name, Size, Color, Price, Picture, Category_Id, Description)
VALUES ('', '$name', '$size', '$color', '$price', '$image', '$category', '$description')";
$result = mysqli_query ($conn, $query);
if ($result) { // check if query was successfully executed
echo 'Successfully Added';
} else {
echo 'Product could not be added';
}
mysqli_close ($conn); // Close the database connect
} else {
echo "<p>Unable to connect to our database for adding the product.</p>";
}
}
?>
I guess you're trying to store the actual encoded image in the database, not a pointer to it. It looks to me like your eleven-byte BLOB has the pointer in it instead.
Your code contains this sequence of lines.
$image = addslashes($_FILES['image']['tmp_name']);
$image = file_get_contents($image);
$image = base64_encode($image);
$image=basename( $_FILES["image"]["tmp_name"],".jpg");
The third line puts an encoded, not binary, version of the image into a text string. That's close to what you want, but you probably should not base64-encode it if you're putting in a BLOB.
The fourth line discards the image itself and overwrites it with an image name. I think that's wrong.
If you're going to use BLOB data this way, you also need to use mysqli's facilities to prepare your SQL statements, and then bind your parameters. The bind_param() function gives you a way to declare a parameter to be a blob. That's better than trying to trick php's string processing into accepting it.
All that being said, most people use a file system or content server rather than BLOBs to store and serve images to web clients. BLOB programming is a pain in the neck. Also, using a DBMS to store and retrieve images quickly becomes a performance bottleneck in an application that scales up.
This question already has answers here:
Why can't I run two mysqli queries? The second one fails [duplicate]
(2 answers)
Closed 6 years ago.
I am trying to create a php/html form which will insert results into a dog show database. The problem no matter what I do I get this error:
QUERY FAILED .You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INSERT INTO.
Here is the code for the page any help appreciated.
<?php
if(isset($_POST['create_show'])) {
//Insert Judges
$show_title = escape($_POST['show_title']);
$show_user = escape($_POST['show_user']);
$show_category_id = escape($_POST['show_category_id']);
$show_status = escape($_POST['show_status']);
// $show_image = escape($_FILES['show_image']['name']);
//$show_image_temp = escape($_FILES['image']['tmp_name']);
$show_tags = escape($_POST['show_tags']);
$show_content = escape($_POST['show_content']);
//$show_date = escape(date('d-m-y'));
//INSERT Judges
$judge_affix = escape($_POST['judge_affix']);
$judge_name = escape($_POST['judge_name']);
$judge_show = escape($_POST['show_idj']);
//Insert Dogs
$dog_name = escape($_POST['dog_name']);
$resultIDD = escape($_POST['resultIDD']);
//Insert Into Results
$class_name = escape($_POST['class_name']);
$placement = escape($_POST['placement']);
$award = escape($_POST['award']);
//move_uploaded_file($show_image_temp, "../images/$show_image" );
//Insert Shows
$query = "INSERT INTO shows (show_category_id, show_title, show_user, show_content, show_tags, show_status) VALUES ('$show_category_id','$show_title','$show_user','$show_content','$show_tags','$show_status');";
$query .= "INSERT INTO judges (judge_affix, judge_name) VALUES ('$judge_affix','$judge_name');";
$query .= "INSERT INTO dogs (dog_name, resultIDD) VALUES ('$dog_name','$resultIDD');";
$query .= "INSERT INTO result(class_name, placement,) VALUES ('$class_name','$placement')";
$create_show_query = mysqli_query($connection, $query);
confirmQuery($create_show_query);
$the_show_id = mysqli_insert_id($connection);
echo "<p class='bg-success'>Show Created. <a href='../show.php?s_id={$the_show_id}'>View Post </a> or <a href='shows.php'>Edit More Shows</a></p>";
}
?>
<form action="" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="show_title">Show Title</label>
<input type="text" class="form-control" name="show_title">
</div>
<div class="form-group">
<label for="category">Category</label>
<select name="show_category" id="">
<?php
$query = "SELECT * FROM categories";
$select_categories = mysqli_query($connection,$query);
confirmQuery($select_categories);
while($row = mysqli_fetch_assoc($select_categories )) {
$cat_id = $row['cat_id'];
$cat_title = $row['cat_title'];
echo "<option value='$cat_id'>{$cat_title}</option>";
}
?>
</select>
</div>
<div class="form-group">
<label for="users">Users</label>
<select name="post_user" id="">
<?php
$users_query = "SELECT * FROM users";
$select_users = mysqli_query($connection,$users_query);
confirmQuery($select_users);
while($row = mysqli_fetch_assoc($select_users)) {
$user_id = $row['user_id'];
$username = $row['username'];
echo "<option value='{$username}'>{$username}</option>";
}
?>
</select>
</div>
<!-- <div class="form-group">
<label for="title">Post Author</label>
<input type="text" class="form-control" name="author">
</div> -->
<div class="form-group">
<select name="show_status" id="">
<option value="draft">Show Status</option>
<option value="published">Published</option>
<option value="draft">Draft</option>
</select>
</div>
<div class="form-group">
<label for="show_tags">Show Tags</label>
<input type="text" class="form-control" name="show_tags">
</div>
<div class="form-group">
<label for="judge_name">Show Tags</label>
<input type="text" class="form-control" name="judge_name">
</div>
<div class="form-group">
<label for="judge_affix">Show Tags</label>
<input type="text" class="form-control" name="judge_affix">
</div>
<div class="form-group">
<label for="show_content">Show Content</label>
<textarea class="form-control " name="show_content" id="" cols="30" rows="5">
</textarea>
</div>
<div class="form-group">
<p>Minor Puppy Dog</p>
</div>
<div class="form-group">
<label for="dog_name">1st Dog Name</label>
<input type="text" class="form-control" name="dog_name">
</div>
<div class="form-group">
<input type="hidden" class="form-control" name="placement" value="1">
</div>
<div class="form-group">
<input class="btn btn-primary" type="submit" name="create_show" value="Publish Show">
</div>
</form>
The mysqli_query only executes one single query.
For executing multiple queries at once, you can use mysqli_multi_query.
Simply replace your mysqli_query with the mysqli_multi_query like so:
$create_show_query = mysqli_multi_query($connection, $query);
After submit in signup page my signUp page redirects to info.php where I want to collect additional info of user using email id he gives on signup page but when I tried to get the email id of user through sessions, session return empty value.
THIS IS MY SIGNUP CODE
<?php
session_start();
if(isset($_POST['submit'])){
$name= $_POST['_user'];
$email = $_POST['_email'];
$pass = $_POST['_password'];
//Insert Data
$sql = "INSERT INTO signup(name,email,password)
VALUES('$name','$email','$pass')";
//Data Validation
if(mysqli_query($conn,$sql)){
echo "<script>alert('SignUp Successfull')</script>";
$_SESSION['user_email'] = $email;
header('Location: info.php');
}
else{
echo "<script>window.alert('You are already a user.')</script>";
}
}
mysqli_close($conn);
?>
AND THIS MY INFO.PHP CODE
<?php
session_start();
if(isset($_POST['_submit'])){
if(empty($_POST['_address']) || empty($_POST['_country']) || empty($_POST['_number']) || empty($_POST['_cnic']) || empty($_POST['_passport'])){
echo "<script>window.alert('All fields are required')</script>";
}
else{
$address = $_POST['_address'];
$country = $_POST['_country'];
$number = $_POST['_number'];
$cnic = $_POST['_cnic'];
$passport = $_POST['_passport'];
$email=$_SESSION['user_email'];
$query = "INSERT INTO info(email,address,country,mobile,cnic,passport)
VALUES('$email','$address','$country','$number','$cnic','$passport')";
if(mysqli_query($conn,$query)){
header('Location: ../index.php');
}
else{
echo "<script>window.alert('Error While Entering the data!.')</script>";
}
}
}
mysqli_close($conn);
?>
In addition I use this global session variable for login page and it works fine.
UPDATE
SIGNUP HTML CODE
<div class="outside">
<form class="form-horizontal" role="form" method="post">
<div class="form-group">
<label class="control-label col-sm-3 glyphicon glyphicon-user" for="name"></label>
<div class="control-label col-sm-8">
<input type="text" name="_user" class="form-control" id="name" placeholder="Full Name">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="email">
<img class="glyphicon1" src="../assests/at-sign.png">
</label>
<div class="control-label col-sm-8">
<input type="email" name="_email" class="form-control" id="email" placeholder="Enter Email">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3 glyphicon glyphicon-lock" for="password"></label>
<div class="control-label col-sm-8">
<input type="password" name="_password" class="form-control" id="password" placeholder="Enter Password">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-3">
<button name="submit" id="submit" value="Upload" type="submit" class="btn btn-default">Confirm SignUp</button>
</div>
</div>
<p>Already a User? LogIn</p>
</form>
</div>
Use this for Returns the auto generated id used in the last query
mysqli_insert_id($link)
I have a dozen fully functional scripts that use heredoc statements to display HTML including e.g. $errors[field_name] yet this nearly identical script results in POST errors like
"Notice: Undefined index: user_password in register.php on line 162"
When the user enters a password with 5 characters when 8+ characters are required, a validation function populates $errors['password'] and the form is supposed to re-display along with validation errors.
Can't see what I'm missing in this Bootstrap style form. The $errors array is global and I can force the display of errors, so I know errors are initialized but I keep getting
"Notice: Undefined index"
$fields = array( 'user_name', 'user_email', 'user_password', 'user_password2' );
function display_form($string = '')
{
global $error_token, $cfg, $fields, $form, $errors, $s, $token, $validation_status;
$error_message = '';
switch($_SERVER['REQUEST_METHOD'])
{
Case 'POST':
// validation failed, redisplay the form
$autofocus = '';
foreach($fields as $field){
$$field = htmlentities(get_cgi_var($field), ENT_QUOTES, 'UTF-8');
// wrap errors in Bootstrap alert markup
$errors[$field] = !empty($errors[$field]) ? '<div class="alert alert-danger">'.htmlentities($errors[$field], ENT_QUOTES, 'UTF-8').'</div>' : '';
// debug, force the premature display of errors.
// echo !empty($errors[$field]) ? '<div class="alert alert-danger">'.htmlentities($errors[$field], ENT_QUOTES, 'UTF-8').'</div>' : '<p>empty</p>';
}
break;
Case 'GET':
default:
$autofocus = 'autofocus';
foreach($fields as $field){
$$field = '';
$errors[$field] = '';
}
$error_token = '';
break;
};
foreach($fields as $field){
$validation_status[$field] = empty($errors[$field]) ? ' has-success' : ' has-error';
}
$self = SELF;
print<<<_HTML_
<div class="col-lg-6">
<div class="panel panel-primary">
<div class="panel-heading">Registration</div>
<div class="panel-body">
$string
$error_message
<form name="form1" id="form1" action="$self" class="form-horizontal" role="form" method="POST">
<fieldset>
$error_token
$errors[user_name]
<div class="row form-group$validation_status[user_name]">
<label for="user_name" class="col-lg-3 control-label">Name</label>
<div class="col-lg-9">
<input type="text" name="user_name" id="user_name" value="$user_name" maxlength="255" $autofocus required placeholder="Your First & Last Name" title="Your First & Last Name" autocomplete="on" class="form-control">
</div>
</div>
$errors[user_email]
<div class="row form-group$validation_status[user_email]">
<label for="user_email" class="col-lg-3 control-label">Email</label>
<div class="col-lg-9">
<input type="email" name="user_email" id="user_email" value="$user_email" maxlength="255" required placeholder="Your Email Address" autocomplete="on" class="form-control">
</div>
</div>
$errors[user_password]
<div class="row form-group$validation_status[user_password]">
<label for="user_password" class="col-lg-3 control-label">Password</label>
<div class="col-lg-9">
<input type="text" name="user_password" id="user_password" value="$user_password" maxlength="255" required placeholder="Password or Passphrase" autocomplete="on" class="form-control">
<p class="help-block">Case sensitive password containing 8+ characters or a phrase containing 3-5 words</p>
</div>
</div>
$errors[user_password2]
<div class="row form-group$validation_status[user_password2]">
<label for="user_password2" class="col-lg-3 control-label">Password</label>
<div class="col-lg-9">
<input type="text" name="user_password2" id="user_password2" value="$user_password2" maxlength="255" required placeholder="Re-enter Password or Passphrase" autocomplete="on" class="form-control">
</div>
</div>
<div class="row form-group">
<label for="submit_button" class="col-lg-3 control-label"> </label>
<div class="col-lg-9 text-center">
<input type="hidden" name="token" value="$token">
<input type="submit" name="submit_button" id="submit_button" value="Submit" onClick="return captcha_validation(this.form);" class="btn btn-primary">
</div>
</div>
</fieldset>
</form>
</div><!-- /panel-body -->
<div class="panel-footer text-center"> </div>
</div><!-- /panel -->
</div><!-- /col -->
<div class="col-lg-6">
<div class="well">unused column</div>
</div><!-- /col -->
_HTML_;
};
Here's your problem:
default:
$autofocus = 'autofocus';
foreach($fields as $field){
$$field = ''; // <------------------
$errors[$field] = '';
}
$error_token = '';
break;
replace $$field with $field or remove it altogether - it's not needed here.