add a value to a specific row in mysql

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
aneuryzma
Forum Contributor
Posts: 106
Joined: Sat May 17, 2008 7:03 am

add a value to a specific row in mysql

Post by aneuryzma »

How can I add a value to a specific row in mysql ?

The row is the one with that user_id value.

thanks

Code: Select all

if(isset( $_SESSION['user_id'] )) {
 
    try {
                        
                $db = mysqli_connect('127.0.0.1', 'root', 'mo98nf89') or die("Could not connect: " . mysqli_error());
                mysqli_select_db($db, "phpro_auth");
        
                $sql = 'INSERT INTO phpro_users (quote ) VALUES (?)';
        
                $stmt = $db->stmt_init( );
                   
                if ($stmt->prepare($sql)) {
        
                
                    // Associate placeholders with data type and variable name
                    $stmt->bind_param('s', $quote);
        
                
                    // Bind result variables
                    //$stmt->bind_result($username);
        
                    // Execute prepared statement
                    $stmt->execute( );
        
                }
 
            }
Last edited by Benjamin on Tue May 12, 2009 11:26 am, edited 1 time in total.
Reason: Changed code type from text to php.
Yossarian
Forum Contributor
Posts: 101
Joined: Fri Jun 30, 2006 4:43 am

Re: add a value to a specific row in mysql

Post by Yossarian »

How can I add a value to a specific row in mysql ?
This is a question about your sql statement, to change a value in an existing row you use the UPDATE command instead,

Code: Select all

"update phpro_users set quote = 'et tu Brute?' where name = 'Caesar' ";
Post Reply