English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

*********
test.php:
include("includes/get_files.php");
include("includes/parse_html.php");
include("includes/mysql.php");
include("includes/strip.php");

$alines = $html->get_author_lines(1);
$inauthor = " ".join($alines)." ";

$datestriped = print end(explode('   ',$inauthor));
print "
";
$author = print strip_author("$inauthor");

etc.........

?>

*********

returns:

Published: 12-08-2006
Author: Adam Beazley


when i insert into mysql using:

$query = "INSERT INTO t4d.articles (datetime,author)
VALUES ('$datestriped','$author')";
$result = mysql_query($query);
print mysql_error();
$br = '
';


********problem:
1 is inserted in the mysql table columns for: $datestriped and $author!!

why is this?

my data types are varchar(200) null etc...

i have tried everything, these variables print fine in php!
i saved test.php as: utf-8 and tried & other formats, whats going on?

Thanks in advance
Tovia Singer

2007-12-31 10:10:26 · 5 answers · asked by jam 5 in Computers & Internet Programming & Design

5 answers

Your mysql syntax is fine.

MySQL is smart enough to parse it correctly, your problem is this:

$datestriped = print end(explode(' ',$inauthor));
print "
";
$author = print strip_author("$inauthor");

You are assigning the return value of print to your variables, in this case a 1. Take for instance:

$var = print "text";
print "Var equals $var";

$var will equal 1 because print executed successfully. Note that the above code would display:

text
Var equals 1


Simply change your code to:

$datestriped = end(explode(' ',$inauthor));
print $datestriped;
print "
";
$author = strip_author("$inauthor");
print $author;

And it should correct the problem.

Good luck!

2008-01-01 09:48:57 · answer #1 · answered by Coice 1 · 0 0

We can't see the data structure to see where the fields should go. Is there an auto_increment field for an id? maybe the ('0' field sould be '', empty rather than 0. Why not ad a die (mysql_error()) after the insert string which will at least tell you if it is data errors. You could also try making the query a string as in $insert_string = " your query, then using an : echo $insert_string; exit; //before the actual query runs. Cleaner way to use queries and it allows building them from massive amounts of data including constants and functions. Then using the query becomes : $my_resource = mysql_query($insert_string It is not a good idea to use get for what may be sensitive material, people's personal data can put them at risk, it is easy to recover this data from the headers. Use post.

2016-05-28 07:16:41 · answer #2 · answered by ? 3 · 0 0

Wrong syntax!
$query =
" INSERT INTO t4d.articles
( ` datetime ` , ` author ` )
VALUES
( ' " . $datestriped . " ' , ' " . $author . " ' ) " ;
Spaces added for clarity.
Beware: ` is != to ´ nor to ' nor to "...
(MySQL does not parse exactly the same way as PhP.)
JR
EDIT: Coice is absolutely correct! I did not notice these two lines
$datestriped = print end(explode(' ',$inauthor));
$author = print strip_author("$inauthor");
Your two variables are assigned the return value of "print()" (TRUE because it succeeds...)
Next time, put all the lines of code in the order they are!
Coice for the best answer...

2007-12-31 22:43:02 · answer #3 · answered by just "JR" 7 · 0 0

you cant have a zero or a neg so 1 you get does this help

2007-12-31 10:58:04 · answer #4 · answered by Ray . 2 · 0 0

The reason why $datestriped and $author are being populated into the table instead of the values that the vars represent, is that you built your query string to include them as strings.

2007-12-31 10:34:21 · answer #5 · answered by CatNip 6 · 0 0

fedest.com, questions and answers