Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Driving me crazy !

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Driving me crazy !

Postby wckf » Sun Mar 31, 2013 11:15 am

$query = "UPDATE customers SET fname = $name, address = $address, pnumber = $pnumber, email = $email WHERE iD = $id " ;
if($query_run = mysql_query($query)){
echo'sucess';
} else {
echo 'please retry another time';
}


something is wrong with this code !
wckf
New php-forum User
New php-forum User
 
Posts: 15
Joined: Wed Mar 27, 2013 7:59 am

Re: Driving me crazy !

Postby Strider64 » Sun Mar 31, 2013 1:58 pm

Use mysqil or PDO, mysql is depreciated. Here's an example of mysqli that binds variables to a prepared statement as parameters. I didn't test the code out, but you can find further help at http://www.php.net.

Code: Select all
<?php
$link = mysqli_connect('localhost', 'my_user', 'my_password', 'your_database');

/* check connection */
if (!$link) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

$stmt = mysqli_prepare($link, "UPDATE
           customers
          SET                        
            fname = ?,
            address = ?,
                           pnumber = ?,
                           email = ?
          WHERE
            id = ?
        ");
mysqli_stmt_bind_param($stmt, 'sssss', $name, $address, $pnumber, $email, $id);

// Assign your variables here before the execute statement,  if needed...example $name = "John Smith";

/* execute prepared statement */
mysqli_stmt_execute($stmt);

echo "Success!!!!!!...well hopefully ;)";

/* close statement and connection */
mysqli_stmt_close($stmt);
User avatar
Strider64
New php-forum User
New php-forum User
 
Posts: 69
Joined: Sat Mar 23, 2013 8:24 am


Return to PHP coding => General

Who is online

Users browsing this forum: Google [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.