...

View Full Version : Error in this Mysql to PHP script



johnnycabbage
11-12-2011, 02:13 AM
I am sending data to my MySQL database. This script was working fine, until I included the 'TIME: auto NOW(TIME' )"; code. So I'm pretty sure I made an error with inserting the time, or it's not formatted correctly. Can anyone locate the problem I've made?



<?php
$con = mysql_connect("localhost","myusername","mypassword");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("silviafilms_ca_4", $con);
$sql="INSERT INTO Comments (FirstName, Comments, TIME, )
VALUES
('$_POST[firstname]','$_POST[comments]','TIME: Auto NOW(TIME)' )";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
header( 'Location: http://www.mywebsite.com' ) ;
{
mysql_close($con)
?>

johnnycabbage
11-12-2011, 02:35 AM
It works fine when I have it like this, but then it creates two table:

<?php
$con = mysql_connect("localhost","myusername","mypassowrd");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("silviafilms_ca_4", $con);
$sql="INSERT INTO Comments (FirstName, Comments)
VALUES
('$_POST[firstname]','$_POST[comments]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
header( 'Location: http://mywebsite.com' ) ;
{
$query_auto = "INSERT INTO Comments (TIMER, TIME)
VALUE ('TIME: Auto NOW()', NOW() )";
mysql_query($query_auto) or die(mysql_error());
}
mysql_close($con)
?>

Dormilich
11-12-2011, 10:11 AM
well, you’re doing two queries …

johnnycabbage
11-12-2011, 09:34 PM
I did this, and it actually works how I want it to. I'm surprised as you are:
<?php
$con = mysql_connect("localhost","username","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("silviafilms_ca_4", $con);
$query_auto = "INSERT INTO Comments (firstname, comments, TIMER, TIME)
VALUE ('$_POST[firstname]','$_POST[comments]','TIME: Auto NOW()', NOW() )";
mysql_query($query_auto) or die(mysql_error());
{
header( 'Location: http://www.google.ca/images/persons.html' ) ;
}
mysql_close($con)
?>

Inigoesdr
11-13-2011, 03:13 AM
I'm surprised as you are

So, not surprised? You were running two INSERT queries; you should be getting two rows. When you removed one of the INSERT queries you get one row.

johnnycabbage
11-13-2011, 03:47 AM
No, I was surprised that I was able to combine both of the insert queries, and have it run fine:

$query_auto = "INSERT INTO Comments (firstname, comments, TIMER, TIME)
VALUE ('$_POST[firstname]','$_POST[comments]','TIME: Auto NOW()', NOW() )";

Because one query was transferred data, and the other query was generated data.

Dormilich
11-13-2011, 09:23 AM
after evaluating the query string you only have a string where you can’t determine (from looking at the string itself) which parts originate where.

johnnycabbage
11-27-2011, 11:01 PM
after evaluating the query string you only have a string where you canít determine (from looking at the string itself) which parts originate where.They originated from a previous page.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum