Driving me crazy !

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
wckf
New php-forum User
New php-forum User
Posts: 15
Joined: Wed Mar 27, 2013 7:59 am

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 !

User avatar
Strider64
php-forum Active User
php-forum Active User
Posts: 293
Joined: Sat Mar 23, 2013 8:24 am

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);

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 4 guests