ßł Ặck Ĥặwk ßł Ặck Ĥặwk - 1 year ago 70
MySQL Question

I can't update table's columns in MySQL database

I have created a tabe with values using this command :

`id` int(11) NOT NULL auto_increment,
`title` text NOT NULL,
`content` text NOT NULL,
`price` text NOT NULL,
`link` text NOT NULL,
`ppcode` text NOT NULL,
`type` text NOT NULL,

And when i use this php codes i cant update any value of the columns :

if (isset($_POST['edit'])){
$delsql = "UPDATE news SET title='$newsubject',content='$newdisc',link='$newlink',
price='$newprice',ppcode='$newppcode' WHERE id = '$id'";
$result = mysql_query($delsql) or die(mysql_error());
echo 'OK';

Note : the version of MySQL is and the version of PHP is 5.3

Answer Source

Use mysqli_* functions or PDO!!!!

//db connection

global $conn;

$servername = "localhost";  //host name

$username = "username"; //username

$password = "password"; //password

$mysql_database = "dbname"; //database name

//mysqli prepared statement 

$conn = mysqli_connect($servername, $username, $password) or die("Connection failed: " . mysqli_connect_error());

mysqli_select_db($conn,$mysql_database) or die("Opps some thing went wrong");

$stmt = $conn->prepare("UPDATE news SET title=?,content=?,link=?,price=?,ppcode=? WHERE id =?");


 //   i corresponding variable has type integer
 //  d  corresponding variable has type double
//  s   corresponding variable has type string
//  b   corresponding variable is a blob and will be sent in packets


            $row_count= $stmt->affected_rows;