Jump to content

[SOLVED] dealing with forms


irkevin

Recommended Posts

Hi, sorry for bugging you again..

 

I have a form.. the php code to insert to data in the database works well..

 

but now, i'm trying to prevent people from being childish with the form.. sorry for the expression..

 

If i do

 

<?php
if(!$_POST['name']){
echo "You did not enter your name";
}
?>

 

basically, it will tell the user that he didn't enter his name.. But i noticed on the net, some form, when you just hit spacebar once and then click submit, it submits the data and obviously, you'll get only a space in the database.. Why is it so? Is there a way to prevent this?

 

If someone know how to prevent this, plz tell me. will be very grateful..

Link to comment
Share on other sites

addslashes adds a slash after something strip slashes removes slashes from something.

 

 

if you want to remove whitespace you need to use  the trim function

 

also empty function if nothing is input into that field it wont allow you to post it errors

Link to comment
Share on other sites

it still enter a space.. here's the code

 

<?php
session_start();

require('config.php');
require('../functions.php');

$id = "0";
$shout = trim($_POST['shout_msg']);
$shouter = $_SESSION['user_name'];
$timeposted = date("F j, Y, g:i a");



if(!$shouter){
//do nothing
}else{

$conn = mysql_connect("localhost","****","****");
$db = mysql_select_db("kevin",$conn);
$sql = "INSERT INTO myshoutpro_shoutbox VALUES ('$id', '$shouter', '$shout','$timeposted')";
$result = mysql_query($sql);
}
?>
<html>
<meta http-equiv="refresh" content="0;url=http://www.mu-anime.com/shoutbox/index.php" />
</html>

 

whats wrong in this.. im going to smash my forehead on the keyboard :P

Link to comment
Share on other sites

yes it is entering in the database.. and it's showing a space on the shoutbox too..

 

basically it shows the space when i hit spacebar and press enter.. but i don't want that to happen even if i hit spacebar and press enter.. Im lost :S

Link to comment
Share on other sites

<?php
session_start();

require('config.php');
require('../functions.php');

$id = "0";
$shout = $_POST['shout_msg'];
$shoutt= str_replace(' ', '', $shout);
$shouter = $_SESSION['user_name'];
$timeposted = date("F j, Y, g:i a");



if(!$shouter){
//do nothing
}else{

$conn = mysql_connect("localhost","username","password");
$db = mysql_select_db("$db_name",$conn);
$sql = "INSERT INTO myshoutpro_shoutbox VALUES ('$id', '$shouter', '$shoutt','$timeposted')";
$result = mysql_query($sql);
}
?>
<html>
<meta http-equiv="refresh" content="0;url=http://www.mu-anime.com/shoutbox/index.php" />
</html>

 

here it is

Link to comment
Share on other sites

<?php
session_start();

require('config.php');
require('../functions.php');

$id = "0";
$shoutt = trim($_POST['shout_msg']);
$shoutt= str_replace(' ', '', $shoutt);
$shouter = $_SESSION['user_name'];
$timeposted = date("F j, Y, g:i a");



if(!$shouter){
//do nothing
}else{

$conn = mysql_connect("localhost","username","password");
$db = mysql_select_db("$db_name",$conn);
$sql = "INSERT INTO myshoutpro_shoutbox VALUES ('$id', '$shouter', '$shoutt','$timeposted')";
$result = mysql_query($sql);
}
?>
<html>
<meta http-equiv="refresh" content="0;url=http://www.mu-anime.com/shoutbox/index.php" />
</html>

Link to comment
Share on other sites

I tried the code you gave me but it didn't work.. then i tried added this part

 

if(!$shouter || !$shout){

//do nothing

}

 

I added !$shout, and it works perfectly.. so normally, you're replacing a space with this '', which means nothing.. it's same as leaving a field blank, right??

 

so it's the same as !$shout i presume..

 

Am i right? huh.. 0_o.. lol

 

but now when i type a normal text, it goes like this

 

thsiisjustatest

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.