SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    SitePoint Guru
    Join Date
    Dec 2000
    Location
    Karachi, Pakistan
    Posts
    913
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hello..

    i was learning through julie c. melony's php essentials how to add a record to the database.. actually it is a chapter teaching us how to design a complete book store.

    i am having problems adding a record to the table..

    here is some info:
    db name: shin_omair
    table name: MASTER_PRODUCTS

    and here is the code:

    PHP Code:
    <?php
    if (!isset($PHP_AUTH_USER)) {
    header('WWW-Authenticate: Basic realm="XYZ COMPANY Admin Area"');
    header('HTTP/1.0 401 Unauthorized');
    echo 
    'Authorization Required.';
    exit;
    } else if (isset(
    $PHP_AUTH_USER)) {
    if ((
    $PHP_AUTH_USER != "admin") || ($PHP_AUTH_PW != "xxxxxx")) {
    header('WWW-Authenticate: Basic Realm="XYZ Company Admin Area"');
    header('HTTP/1.0 401 Unauthorized');
    echo 
    'Authorization Reuired.';
    exit;
    } else {
    if ((!
    $isbn) || (!$title) || (!$price)) {
    header("Location: [url]http://www.dayzero.org/omair/admin_addrecord1.php[/url]");
    exit;
    }


    //prepare SQL Statement
    $sql "INSERT INTO MASTER_PRODUCTS VALUES (\"$isbn\", \"$title\", \"author\", \"$publisher\", \"$category\", \"$type\", \"$info_blurb\", \"$page_num\", \"$price\")";

    // create connection
    $connection mysql_connect("localhost","login","password") or die("Could'n connect to the database.");

    //select database
    $db mysql_select_db("shin_omair",$connection) or die ("Could'nt select the database.);

    // execute SQL QUERY AND GET RESULTS
    $sql_result = mysql_query($sql,$connection) or die
    ("
    Could'nt execute query");

    if (!$sql_result) {
    echo "<p>Could'
    nt add record!</p>";
    } else {

    echo "

    <html>
    <
    head>
    <
    title>Add New Product</title>
    </
    head>

    <
    body bgcolor=\"#FFFFFF\" text=\"#000000\">

    <p>&nbsp;</p>
    <p><h1>Product added to the XYZ Company Catalog:</h1></p>
    <p>&nbsp;</p>
    <p>ISBN:&nbsp;&nbsp;&nbsp;&nbsp; 
    $isbn </p>
    <p>Title of the book:&nbsp;&nbsp;&nbsp;&nbsp; 
    $title</p>
    <p>Author's Name:&nbsp;&nbsp;&nbsp;&nbsp; 
    $author</p>
    <p>Publisher:&nbsp;&nbsp;&nbsp;&nbsp; 
    $publisher</p>
    <p>Category:&nbsp;&nbsp;&nbsp;&nbsp; 
    $category</p>
    <p>Type:&nbsp;&nbsp;&nbsp;&nbsp; 
    $type</p>
    <p>Paragraph about the book:&nbsp;&nbsp;&nbsp;&nbsp; 
    $info_blurb</p>
    <p>Number of Pages:&nbsp;&nbsp;&nbsp;&nbsp; 
    $page_num</p>
    <p>Retail Price:&nbsp;&nbsp;&nbsp;&nbsp; 
    $price</p>
    <p align=\"center\">< a href=\"admin_menu.php\">Return to Menu</a></p>
    <p>&nbsp;</p>
    </body>
    </html>

        "
    ;
    }
    }
    }
    ?>
    can you tell me what is the problem ??
    36Host.com - $36/year web hosting [affiliates earn 30%]
    * Affordable Small Business Web Hosting since 2003! *
    "500mb space, 10gb bandwith, 50 pop/ftp accounts, php,
    mysql, pre-installed php scripts, 24/7 support & more...."



  2. #2
    SitePoint Guru
    Join Date
    Dec 2000
    Location
    Karachi, Pakistan
    Posts
    913
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry..
    i forgotted..

    here is the error:

    Parse error: parse error in /home/shin/public_html/omair/admin_addrecord2.php on line 32




    thanks,
    36Host.com - $36/year web hosting [affiliates earn 30%]
    * Affordable Small Business Web Hosting since 2003! *
    "500mb space, 10gb bandwith, 50 pop/ftp accounts, php,
    mysql, pre-installed php scripts, 24/7 support & more...."



  3. #3
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think you forgot to escape a quote on this line

    PHP Code:
    <body bgcolor="#FFFFFF\" text=\"#000000\"> 
    You see it?
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  4. #4
    SitePoint Guru
    Join Date
    Dec 2000
    Location
    Karachi, Pakistan
    Posts
    913
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here is the code again..

    PHP Code:
    <?php
    if (!isset($PHP_AUTH_USER)) {
    header('WWW-Authenticate: Basic realm="XYZ COMPANY Admin Area"');
    header('HTTP/1.0 401 Unauthorized');
    echo 
    'Authorization Required.';
    exit;
    } else if (isset(
    $PHP_AUTH_USER)) {
    if ((
    $PHP_AUTH_USER != "admin") || ($PHP_AUTH_PW != "abc123")) {
    header('WWW-Authenticate: Basic Realm="XYZ Company Admin Area"');
    header('HTTP/1.0 401 Unauthorized');
    echo 
    'Authorization Reuired.';
    exit;
    } else {
    if ((!
    $isbn) || (!$title) || (!$price)) {
    header("Location: [url]http://www.dayzero.org/omair/admin_addrecord1.php[/url]");
    exit;
    }


    //prepare SQL Statement
    $sql "INSERT INTO MASTER_PRODUCTS VALUES (\"$isbn\", \"$title\", \"author\", \"$publisher\", \"$category\", \"$type\", \"$info_blurb\", \"$page_num\", \"$price\")";

    // create connection
    $connection mysql_connect("localhost","shin_omair","ilikefrogs") or die("Couldnt connect to the database.");

    //select database
    $db mysql_select_db("shin_omair",$connection) or die ("Couldnt select the database.);

    // execute SQL QUERY AND GET RESULTS
    $sql_result = mysql_query($sql,$connection) or die
    ("
    Couldnt execute query");

    if (!
    $sql_result) {
    echo "
    <p>Couldnt add record!</p>";
    } else {

    echo "

    <html>
    <
    head>
    <
    title>Add New Product</title>
    </
    head>

    <
    body bgcolor=\"#FFFFFF\" text=\"#000000\">

    <p>&nbsp;</p>
    <p><h1>Product added to the XYZ Company Catalog:</h1></p>
    <p>&nbsp;</p>
    <p>ISBN:&nbsp;&nbsp;&nbsp;&nbsp; 
    $isbn </p>
    <p>Title of the book:&nbsp;&nbsp;&nbsp;&nbsp; 
    $title</p>
    <p>Author's Name:&nbsp;&nbsp;&nbsp;&nbsp; 
    $author</p>
    <p>Publisher:&nbsp;&nbsp;&nbsp;&nbsp; 
    $publisher</p>
    <p>Category:&nbsp;&nbsp;&nbsp;&nbsp; 
    $category</p>
    <p>Type:&nbsp;&nbsp;&nbsp;&nbsp; 
    $type</p>
    <p>Paragraph about the book:&nbsp;&nbsp;&nbsp;&nbsp; 
    $info_blurb</p>
    <p>Number of Pages:&nbsp;&nbsp;&nbsp;&nbsp; 
    $page_num</p>
    <p>Retail Price:&nbsp;&nbsp;&nbsp;&nbsp; 
    $price</p>
    <p align=\"center\">< a href=\"admin_menu.php\">Return to Menu</a></p>
    <p>&nbsp;</p>
    </body>
    </html>

        "
    ;
    }
    }
    }
    ?>

    Thanks,
    36Host.com - $36/year web hosting [affiliates earn 30%]
    * Affordable Small Business Web Hosting since 2003! *
    "500mb space, 10gb bandwith, 50 pop/ftp accounts, php,
    mysql, pre-installed php scripts, 24/7 support & more...."



  5. #5
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You didn't change the line I was talking about.

    PHP Code:
    <body bgcolor="#FFFFFF\" text=\"#000000\"> 
    should be

    PHP Code:
    <body bgcolor=\"#FFFFFF\" text=\"#000000\"> 
    Like I said 5 minutes ago.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  6. #6
    SitePoint Guru
    Join Date
    Dec 2000
    Location
    Karachi, Pakistan
    Posts
    913
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i have done it,
    here is the code again..

    <?php
    if (!isset($PHP_AUTH_USER)) {
    header('WWW-Authenticate: Basic realm="XYZ COMPANY Admin Area"');
    header('HTTP/1.0 401 Unauthorized');
    echo 'Authorization Required.';
    exit;
    } else if (isset($PHP_AUTH_USER)) {
    if (($PHP_AUTH_USER != "admin") || ($PHP_AUTH_PW != "abc123")) {
    header('WWW-Authenticate: Basic Realm="XYZ Company Admin Area"');
    header('HTTP/1.0 401 Unauthorized');
    echo 'Authorization Reuired.';
    exit;
    } else {
    if ((!$isbn) || (!$title) || (!$price)) {
    header("Location: http://www.dayzero.org/omair/admin_addrecord1.php");
    exit;
    }


    //prepare SQL Statement
    $sql = "INSERT INTO MASTER_PRODUCTS VALUES (\"$isbn\", \"$title\", \"author\", \"$publisher\", \"$category\", \"$type\", \"$info_blurb\", \"$page_num\", \"$price\")";

    // create connection
    $connection = mysql_connect("localhost","shin_omair","ilikefrogs") or die("Couldnt connect to the database.");

    //select database
    $db = mysql_select_db("shin_omair",$connection) or die ("Couldnt select the database.);

    // execute SQL QUERY AND GET RESULTS
    $sql_result = mysql_query($sql,$connection) or die("Couldnt execute query");

    if (!$sql_result) {
    echo "<p>Couldnt add record!</p>";
    } else {

    echo "

    <html>
    <head>
    <title>Add New Product</title>
    </head>

    <body bgcolor=\"#FFFFFF\" text=\"#000000\">

    <p>&nbsp;</p>
    <p><h1>Product added to the XYZ Company Catalog/h1></p>
    <p>&nbsp;</p>
    <p>ISBN:&nbsp;&nbsp;&nbsp;&nbsp; $isbn </p>
    <p>Title of the book:&nbsp;&nbsp;&nbsp;&nbsp; $title</p>
    <p>Author's Name:&nbsp;&nbsp;&nbsp;&nbsp; $author</p>
    <p>Publisher:&nbsp;&nbsp;&nbsp;&nbsp; $publisher</p>
    <p>Category:&nbsp;&nbsp;&nbsp;&nbsp; $category</p>
    <p>Type:&nbsp;&nbsp;&nbsp;&nbsp; $type</p>
    <p>Paragraph about the book:&nbsp;&nbsp;&nbsp;&nbsp; $info_blurb</p>
    <p>Number of Pages:&nbsp;&nbsp;&nbsp;&nbsp; $page_num</p>
    <p>Retail Price:&nbsp;&nbsp;&nbsp;&nbsp; $price</p>
    <p align=\"center\">< a href=\"admin_menu.php\">Return to Menu</a></p>
    <p>&nbsp;</p>
    </body>
    </html>

    ";
    }
    }
    }
    ?>
    Last edited by Omair Haroon; May 8, 2001 at 09:58.
    36Host.com - $36/year web hosting [affiliates earn 30%]
    * Affordable Small Business Web Hosting since 2003! *
    "500mb space, 10gb bandwith, 50 pop/ftp accounts, php,
    mysql, pre-installed php scripts, 24/7 support & more...."



  7. #7
    SitePoint Guru
    Join Date
    Dec 2000
    Location
    Karachi, Pakistan
    Posts
    913
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    anybody who can help..


    here is the error!



    Parse error: parse error in /home/shin/public_html/omair/admin_addrecord2.php on line 30



    Thanks,
    36Host.com - $36/year web hosting [affiliates earn 30%]
    * Affordable Small Business Web Hosting since 2003! *
    "500mb space, 10gb bandwith, 50 pop/ftp accounts, php,
    mysql, pre-installed php scripts, 24/7 support & more...."



  8. #8
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's another line with a syntax error - no closing double quotes. Note that I could tell there was a problem with that line - because the colour coding is all wrong in the lines under it (which hinted that a string had not been closed properly).

    $db*=*mysql_select_db("shin_omair",$connection)*or*die*("Could'nt*select*the*database.);

  9. #9
    SitePoint Guru
    Join Date
    Dec 2000
    Location
    Karachi, Pakistan
    Posts
    913
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just checking it out



    Thanks,
    36Host.com - $36/year web hosting [affiliates earn 30%]
    * Affordable Small Business Web Hosting since 2003! *
    "500mb space, 10gb bandwith, 50 pop/ftp accounts, php,
    mysql, pre-installed php scripts, 24/7 support & more...."



  10. #10
    SitePoint Guru
    Join Date
    Dec 2000
    Location
    Karachi, Pakistan
    Posts
    913
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    alas!


    i got it worked..

    all of you! thanks a lot..

    if i had any other problems.. i would surely contact you..
    thanks.
    36Host.com - $36/year web hosting [affiliates earn 30%]
    * Affordable Small Business Web Hosting since 2003! *
    "500mb space, 10gb bandwith, 50 pop/ftp accounts, php,
    mysql, pre-installed php scripts, 24/7 support & more...."



  11. #11
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I also think you have one extra closing bracket at the bottom of the script, also it would help to give us the exact line that the error is on, and not the line number but the actual line.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  12. #12
    SitePoint Guru
    Join Date
    Dec 2000
    Location
    Karachi, Pakistan
    Posts
    913
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    might be..

    but it now works.

    and the only things needed was it to work..
    and if i do something it may not work.. and i dont want that to happen.



    thanks anyway
    36Host.com - $36/year web hosting [affiliates earn 30%]
    * Affordable Small Business Web Hosting since 2003! *
    "500mb space, 10gb bandwith, 50 pop/ftp accounts, php,
    mysql, pre-installed php scripts, 24/7 support & more...."



  13. #13
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thats a pretty lame way of looking at things. I would say its better to learn how something works than to just make it work and hope it doesn't break, so what, when it breaks again you will have to ask again, why not learn how it works first then write the script. I am sure most people who post here would rather know that their valuable time teaching you these concepts will help you to do these things on your own. If all people were doing was fixing your hacked up scripts all day long don't you think it would get kind of old.

    I suggest you learn the basics before trying to write as complex a script as your example. I suggest you start with control structures such as if {} else {} and variable usage.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  14. #14
    SitePoint Guru
    Join Date
    Dec 2000
    Location
    Karachi, Pakistan
    Posts
    913
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    freddy,

    i have some other kind of concept..

    well, i use to learn by copying some difficult sort of scripts..

    that way its more clear that what every function do..
    as well as, you get an idea what can you do with the respective language..

    hope that clears up my concept..
    everyone learns its own way.. so do I.

    thanks,
    36Host.com - $36/year web hosting [affiliates earn 30%]
    * Affordable Small Business Web Hosting since 2003! *
    "500mb space, 10gb bandwith, 50 pop/ftp accounts, php,
    mysql, pre-installed php scripts, 24/7 support & more...."




Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •