Jump to content

Archived

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

BillyBoB

need help

Recommended Posts

this is what i have but i cant figure whats not working
[code]
<?php
ob_start();
include("config.php");
?>
[/code]
heres the config.php
[code]
<?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);
?>
[/code]

heres the rest of the page

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

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

Share this post


Link to post
Share on other sites
Well what happens?

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

Share this post


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

Share this post


Link to post
Share on other sites
im goin to edit but the Value=\"Submit\" is the text that shows up on the button

Share this post


Link to post
Share on other sites
nothing happens thats the prob i need the data to go to the database but it doesnt

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites
Im unsure if you are allowed spaces inside this part:
(title, by, on, message)
try:
(title,by,on,message)

Share this post


Link to post
Share on other sites
maybe someone can tell me,

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

Share this post


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

Share this post


Link to post
Share on other sites
the only thing i can think of would be the id because its the primary key but that should set itself right?

Share this post


Link to post
Share on other sites
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')");

Share this post


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

Share this post


Link to post
Share on other sites
What happens if you leave out the part (id, title, by, on, message) ?

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

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:

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

Share this post


Link to post
Share on other sites
Change this line:
[code]<?php
$query = mysql_query("INSERT INTO `news` (title, by, on, message) VALUES('$title','$by','$time','$message')");
?>[/code]
to
[code]<?php
$q ="INSERT INTO `news` (`title`, `by`, `on`, `message`) VALUES('$title','$by','$time','$message')"
$query = mysql_query($q) or die("Problem with the query: $q<br>" . mysql_error());
?>[/code]

Ken

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.