remybink Posted July 30, 2011 Share Posted July 30, 2011 I realize I butchered this form by now, but I must have spent a few hours already, and at some point it worked, now it doesn't, just says array this section is separate file <?php //check for submit insert form in installed by us if(isset($_POST['submit'])){ $errors = array(); // initialize error array //extract content from form //public name section---------------------------------------------------- if(empty($_POST['prod_name'])){ $errors[] = 'no name'; }else{ $pname = trim($_POST['prod_name']); } //test for only alpha if(!preg_match('/^[a-zA-Z ]+$/', $pname)){ $errors[]='bad name'; } //dropdown menu select $cat = $_POST['category_select']; //comment section------------------------------------------------- if(empty($_POST['prod_descrip'])){ $errors[] = 'no description'; }else{ $pdescrip=$_POST['prod_descrip'];} //remove all characters except alpha numerics // $new_pdescrip = preg_replace("/[^a-zA-Z0-9\s]/", "", $pdescrip); //state bad words // $bad_words = array("sex", "fuck", "porn", "ass", "dick", "cunt", "whore", "stupid", "cum", "bitch", "bastard", "loser", "gay", "pornography", "nude", "shit", "cock", "suck", "penis", "vagina", "sex", "suck", "fukk", "dik", "dumb", "retard", "idiot", "butt", "clit", "kill", "www", "http", "dck", "naked", "milf"); //remove bad words and replace with **** // $new_pdescrip = str_replace($bad_words, " ", $new_pdescrip); //comment section------------------------------------------------- if(empty($_POST['installer_view'])){ $errors[] = 'no tech view'; }else{ $installer=$_POST['installer_view'];} //remove all characters except alpha numerics // $new_pdescrip = preg_replace("/[^a-zA-Z0-9\s]/", "", $pdescrip); //state bad words // $bad_words = array("sex", "fuck", "porn", "ass", "dick", "cunt", "whore", "stupid", "cum", "bitch", "bastard", "loser", "gay", "pornography", "nude", "shit", "cock", "suck", "penis", "vagina", "sex", "suck", "fukk", "dik", "dumb", "retard", "idiot", "butt", "clit", "kill", "www", "http", "dck", "naked", "milf"); //remove bad words and replace with **** // $new_pdescrip = str_replace($bad_words, " ", $new_pdescrip); //images section if(!empty($_POST['prod_img1'])){ $img1 = $_POST['prod_img1'];} if(!empty($_POST['prod_img1a'])){ $img1a = $_POST['prod_img1a'];} if(!empty($_POST['prod_img2'])){ $img2 = trim($_POST['prod_img2']);} if(!empty($_POST['prod_img2a'])){ $img2a = trim($_POST['prod_img2a']);} if(!empty($_POST['prod_img3'])){ $img3 = trim($_POST['prod_img3']);} if(!empty($_POST['prod_img3a'])){ $img3a = trim($_POST['prod_img3a']);} if(!empty($_POST['prod_img4'])){ $img4 = trim($_POST['prod_img4']);} if(!empty($_POST['prod_img4a'])){ $img4a = trim($_POST['prod_img4a']);} $msrp = $_POST['prod_msrp']; $sale = $_POST['prod_sale']; if(!empty($_POST['active'])){ $active = $_POST['active']; }else{ $errors[] = 'active not selected';} if(empty($errors)){ require('../scripts/dbconnect.php'); mysql_query("INSERT INTO items (prod_name, prod_cat, prod_descrip, installer_view, prod_img1, img1a, prod_img2, img2a, prod_img3, img3a, prod_img4, img4a, prod_msrp, prod_sale, prod_active) VALUES ('{$pname}', '{$cat}', '{$pdescrip}', '{$installer}', '{$img1}', '{$img1a}', '{$img2}', '{$img2a}', '{$img3}', '{$img3a}', '{$img4}', '{$img4a}', '{$msrp}', '{$sale}', '{$active}' )"); //$url = 'http://www.installedbyus.com'; }else{ // $url = 'http://www.installedbyus.com/insert.php'; echo $errors; } // header("location: $url"); exit(); } ?> I turned off much of the script looking for issues however i suspect the following to be an issue I tried to make the drop down menu in the form to extract categories from my db <?php require('scripts/dbconnect.php'); ?> <?php require('req/header.php'); ?> <body> <div id="wrapper-wrap"> <div id="wrapper"> <?php require('req/banner.php'); ?> <?php require('req/nav.php'); ?> <div class="clear"></div> <!-- end searches --> <div id="body"> <?php $records = "SELECT * FROM (categories)"; $query_records = mysql_query($records); $num_records = mysql_num_rows($query_records); if ($num_records == 0) { echo "nothing found."; }else{ echo "Database is open";} ?> <form action="scripts/insert_item.php" method="post" id="insert_form"> <p>prod_name <input type="text" name="prod_name" value="" /></p> <!-- category select --> <p>prod_cat <select name="category_select"> <?php while($row = mysql_fetch_assoc($query_records)){ $dbcategory = ($row['category']); echo '<option value="'.$dbcategory.'">'.$dbcategory.'</option>'; } ?> </select> </p> page link http://www.installedbyus.com/insert.php I am going to step away from this for 5 minutes. I think I will start cleaning it up and see what i come across, any pointers to improve this code is extremely appreciated Link to comment https://forums.phpfreaks.com/topic/243250-form-submission-returns-array/ Share on other sites More sharing options...
marcus Posted July 30, 2011 Share Posted July 30, 2011 Well $errors is an Array, so all you're doing is echoing the object. You gotta echo out each individual error. echo implode("<br/>",$errors); Link to comment https://forums.phpfreaks.com/topic/243250-form-submission-returns-array/#findComment-1249306 Share on other sites More sharing options...
remybink Posted July 30, 2011 Author Share Posted July 30, 2011 Thanks Marcus I should have taken a break a bit ago, had a different array problem and I fixed it, and fixed all the other errors prior, thanks for your help, I got it. Link to comment https://forums.phpfreaks.com/topic/243250-form-submission-returns-array/#findComment-1249308 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.