Jump to content

Archived

This topic is now archived and is closed to further replies.

hey_suburbia

echo works, but doesn't write to DB

Recommended Posts

This give me a nice read out:

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

but this won't go into my DB:

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

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

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

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

Share this post


Link to post
Share on other sites
[code]<?php
mysql_query("INSERT INTO counter (email,name,pagename,date)".
      "VALUES ('$sess', '$sess2', '$scr2', ".date('l dS \of F Y h:i:s A').")");
?>[/code]

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.

Share this post


Link to post
Share on other sites
@Cesear

I am passing these variables:

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

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Thanks!

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

[code]$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')");[/code]

Share this post


Link to post
Share on other sites
you were missing the single quotes

Its easier to read the query if you only use variables and strings (no funcitons)

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.