Jump to content


Photo

php help


  • Please log in to reply
7 replies to this topic

#1 onthespot

onthespot
  • Members
  • PipPipPip
  • Advanced Member
  • 424 posts

Posted 15 August 2006 - 11:59 PM

<form action="insert12.php" method="post">
Title: <input type="text" name="title"  value"<? echo $form->value("title"); ?>" />
Text: <input type="text" name="text" value"<? echo $form->value("text"); ?>" />
<input type="submit" />
</form>
<?php
if(empty($title) || empty($text)) exit("You didn't completely fill in the form!");
// we're presuming here that you used 'title' and 'text' as the names for your form elements
$title = addslashes($title);
$text = addslashes($text);
// add slashes to the sent info so no escape characters are around (they'll possibly bust the script)
mysql_query("INSERT INTO news (title,text) VALUES ('$title','$text')"); ?>

this code is allowing me to submit the news, however, its not showing a message saying news piece added, and its always showing the "you didnt fill in form" even when the title and text are not empty!

any ideas

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 16 August 2006 - 12:07 AM

try

if(empty($_POST['title']) || empty($_POST['text'])) exit("You didn't completely fill in the form!");

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 16 August 2006 - 12:07 AM

Q/ Where do you define $title and $text?

A/ You dont. Replace them with $_POST['title'] and $_POST['text'] and you might have more luck.

#4 onthespot

onthespot
  • Members
  • PipPipPip
  • Advanced Member
  • 424 posts

Posted 16 August 2006 - 12:09 AM

still not working  ???

#5 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 16 August 2006 - 12:12 AM

It appears register globals is off (which is good!)

try:

$title = isset($_POST['title']) ? addslashes($_POST['title']) : NULL;
$text = isset($_POST['text']) ? addslashes($_POST['text']) : NULL;

if (is_null($title) || is_null($text)) {
exit("You didn't completely fill in the form!");
}

....
follow me on twitter @PHPsycho

#6 onthespot

onthespot
  • Members
  • PipPipPip
  • Advanced Member
  • 424 posts

Posted 16 August 2006 - 12:17 AM

stick not working ??

#7 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 16 August 2006 - 12:19 AM

echo $form->value("title");

Where is $form defined?
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#8 onthespot

onthespot
  • Members
  • PipPipPip
  • Advanced Member
  • 424 posts

Posted 16 August 2006 - 12:22 AM

im not sure, im new to php and am getting really confused!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users