Tuesday 15 April 2014

text variable in sql statement - PHP -



text variable in sql statement - PHP -

i'm trying variable in sql-statement, set sql doesn't see string. i've searched long time solution, can't figure out.

<?php ob_start(); ?> <h2 class="title_test"></h2> <?php $contents = ob_get_contents(); $test = 'singer/songwriter nadine shah interview'; $mytext = (string)$contents; $result = mysqli_query($con, "select channel_id guestlist_tvs title = '$mytext'"); $row = mysqli_fetch_array($result); echo $row[0]; ?>

the ob_start gets text h2

and mytext makes string $contents (the value between h2). don't result if run sql statement.

if set sql-statement;

$result = mysqli_query($con, "select channel_id guestlist_tvs title = '$test'");

it returns right title.. there's wrong converting variable string, set don't know how prepare it.

every comment appreciated.

thanks

<?php ob_start(); ?> <h2 class="title_test"></h2> <?php $contents = ob_get_contents(); $test = 'singer/songwriter nadine shah interview'; $mytext = mysqli_real_escape_string($con, trim(strip_tags($contents))); $result = mysqli_query($con, "select channel_id guestlist_tvs title = '$mytext'"); $row = mysqli_fetch_array($result); echo $row[0]; ?>

how this?

php sql

No comments:

Post a Comment