php - Mysql Unable to make a query -
i trying put data in mysql table using php. i'm retrieving data variable database. let is:
$data = "some variable";
but problem in place of some variable
have data this
$data = $row['some data'];
i don't know fetching may time may hyper links may time may junk data. problem arises when try put data mysql table.
i tried echo out query suppose query
$query = "insert table values(0, '$data')";
the output was:
insert table values(0,'donatted book:'25 ways improve life');
here there upper quotation after donated book. can't change because data comes on here database. how make insert command work.
here how code working
<?php $query = "select*from table id=$content_id"; $data = mysqli_query($dbc, $query); $row = mysqli_fetch_array($data); $data = $row['col']; $query2 = "insert table values(0, $data)"; mysqli_query($query2); ?>
since using mysqli_*
api mentioned in comments.
you looking for: mysqli_real_escape_string()
.
but easier use mysqli_* prepared statements
.
side notes:
table
mysql reserved word, have put backticks around e.g.
$query2 = "insert `table` values(0, $data)"; //^ ^
also you're missing $dbc
first argument in second query, add this:
$row = mysqli_query($dbc, $query2);
i recommend check errors or die(mysqli_error($db));
, e.g.
$row = mysqli_query($dbc, $query2) or die(mysqli_error($dbc));
Comments
Post a Comment