help with code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
zer0
Forum Newbie
Posts: 3
Joined: Sun Jun 29, 2003 12:15 am

help with code

Post 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)&#123;mysql_query(insert into news values="$author,$title,$date,$content")) or die ("cant post")&#125;;
?>
<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 :D
MeltedPixel
Forum Newbie
Posts: 8
Joined: Sun Jun 29, 2003 12:22 am

Post 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.
User avatar
Sevengraff
Forum Contributor
Posts: 232
Joined: Thu Apr 25, 2002 9:34 pm
Location: California USA
Contact:

Post 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.
zer0
Forum Newbie
Posts: 3
Joined: Sun Jun 29, 2003 12:15 am

Post 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
User avatar
Sevengraff
Forum Contributor
Posts: 232
Joined: Thu Apr 25, 2002 9:34 pm
Location: California USA
Contact:

Post 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 :arrow:

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.
zer0
Forum Newbie
Posts: 3
Joined: Sun Jun 29, 2003 12:15 am

Post 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
User avatar
Sevengraff
Forum Contributor
Posts: 232
Joined: Thu Apr 25, 2002 9:34 pm
Location: California USA
Contact:

Post by Sevengraff »

change

Code: Select all

mysql_query("INSERT INTO news VALUES('&#123;$_POST&#1111;'author']&#125;', '&#123;$_POST&#1111;'title']&#125;', '&#123;$date&#125;', '&#123;$_POST&#1111;'content']&#125;');") or die("Cant post");
to

Code: Select all

mysql_query("INSERT INTO news VALUES('&#123;$_POST&#1111;'author']&#125;', '&#123;$_POST&#1111;'title']&#125;', '&#123;$date&#125;', '&#123;$_POST&#1111;'content']&#125;');") or die("Cant post: <br><pre>" . mysql_error() . '</pre>');
and it will tell you why.
Post Reply