467,927 Members | 1,868 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,927 developers. It's quick & easy.

--- 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($FirstName) 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."'$FirstName'";
$qry = $qry.",'$LastName'";
qry = $qry.",'$Email'";
$qry = $qry.")";

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

$result = mssql_query("SELECT * 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 "Congratulations, $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','$Email')";

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

Jul 16 '05 #1
  • viewed: 4183
Share:
1 Reply
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:
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($FirstName) 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."'$FirstName'";
$qry = $qry.",'$LastName'";
qry = $qry.",'$Email'";
$qry = $qry.")";

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

$result = mssql_query("SELECT * 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 "Congratulations, $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','$Email')";

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


Jul 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Tom | last post: by
4 posts views Thread by Sarir Khamsi | last post: by
2 posts views Thread by Sudheer Kareem | last post: by
6 posts views Thread by wukexin | last post: by
6 posts views Thread by d.warnermurray | last post: by
5 posts views Thread by Craig Keightley | last post: by
reply views Thread by tbatwork828 | last post: by
3 posts views Thread by Colin J. Williams | last post: by
2 posts views Thread by BT Openworld | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.