jonw118 Posted November 23, 2009 Share Posted November 23, 2009 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); } ?> Link to comment https://forums.phpfreaks.com/topic/182562-trouble-inserting-a-new-field-into-mysql/ Share on other sites More sharing options...
jonw118 Posted November 23, 2009 Author Share Posted November 23, 2009 Actually. Please ignore this... I finally figured out the answer. Sorry for taking up room on the forum - stupid mistake!!! Link to comment https://forums.phpfreaks.com/topic/182562-trouble-inserting-a-new-field-into-mysql/#findComment-963575 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.