Jump to content


Photo

echo works, but doesn't write to DB


  • Please log in to reply
6 replies to this topic

#1 hey_suburbia

hey_suburbia
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 09 August 2006 - 10:03 PM

This give me a nice read out:

      echo ("INSERT INTO counter (email,name,pagename,date)".
      "VALUES ('$sess', '$sess2', '$scr2', ".date('l dS \of F Y h:i:s A').")");

but this won't go into my DB:

      $result = mysql_query("INSERT INTO counter (email,name,pagename,date)".
      "VALUES ('$sess', '$sess2', '$scr2', ".date('l dS \of F Y h:i:s A').")");

Any thoughts?  It's connecting because if I try just this:

      $result = mysql_query("INSERT INTO counter (email)".
      "VALUES ('$sess')");

It gives me a new field but they are blank...

#2 Caesar

Caesar
  • Members
  • PipPipPip
  • Advanced Member
  • 1,025 posts

Posted 09 August 2006 - 10:05 PM

<?php
mysql_query("INSERT INTO counter (email,name,pagename,date)".
      "VALUES ('$sess', '$sess2', '$scr2', ".date('l dS \of F Y h:i:s A').")");
?>

try that by itself. It's not going to INSERT, if you don't tell it to. If your simply saying $result = [query], you're not telling it to execute it.
PHP Ninja

#3 Caesar

Caesar
  • Members
  • PipPipPip
  • Advanced Member
  • 1,025 posts

Posted 09 August 2006 - 10:07 PM

Where are you defining: $sess, $sess2, $scr2?


PHP Ninja

#4 hey_suburbia

hey_suburbia
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 09 August 2006 - 10:18 PM

@Cesear

I am passing these variables:

$sess=$_SESSION['email'] ;
$sess2=$_SESSION['visitor'] ;
$scr=$_SERVER['SCRIPT_FILENAME'];

I have it working now, up to the date, so I'm thinking the date syntax is wrong?

#5 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 09 August 2006 - 10:40 PM

run the query lilke this

$query = "INSERT INTO counter (email,name,pagename,date)".
      "VALUES ('$sess', '$sess2', '$scr2', '".date('l dS \of F Y h:i:s A')."'";
$result = mysql_query($query);
if($result){
echo everything worked
}else{
echo "Error: ".mysql_error();
}

I also noticed date did not have single quotes round it
Tell me the problem, I will try tell you the solution

#6 hey_suburbia

hey_suburbia
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 09 August 2006 - 10:45 PM

Thanks!

I got it working by just putting the date into a variable:

$thedate=date('l dS \of F Y h:i:s A');

$result = mysql_query("INSERT INTO counter (email,name,pagename,date)".
"VALUES ('$sess', '$sess2', '$scr2', '$thedate')");


#7 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 09 August 2006 - 11:55 PM

you were missing the single quotes

Its easier to read the query if you only use variables and strings (no funcitons)
Tell me the problem, I will try tell you the solution




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users