Page 1 of 1
help with code
Posted: Sun Jun 29, 2003 12:15 am
by zer0
i need help i am making a script to post info in to a php script to me this looks right but when i try to use it i get an error.
Code: Select all
<?
$db=mysql_connect("localhost","user","pass") or die ("cant connect");
mysql_select_db("wsn",$db) or die ("cant change");
if ($submit){mysql_query(insert into news values="$author,$title,$date,$content")) or die ("cant post")};
?>
<form action="<?echo="$PHP_SELF?">" method=POST>
userneme<input type="text" size=11 name="author"><p>
title <input type ="text" size=11 name="title"><p>
content<textarea cols=20 rows=20 name="content"></textarea><p>
<input type="submit" name="submit" value="submit">
</form>
please help me figure out what is wrong with the scripting

Posted: Sun Jun 29, 2003 12:25 am
by MeltedPixel
Did you make the currect Database with all the correct tables?
Did you get all of your database login info correct?
I know these are simple questions, but sometimes thats the problem.
Posted: Sun Jun 29, 2003 12:31 am
by Sevengraff
Well, here is just what I see
<?
$db=mysql_connect("localhost","user","pass") or die ("cant connect");
mysql_select_db("wsn",$db) or die ("cant change");
if ($submit){mysql_query(need quote here, not using $_POST for variables insert into news values="dont think values uses =$author,$title,$date,$content")) or die ("cant post")};no ;
?>
<form action="<?echo="$PHP_SELF?">"have a quote where it shouldn't be method=POST>
userneme<input type="text" size=11 name="author"><p>
title <input type ="text" size=11 name="title"><p>
content<textarea cols=20 rows=20 name="content"></textarea><p>
<input type="submit" name="submit" value="submit">
</form>
Try this:
Code: Select all
<?
$date = time(); // $date needs a value.
$db=mysql_connect("localhost","user","pass") or die ("cant connect");
mysql_select_db("wsn",$db) or die ("cant change");
if (isset($_POST['submit'])){
mysql_query("insert into news values('$_POST['author']', '$_POST['title']','$date', '$_POST['content']')") or die ("cant post");
}
?>
<form action="<?=$PHP_SELF; ?>" method=POST>
userneme<input type="text" size=11 name="author"><p>
title <input type ="text" size=11 name="title"><p>
content<textarea cols=20 rows=20 name="content"></textarea><p>
<input type="submit" name="submit" value="submit">
</form>
If there are still errors, give me some line numbers with them.
Posted: Mon Jun 30, 2003 12:18 am
by zer0
thanks for the help i know for a fact that i have the sql database and tables mead corectly and when i used the scipt provided by Sevengraff i get a Parse error on line 7 it sayes its expecting 'T_STRING' or `T_VARIABLE' or `T_NUM_STRING' thanks for the help
Posted: Mon Jun 30, 2003 1:43 am
by Sevengraff
is that this line?
Code: Select all
mysql_query("insert into news values('$_POST['author']', '$_POST['title']','$date', '$_POST['content']')") or die ("cant post");
This should work better
Code: Select all
mysql_query("INSERT INTO news VALUES('{$_POST['author']}', '{$_POST['title']}', '{$date}', '{$_POST['content']}');") or die("Cant post");
I can't exactly test this stuff.
Posted: Mon Jun 30, 2003 2:44 pm
by zer0
thanks you got it working. but one last thing when i try to submit it it sayes cant post why?
thank you alot for helping me
Posted: Mon Jun 30, 2003 5:29 pm
by Sevengraff
change
Code: Select all
mysql_query("INSERT INTO news VALUES('{$_POSTї'author']}', '{$_POSTї'title']}', '{$date}', '{$_POSTї'content']}');") or die("Cant post");
to
Code: Select all
mysql_query("INSERT INTO news VALUES('{$_POSTї'author']}', '{$_POSTї'title']}', '{$date}', '{$_POSTї'content']}');") or die("Cant post: <br><pre>" . mysql_error() . '</pre>');
and it will tell you why.