Jump to content

HDFilmMaker2112

Members
  • Posts

    547
  • Joined

  • Last visited

    Never

Posts posted by HDFilmMaker2112

  1. Do you mean you're looking to put live stock quotes into a php-based stock market game? And you're asking how to get those stock prices? If so, you're looking at needing to contact the NYSE and NASDAQ (or other markets)... You'll probably have to pay a fee for live streaming quotes from each market, and then figure out how to ingest them into the php script, from what ever format they give you.

  2. Here's the way I do validation:

     

    When the user submits the form it is submitted to a new page, on that page:

    $name=$_POST['name'];
    if($name==""){
    $error0=1;
    }
    else{
    $error0=0;
    }
    

     

    Do the above for each item you want to validate. Incrementing the number after error in the $error variable.

     

    i.e; $error0,$ error1, $error2, ect.

     

    Once you review each form item forward the user back to the form or to your thank you page, via a header redirect.

    if($error!=="0000000"){
    header("Location: ./request_more_info.php?error=".$error0."".$error1."".$error2."".$error3."".$error4."".$error5."".$error6."");
    }
    else{
    header("Location: URL for thank you page");
    

     

    To alter the above you would have to take the total amount of form items you are validating, and place that amount of "0" in this:

    if($error!=="0000000"){
    

     

     

    And then on your initial submitting form:

     

    $error=$_GET['error'];
    <p><label>Name:</label> <input type="text" name="name" size="30"  />';
    if($error[0]==1){ $content.=' <span class="red bold">This field is required.</span>'; }
    $content.='</p>
    

     

    So your flow is essentially:

     

    submitting form ----> process/validate form

     

    if errors, redirect back to submitting form with error=error code in URL

    else, no errors, forward to thank you page

     

     

    You'll need to alter this above code to suit your needs better, especially the CSS class calls and what not.

  3. If you're setting the $_SESSION['cart'] variable with that information, then you shouldn't be getting an error saying that it isn't set. Can we see the code that sets that information into the $_SESSION['cart'] variable? From the code you posted, I don't see that information being placed in the variable.

  4. How should I set it...???

     

    Sould I use something like:

    if(isset($_SESSION["cart"]))
    {
           $cart = $_SESSION["cart"];
    }

    Thank you

     

    What is the purpose of your $_SESSION['cart'] variable? What data should it be holding? Should it be holding all of the items added to the cart?

  5. Well first, do you have any more column in those tables, because I'd just use * instead of calling each individual column.

     

    SELECT * FROM  #__comprofiler AS c, #__users AS u  WHERE (c.user_id = u.id,  c.confirmed = '1', c.approved = '1', c.banned = '0', c.avatar NOT LIKE 'NULL'),(u.usertype = 'author', u.block = '0') ORDER BY lastupdatedate DESC 
    

     

    Try that with adding the LIMIT after.

     

    I maybe off, as this is not my strongest coding area, but if somebody else doesn't answer for a while, it's at least worth a try.

  6. The following mysql update isn't updating the database.

    $tbl_name="products"; // Table name 1
    $tbl_name2="keywords"; // Table name 2
    
    $product_id=$_POST['product_id'];
    $product_name=$_POST['product_name'];
    $product_price=$_POST['product_price'];
    $product_category=$_POST['product_category'];
    $product_link=$_POST['product_link'];
    $product_image=$_POST['product_image'];
    $product_tag=$_POST['product_tag'];
    $keywords=$_POST['keyword'];
    $keywords=explode(",",$keywords);
    $product_features=$_POST['product_features'];
    $product_pros=$_POST['product_pros'];
    $product_cons=$_POST['product_cons'];
    $product_description=$_POST['product_description'];
    $product_notes=$_POST['product_notes'];
    
    $sql20="UPDATE $tbl_name product_name=$product_name, product_price=$product_price, product_category=$product_category, product_link=$product_link, product_image=$product_image, product_tag=$product_tag, product_features=$product_features, product_pros=$product_pros, product_cons=$product_cons, product_description=$product_description, product_notes=$product_notes WHERE product_id = $product_id";
    mysql_query($sql20);
    

  7. I'm looking to know if MySQL or PHP would cause problems if a database entry has a space in the beginning of it.

     

    Say I have a two entries in a DB.

     

    "Test"

    and

    " Test" *space before T.

     

    If one of my users does a search for "Test" would it also return the result of " Test"?

     

  8. The below generates an error of: Warning: implode() [function.implode]: Invalid arguments passed in /home/zyquo/public_html/ghosthuntersportal.com/admincp.php on line 74

     

    $product_id=$_GET['id'];
    $sql300="SELECT * FROM keywords WHERE keywords.product_id=".$product_id."";
    $result300=mysql_query($sql300);
    while($row300=mysql_fetch_array($result300)){
    $keyword.=$row300['keyword'];
    }
    $keyword=implode(",",$keyword);
    
    <p><label>Product Keywords:</label> <input type="text" name="keyword" value="'.$keyword.'" size="30" /></p>
    

     

    When I remove the implode, the input value is populated with the information, it just doesn't have commas in between each keyword.

     

    EDIT: Wrong forum... please move to PHP Coding Help.

  9. Here's my table:

     

    product_id | product_name | product_category | product_tag | product_link | product_price

    2 | test | test | test | test | 1

    3 | test2 | test2 | test2 | test2 | 2

    4 | test2 | test | test | test | 12

     

    EDIT:

    Just realized my issue, I needed to concatenate  the $content variable because it's looping... it was just taking the last entry because it kept overwriting the $content variable from the last loop.

    code is now:

    if(isset($_GET['cat'])){
    $cat=$_GET['cat'];
    $sql30="SELECT * FROM $tbl_name WHERE product_category='$cat'";
    $result30=mysql_query($sql30);
    while($row30=mysql_fetch_array($result30)){
    $content.=$row30['product_category'];
    }
    }
    

     

  10. The following code is returning only one row, when  I know for a fact there are two entries with same product_category in the database. Maybe I'm just missing something blatantly obvious, but I'm not seeing an error in the code.

     

    if(isset($_GET['cat'])){
    $cat=$_GET['cat'];
    $sql30="SELECT * FROM $tbl_name WHERE product_category='$cat'";
    $result30=mysql_query($sql30);
    while($row30=mysql_fetch_array($result30)){
    $content=$row30['product_category'];
    }
    }
    

  11. I have products listed in my database, I need the following to edit that information. The product information itself is fairly straight forward, but when it comes to editing the keywords (for user searches of products), I'm not sure of how to go about it.

     

    Here's what I have right now:

    <?php
    $keywords=$_POST['keyword'];
    $keywords=explode(",",$keywords);
    
    $sql20="UPDATE $tbl_name product_name=$product_name, product_price=$product_price, product_category=$product_category, product_link=$product_link, product_image=$product_image, product_tag=$product_tag, product_features=$product_features, product_pros=$product_pros, product_cons=$product_cons, product_description=$product_description, product_notes=$product_notes WHERE product_id = $product_id";
    mysql_query($sql20);
    
    $ValuePart = array();
    foreach($keywords as $keyword){
    $ValuePart[] = "keyword=$keyword";
    }
    
    if (count($ValuePart) > 0 ) {
    $sql24="UPDATE $tbl_name2 SET" . implode(',',$ValuePart). "WHERE product_id=".$product_id;
    mysql_query($sql24) or die(mysql_error());
    } 
    header("Location: ./admincp.php?edited=yes");
    
    ?>
    

     

    Am I going in the wrong direction with the keywords update? It would seem that if I do it the way I have it right now, if I have the following:

    a,b,c,d,e,f,g

     

    and update it to:

    a,c,e,f,g

     

    That the database would end up with duplicate entries. How should i combat this? I need a way to delete rows when the update reduces the amount of keywords, add entries when the update increases the amount of keywords, and just alter the existing entries when the amount of keywords stay the same.

     

  12. why are you using 2 id's for the table keywords?... doesn't make sense to me... but of course I can be wrong understanding that part of your objectives.

     

    What do you mean by 2 ids?

     

    I have one for product_ids and one for keyword_ids

     

    so my table looks like this:

     

    keyword_id | keyword | product_id

    1 |test | 1

    1 |test | 4

    2 |test2 | 1

    2 |test2 | 5

    3 |test3 | 2

    3 |test3 | 3

    ect.

     

    I also had to add a fourth column to free up keyword_id to permit duplicate entries. So that fourth column is now the primary key.

  13. I'm kind of lost... for better help, could you explain what exactly are you trying to do... seems to me that: (correct me if I understood incorrectly)

    - You are capturing products and associated information.

    - Part of that additional information seems to be a series of "keywords" that in some way could help to describe that specific product

    - Next you want to create the record in the table product  and along with that also insert all the "keywords" associated to that product in the table "keywords"

     

    Did I understand your objective correctly?

     

    That is indeed what I was trying to accomplish, and I just managed to get it to work 2 minutes ago.

  14. Well after some research it seems like my problem is that keyword_id is the primary key in the table. So I created a new column and made that the primary key, freeing up the keyword_id.

     

    But I have a new issue now. In order to generate a new keyword_id for a keyword that is new in the table, I need to get the current max keyword_id and increment by 1.

     

    else{
    $sql15="SELECT MAX(keyword_id) FROM keywords";
    $result15=mysql_query($sql15);
    while($row15=mysql_fetch_array($result15)){
    $max_keyword_id=$row15['keyword_id'];
    $keyword_id=$max_keyword_id++;
    }
    $sql14="INSERT INTO $tbl_name2 (keyword_id,keyword,product_id) VALUES ('$keyword_id','$keyword','$product_id2')";
    mysql_query($sql14);
    }
    

     

    when I run the above it generates a keyword_id of 0, it should be 6 as the highest keyword_id in the table is 5.

  15. Alright, that solved the mysql error. Now, the problem is, if the keyword already exists, it is not being added to the database. I just added a new product with an existing keyword, and it submitted to the products table, but nothing was added to the keywords table... No entry with a new keyword_id nor a new entry with the same keyword_id.

     

    Just wanted to provide some additional details, if this makes any difference:

     

    keyword_id is structured as an int(11) field with Auto_Increment.

  16. HI HD

     

    thanks for your help, I have tried your reply but I am getting an error 1054 unknown column table1.title in where clause

     

    I have made sure that the tables have all the required fields

     

    did you replace table1 and table2 with your actual table names? or are they actually called table1 and table2?

  17. Alright, that solved the mysql error. Now, the problem is, if the keyword already exists, it is not being added to the database. I just added a new product with an existing keyword, and it submitted to the products table, but nothing was added to the keywords table... No entry with a new keyword_id nor a new entry with the same keyword_id.

  18. Thanks for the reply, but unfortunatly that doesnt really mean much to me!

     

    Would you care to ellaborate?

     

    I'm assuming they mean each side of link aka friendship.

     

    I.e;

     

    person 1 | person 2

    a | b

    a | c

    a | d

    b | d

    c | d

     

    ect.

  19. I'm having a few issues with the following code:

     

    <?php
    $host="localhost"; // Host name 
    $username="username"; // Mysql username 
    $password="password"; // Mysql password 
    $db_name="zyquo_ghp"; // Database name 
    $tbl_name="products"; // Table name 1
    $tbl_name2="keywords"; // Table name 2
    
    // Connect to server and select databse.
    mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
    mysql_select_db("$db_name")or die("cannot select DB");
    
    $product_name=$_POST['product_name'];
    $product_price=$_POST['product_price'];
    $product_category=$_POST['product_category'];
    $product_link=$_POST['product_link'];
    $product_image=$_POST['product_image'];
    $product_tag=$_POST['product_tag'];
    $keywords=$_POST['keyword'];
    $keywords=explode(",",$keywords);
    $product_features=$_POST['product_features'];
    $product_pros=$_POST['product_pros'];
    $product_cons=$_POST['product_cons'];
    $product_description=$_POST['product_description'];
    $product_notes=$_POST['product_notes'];
    
    if($_GET['do']=="edit"){
    }
    elseif($_GET['do']=="add"){
    $sql10="INSERT INTO $tbl_name (product_name, product_price, product_category, product_link, product_image, product_tag, product_features, product_pros, product_cons, product_description, product_notes) VALUES ('$product_name', '$product_price', '$product_category', '$product_link', '$product_image', '$product_tag', '$product_features', '$product_pros', '$product_cons', '$product_description', '$product_notes')";
    mysql_query($sql10);
    $sql11="SELECT product_id FROM $tbl_name WHERE product_name='".$product_name."'";
    $result11=mysql_query($sql11);
    while($row11=mysql_fetch_array($result11)){
    $product_id2=$row11['product_id'];
    foreach($keywords as $keyword){
    $sql13="SELECT keyword_id FROM $tbl_name2 WHERE keyword='".$keyword."'";
    $result13=mysql_query($sql13);
    $row13=mysql_fetch_array($sql13);
    $keyword_id=$row13['keyword_id'];
    if(mysql_num_rows($result13) != 0){
    $sql12="INSERT INTO $tbl_name2 (keyword_id,keyword,product_id) VALUES ('$keyword_id','$keyword','$product_id2')";
    mysql_query($sql12);
    }
    else{
    $sql14="INSERT INTO $tbl_name2 (keyword,product_id) VALUES ('$keyword','$product_id2')";
    mysql_query($sql14);
    }
    }
    }
    }
    else{
    }
    ?>
    

     

    It should be taking a list of keywords coming from the form on the previous page (in a,b,c,d, ect. list form), breaking them up and putting them into a $keywords array. From there, it should be looping through each keyword, under the foreach statement, until it runs out of keywords. Under the foreach statement, it should be checking to see if the keyword is already in the database; and if not, create a new entry with a new keyword_id. If is already in the database add another entry with same keyword_id.

     

    Now for what it's actually doing. It seems to be looping through once (I am only adding one keyword right now, so this makes sense) but it throws an error:

     

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result on line 39

     

    Line 39 is: $row13=mysql_fetch_array($sql13)

     

    It does add the information to the database while it throws that error. However, it doesn't seem to detect that the keyword is already in the database, so it creates a new keyword_id when it should take the existing id for the existing keyword in the database.

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