By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,746 Members | 1,924 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,746 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.