Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to solve a hyphen issue in a mySQL insert query
    primarykey
    data
    text
    <p>I want to insert data form an xml-feed into a mysql database (see code below). </p> <pre><code>&lt;?php error_reporting(E_ALL); ini_set('display_errors', 'On'); set_time_limit(0); $xmlDoc = new DOMDocument(); $xmlDoc-&gt;load("daisybelfeed.xml"); $mysql_hostname = "********"; $mysql_user = "*********"; $mysql_password = "*********"; $mysql_database = "*********"; $bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Opps some thing went wrong"); mysql_select_db($mysql_database, $bd) or die("Opps some thing went wrong"); $drop_tabel = "DROP TABLE belvilla"; $create_tabel = "CREATE TABLE belvilla (title VARCHAR(255), img_medium TEXT, country_of_destination TEXT, region_of_destination TEXT,city_of_destination CHAR(100), latitude FLOAT( 10, 6 ) NOT NULL, longitude FLOAT( 10, 6 ) NOT NULL, link TEXT, image TEXT, minimum_price DECIMAL NOT NULL, maximum_price DECIMAL NOT NULL, stars NUMERIC(1) NOT NULL, max_nr_people NUMERIC(1) NOT NULL);"; $drop = mysql_query($drop_tabel) or die('Error, drop query failed'); $create = mysql_query($create_tabel) or die('Error, create query failed'); $x=$xmlDoc-&gt;getElementsByTagName('item'); for ($i=0; $i&lt;=15000; $i++) { $title=$x-&gt;item($i)-&gt;getElementsByTagName('title') -&gt;item(0)-&gt;childNodes-&gt;item(0)-&gt;nodeValue; $image=$x-&gt;item($i)-&gt;getElementsByTagName('img_medium') -&gt;item(0)-&gt;childNodes-&gt;item(0)-&gt;nodeValue; $country=$x-&gt;item($i)-&gt;getElementsByTagName('country_of_destination') -&gt;item(0)-&gt;childNodes-&gt;item(0)-&gt;nodeValue; $regio=$x-&gt;item($i)-&gt;getElementsByTagName('region_of_destination') -&gt;item(0)-&gt;childNodes-&gt;item(0)-&gt;nodeValue; $city=$x-&gt;item($i)-&gt;getElementsByTagName('city_of_destination') -&gt;item(0)-&gt;childNodes-&gt;item(0)-&gt;nodeValue; $latitude=$x-&gt;item($i)-&gt;getElementsByTagName('latitude') -&gt;item(0)-&gt;childNodes-&gt;item(0)-&gt;nodeValue; $longitude=$x-&gt;item($i)-&gt;getElementsByTagName('longitude') -&gt;item(0)-&gt;childNodes-&gt;item(0)-&gt;nodeValue; $link=$x-&gt;item($i)-&gt;getElementsByTagName('link') -&gt;item(0)-&gt;childNodes-&gt;item(0)-&gt;nodeValue; $vanafprijs=$x-&gt;item($i)-&gt;getElementsByTagName('minimum_price') -&gt;item(0)-&gt;childNodes-&gt;item(0)-&gt;nodeValue; $maximaalprijs=$x-&gt;item($i)-&gt;getElementsByTagName('maximum_price') -&gt;item(0)-&gt;childNodes-&gt;item(0)-&gt;nodeValue; $sterren=$x-&gt;item($i)-&gt;getElementsByTagName('stars') -&gt;item(0)-&gt;childNodes-&gt;item(0)-&gt;nodeValue; $maxpeople=$x-&gt;item($i)-&gt;getElementsByTagName('max_nr_people') -&gt;item(0)-&gt;childNodes-&gt;item(0)-&gt;nodeValue; $title=mysql_real_escape_string($title); $image=mysql_real_escape_string($image); $link=mysql_real_escape_string($link); $regio=mysql_real_escape_string($regio); $city=mysql_real_escape_string($city); if ($country == 'FR'){ $insert = "INSERT INTO belvilla (title, img_medium, country_of_destination, region_of_destination, city_of_destination, latitude, longitude, link, image, minimum_price, maximum_price, stars, max_nr_people) VALUES ('$title', '$image', '$country', '$regio', '$city' $latitude, $longitude, '$link', '$image', $vanafprijs, $maximaalprijs, $sterren, $maxpeople)"; $add_member = mysql_query($insert) or die("Error, insert query failed Error: (" . mysql_errno() . ") " . mysql_error()); }} ?&gt; </code></pre> <p>Everything works fine, exept for one issue: I get an mySQL error code 1064 caused by some citynames containing a hyphen (like "La Roche-en-Ardenne"). As you can see in the code I tried to solve this problem using mysql_real_escape_string, but this doesn't work out. </p> <p>Anyone an idea on how to solve this problem?</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload