--- HELP!!: "insert statement" in PHP ---

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • newbie_mw

    #1

    --- HELP!!: "insert statement" in PHP ---

    Seems my post was buried in more cries for help :-) I will try again.
    It's probably a very novice question so please take a look! Thanks!
    -----------------------------------------------------------------

    I created a sign-up sheet (reg.html) where people fill in their first
    name, last name, email, etc. The data are then sent to a PHP script
    (reg.php). The data are then inserted into a table (reg) in MS SQL
    server. I have declared the variables like this:

    The columns and variables are exactly matched so it shouldn't be the
    problem. The error message to the below script is:
    ~~~~~~~~~~~~~~~ ~~~~~~~
    call someoneDB Error:
    Warning: mssql_num_rows( ): supplied argument is not a valid Sybase
    result
    resource ...
    ~~~~~~~~~~~~~~~ ~~~~~~~~~

    Even when I deleted the mssql_num_rows( ) stuff, it still doesn't work.
    The error message then said: "DB error".

    The (almost) full script is here:

    <?php

    // some MS SQL server connection thing that I can't show here :-) //

    if (!(isset($_POST['FirstName']))) {
    $FirstName = "" ;
    } else {
    $FirstName = $_POST['FirstName'] ;
    }

    if (!(isset($_POST['LastName']))) {
    $LastName = "" ;
    } else {
    $LastName = $_POST['LastName'] ;
    }

    if (!(isset($_POST['Email']))) {
    $Email = "" ;
    } else {
    $Email = $_POST['Email'] ;
    }

    if(empty($First Name) OR empty($LastName ) OR empty($Email))

    {
    echo "Oops, you must complete the form to register. Please use the
    browser
    back button to go back and complete the form.";
    echo "</body></html>";
    exit;
    }

    $qry = "insert into reg values (";
    $qry = $qry."'$FirstNa me'";
    $qry = $qry.",'$LastNa me'";
    qry = $qry.",'$Email' ";
    $qry = $qry.")";

    $rs=$db->query ($qry);
    if (DB::iserror($r s)){print"call someone"; print $rs->getMessage() ;}

    $result = mssql_query("SE LECT * FROM reg");
    $num_rows = mssql_num_rows( $result) ;

    if ($num_rows > 10)
    {
    echo "Sorry, our registration is full. Please stay tuned till the next

    one.";
    }

    else
    {
    echo "Congratulation s, $FirstName! Your have registered for --- ";
    echo "<p>";
    }

    ?>

    Hope it is clearer now. What's most frustrating is that it worked for a
    while,
    but now it is messed up.

    I also tried another "insert" statement that goes like this:
    $qry = "insert into reg values ('$FirstName',' $LastName','$Em ail')";

    However, this doesn't work either. I looked into examples online, but
    none of those "insert into" statements handle varibles (they all insert
    actual values such as "Hanna, Smith, hs@yahoo.com', etc.)

    Newbie



  • newbie_mw

    #2
    ignore this Re: --- HELP!!: &quot;insert statement&quot; in PHP ---

    I just found out what the problem is so please ignore this post! It was
    rather stupid (I didn't set the right permission on the user for the table).
    Thanks for your help Ian!

    Newbie

    newbie_mw wrote:
    [color=blue]
    > Seems my post was buried in more cries for help :-) I will try again.
    > It's probably a very novice question so please take a look! Thanks!
    > -----------------------------------------------------------------
    >
    > I created a sign-up sheet (reg.html) where people fill in their first
    > name, last name, email, etc. The data are then sent to a PHP script
    > (reg.php). The data are then inserted into a table (reg) in MS SQL
    > server. I have declared the variables like this:
    >
    > The columns and variables are exactly matched so it shouldn't be the
    > problem. The error message to the below script is:
    > ~~~~~~~~~~~~~~~ ~~~~~~~
    > call someoneDB Error:
    > Warning: mssql_num_rows( ): supplied argument is not a valid Sybase
    > result
    > resource ...
    > ~~~~~~~~~~~~~~~ ~~~~~~~~~
    >
    > Even when I deleted the mssql_num_rows( ) stuff, it still doesn't work.
    > The error message then said: "DB error".
    >
    > The (almost) full script is here:
    >
    > <?php
    >
    > // some MS SQL server connection thing that I can't show here :-) //
    >
    > if (!(isset($_POST['FirstName']))) {
    > $FirstName = "" ;
    > } else {
    > $FirstName = $_POST['FirstName'] ;
    > }
    >
    > if (!(isset($_POST['LastName']))) {
    > $LastName = "" ;
    > } else {
    > $LastName = $_POST['LastName'] ;
    > }
    >
    > if (!(isset($_POST['Email']))) {
    > $Email = "" ;
    > } else {
    > $Email = $_POST['Email'] ;
    > }
    >
    > if(empty($First Name) OR empty($LastName ) OR empty($Email))
    >
    > {
    > echo "Oops, you must complete the form to register. Please use the
    > browser
    > back button to go back and complete the form.";
    > echo "</body></html>";
    > exit;
    > }
    >
    > $qry = "insert into reg values (";
    > $qry = $qry."'$FirstNa me'";
    > $qry = $qry.",'$LastNa me'";
    > qry = $qry.",'$Email' ";
    > $qry = $qry.")";
    >
    > $rs=$db->query ($qry);
    > if (DB::iserror($r s)){print"call someone"; print $rs->getMessage() ;}
    >
    > $result = mssql_query("SE LECT * FROM reg");
    > $num_rows = mssql_num_rows( $result) ;
    >
    > if ($num_rows > 10)
    > {
    > echo "Sorry, our registration is full. Please stay tuned till the next
    >
    > one.";
    > }
    >
    > else
    > {
    > echo "Congratulation s, $FirstName! Your have registered for --- ";
    > echo "<p>";
    > }
    >
    > ?>
    >
    > Hope it is clearer now. What's most frustrating is that it worked for a
    > while,
    > but now it is messed up.
    >
    > I also tried another "insert" statement that goes like this:
    > $qry = "insert into reg values ('$FirstName',' $LastName','$Em ail')";
    >
    > However, this doesn't work either. I looked into examples online, but
    > none of those "insert into" statements handle varibles (they all insert
    > actual values such as "Hanna, Smith, hs@yahoo.com', etc.)
    >
    > Newbie[/color]

    Comment

    Working...