Jump to content

show record into message alert box?


Yohanne

Recommended Posts

Hi coders,

 

i have search box, and i want to show the result from db into javascript message alert box with option yes and cancel botton. please any help and idea how it to work?

 

same like below but it's not working.

if (isset($_POST['search'])) {

    $word = mysql_real_escape_string($_POST['search']);
  
    $sql = "SELECT code FROM code_number WHERE code like '%" . $word . "%' ORDER BY code LIMIT 2";

	$row = mysql_query($sql) or die(mysql_error());
	    echo '<script type="text/javascript">';
         while($result = mysql_fetch_array($row))
		{
			echo 'alert(\'' + $result[code] + '\');';
		}
	echo '</script>';
		
}

thanks

Link to comment
https://forums.phpfreaks.com/topic/286598-show-record-into-message-alert-box/
Share on other sites

This coding practice to mix up sql/php/js/html, etc....in same document is bad. If you want to use sql/php and js you should consider of using AJAX!

To your question, the following works for me (tested a minute ago)

while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
echo "<script type='text/javascript'>";
echo "alert('{$row['names']}')";
echo "</script>";
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.