Jump to content


Photo

need help


  • Please log in to reply
21 replies to this topic

#1 BillyBoB

BillyBoB
  • Members
  • PipPipPip
  • Advanced Member
  • 630 posts

Posted 13 July 2006 - 09:37 AM

this is what i have but i cant figure whats not working
<?php
	ob_start();
	include("config.php");
?>
heres the config.php
<?php
   ob_start(); 
   $conn = mysql_connect("localhost","user","pass");
   mysql_select_db(database) or die(mysql_error());
   $logged = MYSQL_QUERY("SELECT * from users WHERE id='$_COOKIE[id]' AND password = '$_COOKIE[pass]'");
   $logged = mysql_fetch_array($logged);
?> 

heres the rest of the page

<?php
echo("
<center>
<form method=\"POST\">
Title:<br>
<input type=\"text\" size=\"25\" maxlength=\"50\" name=\"title\"><br>
By:<br>
<input type=\"text\" size=\"25\" maxlength=\"50\" name=\"by\"><br>
Message:<br>
<textarea cols=\"50\" rows=\"5\" name=\"message\" >test</textarea><br>
<input type=\"submit\" value=\"Submit\" name=\"submit\">
</form>
</center>
");
if ($_POST[submit]) {
$title = $_POST[title];
$by = $_POST[by];
$message = $_POST[message];
if ($title==NULL|$by==NULL|$message==NULL) {
echo("You left a space blank!");
}else{
$newtime = time();
$time = gmdate("Y-m-d H:i:s", $newtime);
$query = mysql_query("INSERT INTO `news` (title, by, on, message) VALUES('$title','$by','$time','$message')");
}
}
?>

the query is prob goin to be spaced because its long
but i know its like 4 in the mourning but the faster the better



#2 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 13 July 2006 - 09:39 AM

Well what happens?

And also, you might wanna edit out your database username and password.

#3 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 13 July 2006 - 09:39 AM

dont know if it matters but u have Submit as the value in the form and if ($_POST[submit])

try changing if ($_POST[submit]) to if ($_POST[Submit])

#4 BillyBoB

BillyBoB
  • Members
  • PipPipPip
  • Advanced Member
  • 630 posts

Posted 13 July 2006 - 09:44 AM

im goin to edit but the Value=\"Submit\" is the text that shows up on the button

#5 BillyBoB

BillyBoB
  • Members
  • PipPipPip
  • Advanced Member
  • 630 posts

Posted 13 July 2006 - 09:45 AM

nothing happens thats the prob i need the data to go to the database but it doesnt


#6 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 13 July 2006 - 09:46 AM

Add an or die statement:

$query = mysql_query("INSERT INTO `news` (title, by, on, message) VALUES('$title','$by','$time','$message')") or die(mysql_error());

So we can see if that is the problem.

#7 BillyBoB

BillyBoB
  • Members
  • PipPipPip
  • Advanced Member
  • 630 posts

Posted 13 July 2006 - 09:50 AM

heres the error

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 'by, on, message) VALUES('omga','moga','2006-07-13 09:49:23','te

#8 BillyBoB

BillyBoB
  • Members
  • PipPipPip
  • Advanced Member
  • 630 posts

Posted 13 July 2006 - 09:53 AM

does it matter if i have MySQL version  4.0.25-standard ?

#9 BillyBoB

BillyBoB
  • Members
  • PipPipPip
  • Advanced Member
  • 630 posts

Posted 13 July 2006 - 09:59 AM

ne 1?

#10 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 13 July 2006 - 10:00 AM

i dunno...

#11 BillyBoB

BillyBoB
  • Members
  • PipPipPip
  • Advanced Member
  • 630 posts

Posted 13 July 2006 - 10:01 AM

robot can u figure this out


#12 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 13 July 2006 - 10:05 AM

Im unsure if you are allowed spaces inside this part:
(title, by, on, message)
try:
(title,by,on,message)


#13 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 13 July 2006 - 10:05 AM

maybe someone can tell me,

include("config.php"); does it need to be include('config.php');

#14 BillyBoB

BillyBoB
  • Members
  • PipPipPip
  • Advanced Member
  • 630 posts

Posted 13 July 2006 - 10:08 AM

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 'by,on,message) VALUES('fg','fg','20060713100640','test')' at li

still happens and i even fixed the time so there is no spaces

and brown there doesnt need the be ' there cuz i have used that b4

#15 BillyBoB

BillyBoB
  • Members
  • PipPipPip
  • Advanced Member
  • 630 posts

Posted 13 July 2006 - 10:09 AM

the only thing i can think of would be the id because its the primary key but that should set itself right?

#16 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 13 July 2006 - 10:11 AM

Im not sure, try adding it in and see what happens:

$query = mysql_query("INSERT INTO `news` (id,title, by, on, message) VALUES('','$title','$by','$time','$message')");

#17 BillyBoB

BillyBoB
  • Members
  • PipPipPip
  • Advanced Member
  • 630 posts

Posted 13 July 2006 - 10:13 AM

man this is making me mad how do u guys setup the news on the sites

error:

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 'by,on,message) VALUES('','fff','fff','20060713101229','test')'

#18 BillyBoB

BillyBoB
  • Members
  • PipPipPip
  • Advanced Member
  • 630 posts

Posted 13 July 2006 - 10:15 AM

brb30 min


#19 CheesierAngel

CheesierAngel
  • Members
  • PipPipPip
  • Advanced Member
  • 105 posts
  • LocationBelgium

Posted 13 July 2006 - 10:17 AM

What happens if you leave out the part (id, title, by, on, message) ?

 $query = <<<SQL 
    INSERT INTO news
    VALUES ('', '$title', '$by', '$time', '$message')
SQL;

Your query is propably giving this error because your SQL interpreter sees the 'by' - column as a standard keyword used in other query syntaxes. (Aswell the 'on' - column will be giving the same error). Would be the same if your table would look like:

 $query = <<<SQL
    INSERT INTO news (INSERT, GRANT, SELECT, ...)
    VALUES ('aaa', 'bbb', 'ccc', ...)
SQL;


#20 BillyBoB

BillyBoB
  • Members
  • PipPipPip
  • Advanced Member
  • 630 posts

Posted 13 July 2006 - 03:19 PM

thx for your help and that was it the by fixed it now so thx alot




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users