Jump to content

co.ador

Members
  • Posts

    726
  • Joined

  • Last visited

    Never

Everything posted by co.ador

  1. On the database connection I got that working and I slipped the session_start() function which I have it thanks, now I have to figure out your steps. I have done an if and else statement on <input class="btn" type="submit" name="Insert" value="Insert" /> input tag with the function empty like, <?php if (empty($_POST['Insert'])){ echo ' is either 0, empty, or not set at all'; } else { rest of the code you guys see above in insert.php } ?> it inserted just like you said. On step two you talk about validating all the fields I will double check that since you say validation won't continue upon a mistake found. Let me check on that.
  2. i have a form which action leads to insert.php. In insert.php define the value fields of the forms and then validates but it will submit the form and ignore the validation. Form <form action="Insert.php" method="post" enctype="multipart/form-data">'; <input type="hidden" name="submitted" value="true" /> <label align="left" for="Image">Upload Image:</label> <input name="file" type="file" size="25" /> <label class="City" for="City"> City:</label> <input name="city" type="text" /> <label for="State">State:</label> <input name="state" type="text" /> <label for="ZipCode">Zip Code:</label> <input name="zipcode" type="text" /> <input class="btn" type="submit" name="Insert" value="Insert" /> <input class="btn" type="reset" name="Reset" value="Clear Form" /> </form> Insert.php <?php $custumer_id = $_SESSION['customer_id']; $itemname = ereg_replace("[^A-Za-z0-9]", "", $_POST['name']); // filter everything but numbers and letters $price = $_POST['price']; $city = ereg_replace("[^A-Z a-z0-9]", "", $_POST['city']); // filter everything but spaces, numbers, and letters $state = ereg_replace("[^A-Z a-z0-9]", "", $_POST['state']); // filter everything but spaces, numbers, and letters $zipcode = $_POST['zipcode']; $image = $_POST['file']; if((!$itemname) || (!$country) || (!$state) || (!$city) || (!$price) || (!$details) || (!$subcategory) || (!$image)) { $errorMsg = "You did not submit the following required information!<br /><br />"; if(!$itemname){ $errorMsg .= "--- Product Name"; } else if(!$country){ $errorMsg .= "--- Country"; } else if(!$state){ $errorMsg .= "--- State"; } else if(!$city){ $errorMsg .= "--- City"; } else if(!$price){ $errorMsg .= "--- Price"; } else if(!$image){ $errorMsg .= "Insert a File"; } } $sqlinsert2 = "INSERT INTO products (product_id,product_name,price,city,state, country, category_id) VALUES('','$itemname','$price','$city','$state','$country',)"; $enterquery2 = mysql_query($sqlinsert2) or die(mysql_error()); $product_id = mysql_insert_id(); $sqlinsert3 = "INSERT INTO sales (id,product_id, customer_id, sales_date) VALUES('','$product_id','$custumer_id',now())"; $enterquery3 = mysql_query($sqlinsert3) or die(mysql_error()); } ?>
  3. Thank you taynon, I wanted it to be a single selection that returns both the ID and the name? id and name the fields in the query someone has suggested to send concatenate the fields name and id at the option tag like echo "<option value=\"".$row['name']."$".$row['id']."\">".$row['name']."</option>\n "; then retrieve the data you can explode it as so $option = explode("$", $_POST['category_id']); echo $option[0]; // Name echo $option[1]; / That solved the name
  4. This is the query $sql = mysql_query("INSERT INTO products (product_name, price, details, subcategory, city, state, country, category_id, date_added) VALUES('$productname','$price','$details','$subcategory','$city','$state','$country','$category_id', now())") or die (mysql_error()); // Get the inserted ID here to use in the activation email $id = mysql_insert_id(); ?> This is the form with a name of category_id this field has the value of the id only, I also want to send the name value to the query. <select name="category_id" size="1"><br />'; $sql = "SELECT id, name FROM categories ORDER BY name"; $rs = mysql_query($sql); while($row = mysql_fetch_array($rs)) { echo "<option value=\"".$row['id']."\">".$row['name']."</option>\n "; } echo' </select> SQL structure `product_id` int(11) NOT NULL AUTO_INCREMENT, `product_name` varchar(225) NOT NULL, `price` varchar(16) NOT NULL, `details` text NOT NULL, `category` varchar(255) NOT NULL, `subcategory` varchar(225) NOT NULL, `date_added` datetime NOT NULL, `location` varchar(255) NOT NULL, `city` varchar(50) NOT NULL, `state` varchar(255) NOT NULL, `country` varchar(255) NOT NULL, `category_id` int(11) NOT NULL,
  5. I thought you have understood. The form in the first post will insert in the query below. sql = mysql_query("INSERT INTO products (product_name, price, details, subcategory, city, state, country, category_id, date_added) VALUES('$productname','$price','$details','$subcategory','$city','$state','$country','$category_id', now())") or die (mysql_error()); // Get the inserted ID here to use in the activation email $id = mysql_insert_id(); ?> the query above won't insert the $category_id in category_id field I have defined as follows $category_id = $_POST['category_id']; I guess it is not inserting any value because category_id is a character value no a numeric value. while category_id the table field is a numeric value (integer) int(11) What can I do to insert that the value in the table field?
  6. I never thought that was going to be a problem. But I would like multiple products within that field even when they have the same name they will have different products.
  7. <select name="category_id" size="1"><br />'; $sql = "SELECT id, name FROM categories ORDER BY name"; $rs = mysql_query($sql); while($row = mysql_fetch_array($rs)) { echo "<option value=\"".$row['id']."\">".$row['name']."</option>\n "; } echo' </select> Above I want to insert id into category_id value which is sending it to the database to the category_id field which is a int(11) as you can see it will insert a empty value because of the problem of phpmyadmin interpreting a character value in <option value=\"".$row['id']."\">".$row['name']."</option>\n "; and inserting it into the category_id field as int(11). I also want to set up the form to send the value of name through post to insert it in a field called category varchar(255). how can I send <option value=\"".$row['id']."\"> as an interger and then wihin that select tag send name as a varchar ?
  8. The field 'name' was UNIQUE KEY and was not accepting double entries. So what I did was ALTER TABLE Persons DROP INDEX name Drop the UNIQUE index out of name and it did the job guys............
  9. I thought this $name = ereg_replace("[^A-Za-z0-9]", "", $_POST['name']) was defining the variable at this point I think I haven't define the variable #name then I will have to define them.
  10. $sql = mysql_query("INSERT INTO products (name, price, details, category, subcategory, category_id, city, state, country, date_added) VALUES('$tname','$price','$details','$category','$subcategory','$category_id','$city','$state','$country', now())") or die (mysql_error()); // Get the inserted ID here to use in the activation email $id = mysql_insert_id(); That's the query where the problem seems to be happening. Also I have a code above this query for validation purposes that goes like if (isset($_POST['Insert'])){ //Connect to the database through our include include "storescripts/connect_to_mysql.php"; // Filter the posted variables $name = ereg_replace("[^A-Za-z0-9]", "", $_POST['name']); // filter everything but numbers and letters $country = ereg_replace("[^A-Z a-z0-9]", "", $_POST['country']); // filter everything but spaces, numbers, and letters $state = ereg_replace("[^A-Z a-z0-9]", "", $_POST['state']); // filter everything but spaces, numbers, and letters $city = ereg_replace("[^A-Z a-z0-9]", "", $_POST['city']); // filter everything but spaces, numbers, and letters $price = $_POST['price']; $details = ereg_replace("[^A-Z a-z0-9]", "", $_POST['details']); // filter everything but spaces, numbers, and letters $category = $_POST['category']; $subcategory = ereg_replace("[^A-Z a-z0-9]", "", $_POST['subcategory']); // filter everything but spaces, numbers, and letters $category_id = $_POST['category_id']; if((!$productname) || (!$country) || (!$state) || (!$city) || (!$price) || (!$details) || (!$subcategory)) { $errorMsg = "You did not submit the following required information!<br /><br />"; if(!$name){ $errorMsg .= "--- User Name"; } else if(!$country){ $errorMsg .= "--- Country"; } else if(!$state){ $errorMsg .= "--- State"; } else if(!$city){ $errorMsg .= "--- City"; } else if(!$price){ $errorMsg .= "--- Price"; } else if(!$details){ $errorMsg .= "--- Details"; } else if(!$subcategory){ $errorMsg .= "--- Subcategory"; } } } else { "fill the spaces in blank please...";} Thank you.
  11. Duplicate entry '' for key 'name' what could be causing that error? thank you.
  12. I am looking to compare the data-commentid attribute process in javascript after user slideToglle function. I want to compare that value attribute in each interaction with $id variable within the php. if $id = commentid data attribute in the span tag then display the response. I am not sure whether to do the comparison in php or javascript. an example or idea is if(after slideToggle, write a response, submit the form with the response then compare $id == $idc) that would be the sequence. if $id == $idc then display the response and only then. Any idea code I have so far is as below. <?php $id = $_POST['id']; $idc = $_POST ['replyCommentId']; ?> <table width="100%" align="center" cellpadding="4" bgcolor="#CCCCCC" style="margin-bottom:0.5em"> <tr> <td width="auto" height="auto" bgcolor="#EFEFEF" style="vertical-align:top"><a width="auto" height="auto" title="'.$row2["name"] .' "href="profile.php?id='.$uid "></a><br /> </td> <td width="93%" bgcolor="#EFEFEF"><a href="profile.php?id='.$uid.'">' . $ufirstname . ' </a> • <span style="font-size:10px; font-weight:bold; color:#A6A6A6;">' . $message_date . '</span> <br /> <p id="only"> hi how you doing today id=101</p> <span class="comment" data-commentid=<?php "'. $id .'" ?>>•<a style="padding-left:3.5px; color:#0099ff" href ="">Comment</a></span> <div class="commentForm"> <form align="left" id="bring" action="profile.php?id='. $uid .'" method="post" enctype="multipart/form-data" name="message_from"> <textarea name="comment_field_2" type="text" id="text2" rows="3" style="width:100%; height:30px;"></textarea> <input id="bringinput" name="submit" type="button" value="submit" align="left" /> <input type="button" name="replyCommentID" id="replyCommentId" value=""/> </form> </div> </td> </tr> </table> <br/> <table width="100%" align="center" cellpadding="4" bgcolor="#CCCCCC" style="margin-bottom:0.5em"> <tr> <td width="auto" height="auto" bgcolor="#EFEFEF" style="vertical-align:top"><a width="auto" height="auto" title="'.$row2["name"] .' "href="profile.php?id='.$uid "></a><br /> </td> <td width="93%" bgcolor="#EFEFEF"><a href="profile.php?id='.$uid.'">' . $ufirstname . ' </a> • <span style="font-size:10px; font-weight:bold; color:#A6A6A6;">' . $message_date . '</span> <br /> <p id="only"> hi how you doing today id=101</p> <span class="comment" data-commentid=<?php "'. $id .'" ?>>•<a style="padding-left:3.5px; color:#0099ff" href ="">Comment</a></span> <div class="commentForm"> <form align="left" id="bring" action="profile.php?id='. $uid .'" method="post" enctype="multipart/form-data" name="message_from"> <textarea name="comment_field_2" type="text" id="text2" rows="3" style="width:100%; height:30px;"></textarea> <input id="bringinput" name="submit" type="button" value="submit" align="left" /> <input type="button" name="replyCommentID" id="replyCommentId" value=""/> </form> </div> </td> </tr> </table> $(document).ready(function(){ $(".commentForm").hide(); $(".comment").bind('click', function(){ var commentLink = $(this); $(this).nextAll(".commentForm").slideToggle(function(){ $('#replyCommentId', $(this) .parent() .parent()).val(commentLink.data('commentid')); }); return false; }); var html2 = $("#text2").html(); $(".bringinput").click(function() { console.log("AJAX EVENT OCCURED") $.post($('#bring').attr("action"), $("#bring").serialize(), function(html2) { $(html2) .find('form + table').insertAfter('#blab').after('<br />'); }); }); }); jsfiddle http://jsfiddle.net/xysxD/56/
  13. http://jsfiddle.net/xysxD/11/ if you check the jfiddle 1- will have a comment text that slide toggle a response comment 2- the comment text is inside <a> tags 3- how can I let the response comment form know to what parent comment is it responding at the time of sumission? 4- do i have to record that data at the moment it slide toggles or at the submission time?
  14. is it view_login.php You need to address that int he load part in the php class instead of $this->load->view('view_login'); put $this->load->view('view_login.php'); lol
  15. I want to id each comment so that where any member response on a comment, the INSERT and the SELECT knows where to display the responses, to what comment the responses belong to. t. it is like creating an id for each comment so the SELECT display each responses below in its messages. but i don't know if it is an html, php or javascript issue to handle below there are two forms, the parent form and the responses form below each comment form, I want the responses to display below each comment to what it belongs too. I have some tables structure problems and some html issues. the javascript is working for the parent comment it is working perfectly but for the second form the responses form it is not displaying below the comments. <?php $id = $_GET['id']; // this id of the user being commented in the user table I guess I will need that id to identify which user is being commented "profile" that's the id of his profile if (isset($_SESSION['id'])) { $userid = $_SESSION['id']; $username = $_SESSION['name']; } else { // do this } // the userid contains the id and name of the user commenting "the user logged in". if ($_POST['comment_field_1'] != ""){ $comment_field_1 = $_POST['comment_field_1']; $comment_field_1 = stripslashes($comment_field_1); $comment_field_1 = strip_tags($comment_field_1); $comment_field_1 = mysql_real_escape_string($comment_field_1); $comment_field_1 = eregi_replace("'", "&#38;#39;", $comment_field_1); $sql = mysql_query("INSERT INTO comments (mem_id,commented_men_id, the_message,parent_id, message_date) VALUES('$userid','$idc','$comment_field_1', $parent_id now())") or die (mysql_error()); // i guess the $parent_id should be initialize somewhere in the top with a value of 0 or 1 depending weather it is a response or a comment. } // men_id is the field of the $userid, commented_men_id is the field for the commented on, $idc variable etc... if ($_POST['comment_field_2'] != ""){ // responses form field $comment_field_2 = $_POST['comment_field_2']; $comment_field_2 = stripslashes($comment_field_2); $comment_field_2 = strip_tags($comment_field_2); $comment_field_2 = mysql_real_escape_string($comment_field_2); $comment_field_2 = eregi_replace("'", "&#38;#39;", $comment_field_2); $sql = mysql_query("INSERT INTO comments (mem_id,commented_men_id, the_message,sub_commented_id, message_date) VALUES('$userid','$idc','$comment_field_1', $sub_commented_id now())") or die (mysql_error()); // here instead of $parent_id I use field created for responses to tag a comment as a response should be initialize somewhere in the top with a value of 0 or 1 depending weather it is a response or a comment. I am not sure weather I should leave the parent_id variable or come with this new field $sub_commented_id. What do you think? } // men_id is the field of the $userid, commented_men_id is the field for the commented on, $idc variable etc... if (isset($_SESSION['id'])) { if ($_SESSION['id'] == $userid ) { $the_message_form = ' comment (220 char max) <form align="left" id="comment" action="profile.php?id='.$idc.'" method="post" enctype="multipart/form-data" name="message_from"> <textarea type="text" id="text1" name="comment_field_1" rows="3" style="width:97%;"></textarea> <input class="commentinput" name="submit" type="button" value="submit comment" align="left" /> </form>'; } } $sql1 = mysql_query("SELECT id, mem_id, commented_men_id, the_message,parent_id, message_date FROM comments WHERE commented_men_id='$idc' ORDER BY message_date DESC LIMIT 20")or die ( mysql_error () ); $i = 0; while($row = mysql_fetch_array($sql1)){ $j = $i++; $message_id = $row["id"]; $uid = $row["mem_id"]; $the_message= $row["the_message"]; $message_date = $row["message_date"]; $message_date = strftime("%b %d, %Y, %Y %I:%M:%S %p", strtotime($message_date)); $sql_mem_data = mysql_query("SELECT id, name FROM users WHERE id='$uid' LIMIT 1"); while($row2 = mysql_fetch_array($sql_mem_data)){ $uid = $row2["id"]; $ufirstname = $row2["name"]; $ufirstname = mb_strimwidth($ufirstname, 0, 20, '…'); } $messageDisplayList .= ' <table width="100%" align="center" cellpadding="4" bgcolor="#CCCCCC" style="margin-bottom:0.5em"> <tr> <td width="auto" height="auto" bgcolor="#EFEFEF" style="vertical-align:top"><a width="auto" height="auto" title="'.$row2["name"] .' "href="profile.php?id='.$uid .'&name='.$row2["name"].'">' .$user_pic. '</a><br /> </td> <td width="93%" bgcolor="#EFEFEF"><a href="profile.php?id='.$uid.'">' . $ufirstname . ' </a> • <span style="font-size:10px; font-weight:bold; color:#A6A6A6;">' . $message_date . '</span><br /> <p id="only"> ' . $the_message . '</p><span class="comment">•<a style="padding-left:3.5px; color:#0099ff" href ="">Comment</a></span><div class="commentForm"><form align="left" id="bring" action="profile.php?id='. $uid .'" method="post" enctype="multipart/form-data" name="message_from"> <textarea name="comment_field_2" type="text" id="text2" rows="3" style="width:100%; height:30px;"></textarea> <input id="bringinput" name="submit" type="button" value="submit" align="left" /> </form></div> </td> </tr> </table> <br/>'; } $sql_sub_coment = mysql_query ("SELECT id, mem_id, commented_men_id, sub_commented_id, the_message, message_date FROM comments WHERE sub_commented_id='$blabid3' AND sub_commented_id != 0 ORDER BY blab_date DESC LIMIT 20"); while($row3= mysql_fetch_array($sql_sub_coment)){ $$message_id3 = $row3_sub["id"]; $uid3 = $row3_sub["mem_id"] ; $the_message3 = $row3_sub["the_message"]; $message_date3 = $row3_sub["message_date"]; $message_date3 = strftime("%b %d, %Y, %Y %I:%M:%S %p", strtotime($blab_date3)); $sql_mem_data = mysql_query("SELECT id, name FROM user WHERE id='$uid3' LIMIT 1"); while($row4 = mysql_fetch_array($sql_mem_data)){ $uid4 = $row4["category_id"]; $ufirstname2 = $row4["name"]; $ufirstname2 = mb_strimwidth($ufirstname2, 0, 20, '…'); } $$messageDisplayList2 .= '<table width="100%" align="center" cellpadding="4" bgcolor="#CCCCCC" style="margin-bottom:0.5em"> <tr> <td width="auto" height="auto" bgcolor="#FFFFFF"><a width="auto" height="auto" title="'.$row3["name"] .' "href="profile.php?category_id='.$uid4 .'">' .$blabber_pic2. '</a><br /> </td> <td width="93%" bgcolor="#EFEFEF"><a href="profile.php?id='.$uid4.'">' . $ufirstname2 . ' </a> • <span style="font-size:10px; font-weight:bold; color:#A6A6A6;">' . $message_date3 . '</span><br /><p id="submessage">' . $the_message3 . '</p> </td> </tr> </table>'; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <link rel="stylesheet" href="style/style.css" type="text/css" media="screen" /> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $(".commentForm").hide(); $(".comment").bind('click', function(){ $(this).nextAll(".commentForm:first").slideToggle(); return false; }); var html = $("#text1").html(); $(".blabinput").click(function() { console.log("AJAX EVENT OCCURED") $.post($('#comment').attr("action"), $("#comment").serialize(), function(html) { // Find the first table after the form in the HTML from the server and append it to the form on the page. $(html) .find('form + table').insertAfter('#comment').after('<br />'); }); }); var html2 = $("#text2").html(); $(".bringinput").click(function() { console.log("AJAX EVENT OCCURED") $.post($('#bring').attr("action"), $("#bring").serialize(), function(html2) { // Find the first table after the form in the HTML from the server and append it to the form on the page. $(html2) .find('form + table').insertAfter('#bring').after('<br />'); }); }); }); That's what I have so far. the first form the parent form is submitting and posting with the jquery of id #message, then the #bring id for the id of the second form or the response form is not working properly, it is inserting but posting the comment in the p tags with id only., that's where the parent comment post not the response comment form. it should post below but, somehow I have the html and the jquery mess up. Need help in there. the comment text is sliding toggling but the second time I click on, meaning sometimes it won't toggle the first time I click on it. But the main issue now is getting the responses form displaying below and Ajaxing without browser refresh.
  16. Here is the link I am disoriented as how to organize the profile, for instance where to put the map and the comment form...
  17. live site where you can edit and update http://jsfiddle.net/8Ewjq/1/
  18. Ok so far I have gotten all of it, less centering the caption with the image through the parent <a> tags I have tried as below #navigator ul li a { float:left; padding: 0 0 0 0; margin:0 auto 0 1em; } #navigator ul li a p{ padding: 0 0 0 0; margin:0 auto 0 auto; } with no avail.
  19. I know my semantics are not good except for the form, need some help on centering caption and Link to live site
  20. I have come to take the Recursive iterator out and did a print_r to see if there was any value and indeed there is value but echoing that value is the problem, is coming out as an array but i can't get to echo the array. and below that print_r we have the test echoes of <?php echo $value; echo $value['0']; ?> which both echoes return as ArrayArray how can I echo those values in the print_r($iterator); help
  21. I have this query which query the parent.name and the node.name as well. "SELECT parent.name FROM categories AS node, categories AS parent WHERE node.left_node BETWEEN parent.left_node AND parent.right_node AND node.name = '{$node_name}' ORDER BY parent.right_node AND node.left_node" below in the foreach loop is displaying both the node and parent, I only need the parent. I have done a little if statement saying that if node.name not to display but didn't work because both parent.name and node.name are displaying the he same field name. <?php foreach($iterator as $key=>$value) { if($value <> "node.name") echo $value.'<br />'; } ?>
  22. little if condition on within the foreach loop got rid of the depth field if($key <> "depth") { }
  23. Functions file <?php public function getLocalSubNodes($node_name){ $stmt = conn::getInstance()->prepare(" SELECT node.name, (COUNT(parent.name) - (sub_tree.depth + 1)) AS depth FROM categories AS node, categories AS parent, categories AS sub_parent, ( SELECT node.name, (COUNT(parent.name) - 1) AS depth FROM categories AS node, categories AS parent WHERE node.left_node BETWEEN parent.left_node AND parent.right_node AND node.name = :node_name GROUP BY node.name ORDER BY node.left_node )AS sub_tree WHERE node.left_node BETWEEN parent.left_node AND parent.right_node AND node.left_node BETWEEN sub_parent.left_node AND sub_parent.right_node AND sub_parent.name = sub_tree.name GROUP BY node.name HAVING depth <= 1 ORDER BY node.left_node"); $stmt->bindParam(':node_name', $node_name, PDO::PARAM_STR); $stmt->execute(); return $stmt->fetchALL(PDO::FETCH_ASSOC); } ?> I instantiate the class calling the getLocalSubNodes functions <?php $hierachy = new hierachy; $iterator = new RecursiveIteratorIterator(new recursiveArrayIterator($hierachy->getLocalSubNodes($name1))); try { foreach($iterator as $key=>$value) { echo $key.' -- '.$value.'<br />'; } } catch(Exception $e) { echo $e->getMessage(); } ?> resulting in I only want the want to get rid of the depth. in the database I don't have such a field called depth it seems to be generated in the query above, I need the query to calculate the depth but I don't want to print the depth and its value, Don't need the depth and its value to be printed or echo. so I considered it could be the for each loop. not sure if that's the issue here though. thanks.
  24. <?php $hierachy = new hierachy; $iterator = new RecursiveIteratorIterator(new recursiveArrayIterator($hierachy->getLocalSubNodes($name1))); try { foreach($iterator as $key=>$value) { echo $value = substr($value,0,-1).'<br />'; } } catch(Exception $e) { echo $e->getMessage(); }?>
×
×
  • 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.