Jump to content

Hussam

Members
  • Posts

    63
  • Joined

  • Last visited

    Never

Posts posted by Hussam

  1. ok, I think this is a database question, but anyway:

     

    to show all products and the features simply you can use this simple query:

     

    $query = "SELECT * FROM products"

     

    To select only the products that a certain customer is using then you basically mean by that:

    each customer can select many product(s)

    each product can be selected by many customer(s)

     

    here you need to add another table named customer_product that has two fields:

    customer_id

    product_id

    they have the id's of the customers and the products attached to each other and attach the other two tables to them in your queries.

    the table should look like this after inserting some records:

    customer_id: 2  4  5    2

    product_id:  5  1  2    1

     

    means the customer number 2 took the products number 5 and 1

    the product number 1 was taken by the customers numbered 2 and 4

     

    I don't really know any tutorial that explains this, but I think I explained it clearly, if not then let me know what is hard to understand and I will explain it to you.

     

    Good luck!

  2. This way I think you better make a separate replies table like this:

     

    table: replies:

    id ---> the reply id itself, auto increment.

    base_comment_id ---> the id of the base comment.

    replyTo_id ---> has the id that it is a reply to it, or 0 if its a base comment.

    text ----> the reply's test

     

    I think this way you can have unlimited replies to each other and you can intend from VA to AK lol.

     

    I can't think more of it, its kinda confusing lol.

  3. I think you can't expect much answers from people with this kind of question:

     

    The code is missing alot of things as far as I am concerned, there should be a class file and other code seems to be missing, also try to put your code in php bbcode tags in the forum so we can see better.

     

    The first thing I can see wrong, is using methods of a class without instantiating an object from the class, unless you did that somewhere else in the code and didn't post it.

    $database->setQuery($query);
    $database->query();
    

    good luck!

     

  4. For portability reasons (ability to move your application to different database systems) backticks should NOT be used (because (1) they're not part of stadard SQL, and (2) it forces you to give sensible names to your tables/columns)

     

    This should be enough for these clumsy backticks to not to be used.

     

    I own you one Mchl.

  5. what if you have a table called "from"? a statement like "SELECT * FROM from" will not execute. "SELECT * FROM `from`" would work.

     

     

    I doubt it if you can name a table "from", I think "from" is a reserved word in MySQL, therefore your example is not even right to begin with.

     

    Do you doubt this from your extensive knowledge of databases and in particular mysql? Please. Why don't you try it yourself. "create table `from`(test int primary key)". That's exactly why you would use ` because IT IS A RESERVED WORD.

     

     

    excuse me, my knowledge is not extensive in SQL, I have not written any SQL statement in ages, however, why would a reasonable programmer give a table such name? a reversed word? don't tell me that he ran out of words lol.

     

    This way he is forcing himself to use this ` in each and every statement in his SQL's which sucks.

     

    Anyway, you need to take care of millions of web sites that have their SQL's without ` and convience them all to rewrite their code or look for every piece of SQL in their code.

     

    good luck for those who want to put ` in their SQL, I promise I won't put any lol, in fact I don't even write SQL's but even if I have to, I won't because its ridiculous. 

  6. your questions has been answered correctly, however your query will not work because its wrong.

     

    use this one:

     

    $query = "insert into orders (email, zip) values ('$purchase_email', '$zip')";

     

    dont worry about the concatenation in this case, the query will work this way, no need to litter the code with quotes in this case.

     

    By the way, I love people who know how to ask the question like you did lol.

     

    good luck!

  7. what if you have a table called "from"? a statement like "SELECT * FROM from" will not execute. "SELECT * FROM `from`" would work.

     

    I doubt it if you can name a table "from", I think "from" is a reserved word in MySQL, therefore your example is not even right to begin with.

     

    For the future, if this thing happens in the later versions of MySQL, people won't use it and it will fail because people will stick to the older version because their sites are coded without ` so they are not going to go to each and every SQL statement and add this ` to each and every field and table, this is ridiculous.

     

    Even if they did that, then they will be repeating the same mistake with XHTML 1.1 and XTHML 2.0

     

    cheers!

  8. okay guys, the problem is solved and everything was tested and its all working fine on the server.

     

    I had to change the names of the fields a little bit, I like to follow the conventions.

    reply_id in the replies table was changed to id

    comment_id in the user_comments table was changed to id

     

    both of them are auto increment and primary key's

     

    Now the problem was:

    the condition on top

    if (isset($_POST['submit']))

    this condition  makes the page instantiate the values AFTER the submission not before.

    after the submission there is no GET values.

    so I added the GET value to the action attribute of the form

    therefore I have the GET values anyway, if the form is submitted or not.

    and that won't be a problem after the submission because there is redirection anyway.

     

    the code should be like this:

     

    <?php
    $comment_id = $_GET['comment_id'];
    //
    //echo $comment_id;
    //
    //exit();
    
    //connect to server and select database
    $conn = mysql_connect("localhost", "webdes17_twilite", "minimoon")
        or die(mysql_error());
    $db = mysql_select_db("webdes17_testimonials", $conn) or die(mysql_error());
    
    if (isset($_POST['submit'])) {
    
    //create and issue the first query
    $name=mysql_real_escape_string($_POST['comment_owner']);
    $email=mysql_real_escape_string($_POST['comment_owner_email']); 
    $reply=mysql_real_escape_string($_POST['reply']);
    $comment_id = $_GET['comment_id'];
    
    $error='';//initialize $error to blank
      if(trim($name)=='' ){
          $error.="Please enter your name!<br />"; //concatenate the $error Message with a line break
      }
       if(trim($email)==''){
        $error.="Plese enter your e-mail address!<br />";
        
      }  elseif (!preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", $email)) {
    
            $error.="The e-mail you entered was not valid!<br />";
            
        }
        if(trim($reply)=='' ){
          $error.="Please enter your reply!<br />"; //concatenate the $error Message with a line break
      }
      if($error==''){
    
    
    $sql="INSERT INTO replies (comment_id, reply, reply_create_time, reply_owner, reply_owner_email) VALUES ( '$comment_id', '$reply', now(), '$name','$email')"; 
      
    mysql_query($sql,$conn) or die(mysql_error());
    
    header('Location: testimonials.php');
    
      // mysql_query($sql,$conn) or die(mysql_error());
      }
        else{
           echo "<div class=error><span style=color:red>$error</span><br /></div>";
        }    
    } else {
    
    $name= '';
    $email= '';
    $reply= '';
    }
    ?>
    <form name="comment" id="comment" onsubmit="return validateFormOnSubmit(this)" action="reply.php?comment_id=<?php echo $comment_id; ?>" method="post">
    <table border="0" cellspacing="0" cellpadding="5" width="662" class="style2">
    <tr>
    <td align="left"><label for="name"> Name:</label></td>
    <td>
    <div class="c2"><input type="text" name="comment_owner" id="comment_owner" size="30" value="<?php echo $name; ?>"/></div></td>
    </tr>
    <tr>
    <td align="left"><label for="email">E-mail:</label></td>
    <td>
    <div class="c2"><input type="text" name="comment_owner_email" id="comment_owner_email" size="30" value="<?php echo $email; ?>"/></div></td>
    </tr>
    <tr>
    <td align="left">
    <label for="reply">Reply:</label></td>
    <td>
    <textarea name="reply" id="reply" rows="5" cols="30" value="<?php echo $reply; ?>"></textarea></td>
    </tr>
    <tr>
    <td colspan="4">
    <div class="c1"><input name="submit" type="submit" value="Submit" /> <input type="reset" name="reset" id="reset" value="Reset" /></div></td>
    <td width="2"></td>
    </tr>
    </table>
    </form>

     

    not very clean but tested and working!

     

    good luck!

     

     

  9. I tried echoing the comment id like this and it worked:

     

    I added this right after the first php tag at the beginning and it printed the right comment_id.

     

     

    echo $_GET['comment_id'];

     

     

    Great, retry to post it again and send me the exact code that is printing the right comment_id.

     

    send me both pages with their name in the top.

     

    Thanks,

    Hussam

     

  10. why not use a hidden input for comment_id  within the form  that way it passes right  8)

     

    This will pass the comment_id onto the same page:

     <form method="post" action="$_SERVER["PHP_SELF"]">
    
    
    <input type="hidden" name="<?= $_GET["comment_id"] ?>"></form>

     

    you can do that but you need php tags around the form action value and single quotes for the array index, but anyway this won't solve the problem because the $_GET array is showing that its empty in the page.

  11. I know it is getting the comment_id because I tried echoing it and it is getting it, so I can't figure out why I can't insert it???

     

    I don't think that we could echo $_GET['comment_id'] and also when we tried to echo out the $_GET array, it was an empty array, so the value is not in the $_GET array to begin with.

  12. oh nevermind your passing it to the same page in that case i would use

     

    $_REQUEST['comment_id']

     

    well, the array $_GET is a part of the array $_REQUEST, if the index doesn't exist in $_GET then it certainly doesn't exist in $_REQUEST unless its in $_POST or $_COOKIE but its not in any of them.

     

    I am not sure if you can use $_SESSION in this case because she needs a way to save a certain id in the session before leaving the first page, you need to modify the code in the other page to save the id in the session then you can do it.

  13. its not possible but I am imagining an idea, may be it is possible to do something similar to that and doesn't cost money, which is giving them a sub domain.

     

    like, say your site domain is:

    domain.com

     

    you might be able to give them something like this:

    name@company.domain.com

     

    sub domains are free, most hosts provide unlimited sub domains for free with any hosting plan.

     

    giving them a domain as you mentioned is not possible at all.

     

    good luck!

     

     

    If you continue on that you could keep domain short for example: user@hisdomain.z.com

     

    Great thought, but getting a short domain is something really hard, I think all of them are already taken, may be you can combine a letter with numbers and give it a try.

  14. its not possible but I am imagining an idea, may be it is possible to do something similar to that and doesn't cost money, which is giving them a sub domain.

     

    like, say your site domain is:

    domain.com

     

    you might be able to give them something like this:

    name@company.domain.com

     

    sub domains are free, most hosts provide unlimited sub domains for free with any hosting plan.

     

    giving them a domain as you mentioned is not possible at all.

     

    good luck!

     

  15. OMG, this is overwhelming.

     

    I don't think that it has any thing to do with PHP_SELF, because it will return the same page file name, I told you to put that just in case you wanted to reuse the code in a different page or rename the page, so you dont have a problem.

     

    try to take if off and see what happens.

×
×
  • 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.