View Single Post
Old 12-16-2009, 12:04 PM  
mkx
Confirmed User
 
Industry Role:
Join Date: Nov 2003
Location: Toronto
Posts: 4,001
Quick PHP / Mysql question

I am trying to insert the $array[14] result into my mysql database but it is just inserting $array[14] in plain text instead of the variable.

Code:
<?php
include 'dbconnect.php';

$query  = "SELECT * FROM messages WHERE id=43";
$result = mysql_query($query);


while($row = mysql_fetch_array($result))
  {
  $str = $row['message'];
  }


$arrays = (explode(",\"",$str)); //seperates anything with ,"
$arrays = (explode("\"",$str)); //reseperates anything with "


echo $arrays[14]; //prints result 14


mysql_select_db($mysql);
$query = 'INSERT INTO `sms`.`redirects` (`id`, `msg`, `from_num`, `to_num`, `from_country`, `to_country`, `status2`, `time_created`) VALUES (NULL, \'apples\', \'peanuts\', \'$arrays[14]\', \'\', \'\', \'\', \'\');';

mysql_query($query) or die('Error, insert query failed');

$query = "FLUSH PRIVILEGES";
mysql_query($query) or die('Error, insert query failed');

?>
I tried
uts\', \'"$arrays[14]"\', \'
uts\', \'echo $arrays[14]\', \'
uts\', \'".$arrays[14]."', \'

and a few other variations but it just gave a http 500 error or inserted it in plain text.

Incase your wondering about the weird insert command and all the unnecessary back slashes, I got the code from inserting manually into the mysql database and hitting create php code since nothing else was really working.

Last edited by mkx; 12-16-2009 at 12:06 PM..
mkx is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote