Jump to content

Trouble Inserting A New Field into MySQL


jonw118

Recommended Posts

I have a page where I am trying to essentially clone a field (called "gallery_name") to insert a new field ("main_desc") into the MySQL database... but it's not inserting the data. Does anyone have a clue as to what I may be doing wrong? I'd appreciate any help. Below you can see the different areas I cloned the gallery_name (I highlighted what I added in red). Thanks!!!

 

if(isset($_POST['save_gallery']))
{
$validation_success=true;
if(strlen($_POST['gallery_name'])==0)
	{
	$validation_success=false;
	$form_validation['error_gallery_name']=true;
	$error_msg="Field 'Gallery Name' cannot be blank";
	}
[color=red]
if(strlen($_POST['main_desc'])==0)
	{
	$validation_success=false;
	$form_validation['error_main_desc']=true;
	$error_msg="Field 'Gallery Description' cannot be blank";
	}		[/color]

if($validation_success)
	{
	$gallery_name=$_POST['gallery_name'];
[color=red]$main_desc=$_POST['main_desc'];[/color]

        $max_priority=q()->gallery()->max()->priority;
	q()->gallery=array('gallery_name'=>$gallery_name,'priority'=>$max_priority+1);
        $insert_id=q()->gallery->insert_id;
        if(strlen($_FILES['main_image']['tmp_name'])>0)
            {
            $tmp_name=$_FILES['main_image']['tmp_name'];
            resize_img($tmp_name, "../uploads/images/gallery_main_$insert_id", 'jpg',MAX_IMAGE_X,MAX_IMAGE_Y);
            }

        }
}
else
{
$_POST+=array_fill_keys(array('gallery_name','[color=red]main_desc[/color]'),'');
}
?>

 

<tr>
            <td <?php if(isset($form_validation['error_gallery_name'])) echo "class='error_field'";?>>
                Gallery Name
            </td>
            <td <?php if(isset($form_validation['error_gallery_name'])) echo "class='error_field'";?>>
                <input size=60 type='text' name='gallery_name'  value="<?php echo htmlentities($_POST['gallery_name'],ENT_QUOTES);?>">
            </td>
        </tr>
  
                [color=red]<tr>
            <td <?php if(isset($form_validation['error_main_desc'])) echo "class='error_field'";?>>
                Gallery Description
            </td>
            <td <?php if(isset($form_validation['error_main_desc'])) echo "class='error_field'";?>>
                <input size=60 type='text' name='main_desc'  value="<?php echo htmlentities($_POST['main_desc'],ENT_QUOTES);?>">
            </td>
        </tr>[/color]

 

This is where I think the problem may be coming from not inserting into the DB:

<?php
if(isset($_POST['save_gallery']))
{
$validation_success=true;
if(strlen($_POST['gallery_name'])==0)
	{
	$validation_success=false;
	$form_validation['error_gallery_name']=true;
	$error_msg="Field 'Gallery Name' cannot be blank";
	}

if($validation_success)
	{
	$update_id=$_POST['update_id'];
	q()->gallery($update_id)->gallery_name=$_POST['gallery_name'];
	$row=q()->gallery($update_id);


[color=red]if(strlen($_POST['main_desc'])==0)
	{
	$validation_success=false;
	$form_validation['error_main_desc']=false;
	$error_msg="Field 'Gallery Description' cannot be blank";
	}

if($validation_success)
	{
	$update_id=$_POST['update_id'];
	q()->gallery($update_id)->main_desc=$_POST['main_desc'];
	$row=q()->gallery($update_id);	[/color]	


        if(strlen($_FILES['main_image']['tmp_name'])>0)
            {
            $tmp_name=$_FILES['main_image']['tmp_name'];
            resize_img($tmp_name, "../uploads/images/gallery_main_$update_id", 'jpg',MAX_IMAGE_X,MAX_IMAGE_Y);
            }
    echo msg("Change Successful. <a href='index.php?module=pictures&action=menu_item_pictures'>Click here</a> to return to galleries");
	}
}
elseif(isset($_GET['update_id']))
{
$update_id=$_GET['update_id'];
$row=q()->gallery($update_id);
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.