xhelle Posted June 17, 2009 Share Posted June 17, 2009 Hi to all, I have this code in php that need to insert the data into database, the data came from xml files, the problem is during i run my code i receive an error. Can you please check my code where do i go wrong. Thanks in advance. Here's my code: $xml = simplexml_load_file("KtextContentCatcherSample.xml"); foreach ($xml->children() as $child) { if ($child->getName() == 'params') { foreach ($child->children() as $params) { if ($params->getName() == 'ArtistName') $name = $params; if ($params->getName() == 'ServiceName') $sname = $params; if ($params->getName() == 'encoding') $encoding = $params; if ($params->getName() == 'Message') $message = $params; if ($params->getName() == 'Filename') $fname = $params; if ($params->getName() == 'Data') $data = base64_decode($params); $query = "SELECT * FROM inbox where artist_id = '"; } } } //write file $file = '/var/www/ktext/public/images/content/' .$fname; $fh = fopen($file, 'w') or die("Can't open file"); fwrite($fh, $data); echo "Data Written"; fclose($fh); echo $file; //DATABASE CONFIGURATION $DBhost = 'localhost'; $DBuser = 'root'; $DBpass = 'password'; $DBName = 'ktext'; $aname = $_POST['ArtistName']; $amessage = $_POST['Message']; $bmessage = $_POST['Message']; $fname = $_POST['Filename']; $conn = mysql_connect($DBhost, $DBuser, $DBpass) or die('Cannot connect to the database because: ' .mysql_error()); mysql_select_db($DBName) or die('Database not exist. ' .mysql_error()); $query = "INSERT INTO inbox ('id', 'artist_id', 'date_in, content', 'preview', 'picture') VALUES ('$aname', '$amessage', '$bmessage', '$fname')"; $result = mysql_query($query) or die('Error updating database'); echo "Database Updated"; Hope you can help me.... Quote Link to comment https://forums.phpfreaks.com/topic/162520-cant-connect/ Share on other sites More sharing options...
kickstart Posted June 17, 2009 Share Posted June 17, 2009 Hi What is the error you are getting? One issue is that in your INSERT statement you have quotes around the column names. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/162520-cant-connect/#findComment-857831 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.