Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Update sql cell

Posted on 2010-01-08
6
Medium Priority
?
552 Views
Last Modified: 2012-05-08
I have a simple text box and submit btn in a html form that send
a variable to a php file the php itself is suposed to update 1 field on a sql database below is the code



<?php
         extract( $_POST );
         $iserror = false;

           
            if ( !$iserror )  
            {


$query = "UPDATE contacts" .
SET (LastName) = '$lname' .
WHERE (id) = "1";

               // Connect to MySQL
               if ( !( $database = mysql_connect( "localhost",
                  "zahi", "zahi" ) ) )
                  die( "Could not connect to database" );

               // open MailingList database
               if ( !mysql_select_db( "MailingList", $database ) )
                  die( "Could not open MailingList database" );
             
               // execute query in MailingList database
               if ( !( $result = mysql_query( $query, $database ) ) )
               {
                  print( "Could not execute query! <br />" );
                  die( mysql_error() );
               } // end if

               mysql_close( $database );

               print( "<a href = 'formDatabase.php'>
                  Click here to view ur field.</a>" );
               die();
            }
   ?>





i keep on getting syntax and fatal errors any one knows why?

Thanks in advance


PS. i added an image so you can see the sql setup

sql.jpg
0
Comment
Question by:zahimezher
  • 3
  • 2
6 Comments
 
LVL 5

Expert Comment

by:nuke3dd
ID: 26208447
Rewrite:
$query = "UPDATE contacts" .
SET (LastName) = '$lname' .
WHERE (id) = "1";

as
$query = "UPDATE contacts" .
"SET LastName = '$lname'" .
"WHERE (id) = 1";
0
 
LVL 1

Author Comment

by:zahimezher
ID: 26208663
Could not execute query!
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 '= 'awd'WHERE (id) = 1' at line 1
0
 
LVL 7

Expert Comment

by:Gene_Cyp
ID: 26209328
Add a space on every line to eliminate the problem you've quoted above
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Author Comment

by:zahimezher
ID: 26213259
1 space at the beginning of every line ? :s
0
 
LVL 5

Accepted Solution

by:
nuke3dd earned 2000 total points
ID: 26228530
I'm sorry, another try:
$query = "UPDATE contacts" .
" SET LastName = '$lname'" .
" WHERE (id) = 1";
0
 
LVL 1

Author Comment

by:zahimezher
ID: 26272382
brilliant ! thanx alot
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
MSSQL DB-maintenance also needs implementation of multiple activities. However, unprecedented errors can hamper the database management. In that case, deploying Stellar SQL Database Toolkit ensures fast and accurate database and backup repair as wel…
Screencast - Getting to Know the Pipeline
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question