Hello; I want to turn paragraphs into sentences which I do with $parag = $_POST['parag']; $sent = explode(".", $parag); PHP: Now the problem is how to insert these sentences into separate mysql rows. I used the following mysql_query("INSERT INTO metin_cum (sent) VALUES('$sent[0]'), ('$sent[1]'), ('$sent[2]'), ('$sent[3]'), ('$sent[4]'), ('$sent[5]'), ('$sent[6]'), ('$sent[7]'), ('$sent[8]'), ('$sent[9]'), ('$sent[10]'), ('$sent[11]'), ('$sent[12]'), ('$sent[13]'), ('$sent[14]'), ('$sent[15]'), ('$sent[16]'), ('$sent[17]'), ('$sent[18]'), ('$sent[19]'), ('$sent[20]') ") or die(mysql_error()); PHP: I need a code which will know how many new rows will be needed for each new paragraph. What if I want to insert a paragraph or page with 22 sentences? Please help.
$sqlquery="INSERT INTO metin_cum (sent) VALUES'"; for($i=0;$i<count($sent)-1;$i++) { $sqlquery.="('".$sent[$i]."')," } $sqlquery.="('".$sent[count($sent)]."')"; mysql_query($sqlquery)or die(mysql_error()); PHP:
True $sqlquery.="('".$sent[count($sent)]."')"; PHP: Should be $sqlquery.="('".$sent[count($sent)-1]."')"; PHP: If it still doesn't work, at least provide some information about what doesn't work. (Echo the sqlquery variable)
Well, here is all I can get You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''('Then he went to the gallows, sat beneath them and waited until the evening'),' at line 2 HTML: The paragraph is posted and exploded. No problem here. Below is the whole code $parag = $_POST['parag']; $sent = explode(".", $parag); include('connect.php'); $sqlquery="INSERT INTO metin_cum (sent) VALUES'"; for($i=0;$i<count($sent)-1;$i++) { $sqlquery.="('".$sent[$i]."'),"; } $sqlquery.="('".$sent[count($sent)-1]."')"; mysql_query($sqlquery)or die(mysql_error()); PHP:
What about replacing this: $sqlquery = "INSERT INTO metin_cum (sent) VALUES'"; PHP: with this: $sqlquery = "INSERT INTO metin_cum (sent) VALUES"; PHP: Notice I removed the apostrophe (single quote) after VALUES.
This time I am having an issue with the quotation marks. The parts of the sentences following a quotation mark (") or a (') are omitted.
Here is an example; Input text: A father had two sons. The older son was clever and could do everything. But the younger one was stupid and could not understand or learn anything. When people saw him, they said, “He will be a burden on his father.†When there was something to do, the older son did it. However, when the father asked him to go somewhere at night, he would feel afraid and say, “No, father. I can’t go there. It makes me shudder.†Mysql output: A father had two sons The older son was clever and could do everything But the younger one was stupid and could not understand or learn anything When people saw him, they said, However, when the father asked him to go somewhere at night, he would feel afraid and say, It makes me shudder I can And there are some empty rows. And here is the echo $sql output: (' A father had two sons'),(' The older son was clever and could do everything'),(' But the younger one was stupid and could not understand or learn anything'),(' When people saw him, they said, “He will be a burden on his father'),('†When there was something to do, the older son did it'),(' However, when the father asked him to go somewhere at night, he would feel afraid and say, “No, father'),(' I can’t go there'),(' It makes me shudder'),('†'),('')
Well, if you have a query like this: mysql_query($yourqueryhere); Code (markup): Try adding addslashes() to it; mysql_query(addslashes($yourqueryhere)); Code (markup): This will escape all single and double quotes.
What code is putting in the single quotes and parentheses around the commas? That's one problem. Another one seems to be your lack of understanding of when to use which quotation mark (single or double) in PHP - they're not the same, and if you're creating a SQL string they have to be correct or you're telling MySQL something you don't want to. Edit: I missed that this is an explode. Still, you have to clean up the string because your single and double quotes are being thrown into the wrong places. mysql_real_escape_string() will help, but you still have to make sure that you're ending up with the SQL string you want.
Well, the problem has been solved but in an indirect way. First, I edited the input and replaced the (") and (') marks with "{" and "}" marks, which are not often used in texts. The sentences were inserted into the database in this way. When I retrieve the sentences for use, I str_replace them accordingly. Thank you very much for your kind efforts to help.