Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create Update statement on Post 1

Status
Not open for further replies.

lanm

Programmer
Jul 7, 2005
244
US
I need to update a field on a Submit click event. I've tried using the Server Behavior for the Update, but it's not going to work for me. I need to be able to do it by hand.

I see the following for select statements using the Server Behaviors:

mysql_select_db($database_conn, $conn);
$query_rsFind = sprintf("SELECT videoseen FROM table1 WHERE Znumber = %s", $colname_rsFindvideoseen);

I tried to do mysql_update_db($database_conn, $conn);
...but the namespace for mysql_update_db doesn't look valid
 
Server Behavior"?
mysql_update_db()?

I have no idea what a Server Behavior is. But I do know that the function mysql_update_db() does not appear in the PHP online manual.

If you mean to update the data in a MySQL database, create an UPDATE query and pass that query to mysql_query().


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
sleipnir214!
Thanks again for the help! This is the last thing I need.

I've got the following, but with syntax errors of

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\ on line 88


If ($totalRows_Recordset2==1 AND $_POST['Password']==$Password)
{echo $IDFound;}
mysql_query("Update table1 set videoseen=1 Where ZNumber = $_POST['ZNumber']");
 
It's your attempt to create your query:

mysql_query("Update table1 set videoseen=1 Where ZNumber = $_POST['ZNumber']");

Notice that you have a reference to a superglobal variable element, specifically $_POST['ZNumber'], inside quotes. PHP doesn't like the quotes within quotes thing.

Instead, do explicit string concatenation with the "." operator:

mysql_query("Update table1 set videoseen=1 Where ZNumber = " . $_POST['ZNumber']);

instead of an interpolated string, you have the concatenation of a string literal and a string variable.


Also, do not use the AND operator in conditions:

If ($totalRows_Recordset2==1 AND $_POST['Password']==$Password)

PHP supports two logical-AND operators, "&&" and "AND". The difference between the two is that "&&" has a much higher precedence than "AND". If you use "AND" in a condition, you can run into subtle and difficult-to-debug errors.




Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Thanks sleipnir214!

I'm using:

If ($totalRows_Recordset2==1 && $_POST['Password']==$Password)
{echo $IDFound;}
{
#Do the update of videoseen
#1st make the connection
$conn = mysql_connect ('localhost','usr','pwd');
#now select the db
mysql_select_db ("videocheck");
mysql_select_db($database_conn, $conn);
$ZNumber = $_POST['ZNumber'];
$sqlUpdate = sprintf("Update table1 set videoseen=1 Where ZNumber = ".$_POST['ZNumber']);
$rsUpdate = mysql_query($sqlUpdate, $conn) or die(mysql_error());
}
Else

..and get a syntax error of:
Parse error: syntax error, unexpected T_ELSE in C:\ on line 97
 
I'm not suprised.

Scripts should follow the standard form:

if (/* some_condition */)
{
//do something
}
else
{
//do something else
}

Your script, however, seems to follow the form:

if (/* some condition */)
{
//do something
}
{
//do something else
}
else


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Ahhh..I see it. Just fixed that. Thanks!

Get:
Notice: Undefined index: ZNumber in C:\ on line 95
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

The SQL is:
$sqlUpdate = sprintf("Update table1 set videoseen=1 Where ZNumber = ".$_POST['ZNumber']);
 
So, how can I pull the value from the form's textbox?
 
I don't know. I don't have your form in front of me and I've only seen snippets of your script.

[NOTE: Under no circumstances should you interpret the above paragraph as a request for you to post your entire script or HTML form.]

But here's the troubleshooting questions I would ask, were I in your place:[ol][li]Have I verified that the value is where I think it should be, or have I just assume the value is there?[/li][li]Was a form submitted? If not, $_POST will be empty[/li][li]Keeping in mind that all PHP variable names and associative array subscripts are case-sensitive, do I have a form named exactly "ZNumber" in my form? If not, it would be unreasonable of me to expect the data to be in $_POST under that name[/li][/ol]


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
I know the $_Post['ZNumber'] exists since I can get the echo to write the proper message.

It's just went I add this SQL that I'm getting the error.
 
Well...you're right. If I echo the SQL update statement, the query is:
"Update table1 set videoseen=1 Where ZNumber = "

...where'd the $_Post['ZNumber'] go?
 
Insufficient data for a meaningful answer.

I recommend that you use print or echo statements throughout your script and find out at what points the value exists and does not exist.

One thing to keep in mind is that PHP's comparision operators work like those in c-language. So:

if ($a == $b)

is a comparison but

if ($a = $b)

is an assignment. This can be troublesome for people who are used to languages like VisualBasic.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
You were right sleipnir214!

It was the spelling. Znumber and I was using ZNumber!

Star for you for putting up with me and all your help!

Glad I'm using something other than ASP.NET to get more detail oriented on stuff like this!

Thanks again!
 
Are you getting the error before you actually submit the form?????
If You are, you have to check that the form has been submitted before you can use the values it submits.
So you would need an IF statement to check for submission.

if(isset($_POST['ZNumber']) before attempting to do anything with it. So if it has not been set you don't have a;ll these erro messages popping up.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top