Jump to content

update query for database


shane85

Recommended Posts

sorry for all the posts today guys...

I have a page where im editing a row (clients information) from my database

 

I access it by

edit_prospect?=prospect_id=5 (or whatever the prospect_id number is set in the database)

 

I then have my text fields extra but I have values in them which would be the values that are pulled from the database, so that if need be it can be edited. I then setup my form to go to edit_prospect2.php, in which I have a query that im trying to update my database, but it keeps telling my query failed.

 

I have tried 2 different querys...1 with SET and it gives me the same results...the ones I have been trying are

 

$qry = "UPDATE prospects SET(representative, prospect_feeling, firstname, lastname) VALUES('$representative','$prospect', '$f_name', '$l_name')";

 

which doesnt work, as well as

 

$qry = "UPDATE prospects (representative, prospect_feeling, firstname, lastname) VALUES('$representative','$prospect', '$f_name', '$l_name')";

 

what am I doing wrong ???

Link to comment
https://forums.phpfreaks.com/topic/197290-update-query-for-database/
Share on other sites

This is the update syntax definition -

UPDATE [LOW_PRIORITY] [iGNORE] table_reference

    SET col_name1={expr1|DEFAULT} [, col_name2={expr2|DEFAULT}] ...

    [WHERE where_condition]

    [ORDER BY ...]

    [LIMIT row_count]

 

Using the above syntax def.

 

$qry = "UPDATE prospects SET representative='$representative', prospect_feeling='$prospect', firstname= '$f_name', lastname= '$l_name'"; //You would probably want to add a WHERE clause onto that, or every row in the table will update.

hmm ok. Makes sence I have to include WHERE so that it knows to update the row. So for WHERE im putting prospect_id='$prospect_id' but its still having the same error.

 

$qry = "UPDATE prospects SET(representative, prospect_feeling, firstname, lastname) VALUES('$representative','$prospect', '$f_name', '$l_name') WHERE prospect_id='$prospect_id'";

 

I even tried using a number instead of $prospect_id that co-insidees with my db for testing purposes, but still returns the query failed.

I think I figured out why it wasnt working...my variable $prospect_id wasnt being told to GET it in my query...now I have it as follows

 

$qry = "UPDATE prospects SET representative='$representative', prospect_feeling='$prospect', firstname= '$f_name', lastname= '$l_name' WHERE prospect_id='.$_GET['prospect_id'].'";

 

but its giving me an error

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING

 

before when I had it for prospect_id='37'"; it would work perfectly and update that row, but I want it to update from the variable $prospect_id that I need to use GET for I think?

Try:

$id = (isset($_GET['prospect_id'])) ? (int)$_GET['prospect_id'] : die('error!');
$qry = "UPDATE prospects SET representative='$representative', prospect_feeling='$prospect', firstname= '$f_name', lastname= '$l_name' WHERE prospect_id='$id'";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.