NONAME_2 Posted December 14, 2010 Share Posted December 14, 2010 Hi, I use this form to call a function in self_php_page:addcomment; but it doesn't work. Wich part of form is incorrect: echo' <form action="{$_SERVER['PHP_SELF']}" . "?action=addcomment&id=$id" method="post" id="contactform" >'; echo' <ol>'; echo' <li>'; echo' <textarea id="message" rows="6" cols="50" name="comment"></textarea>'; echo' </li>'; echo' <li class="buttons">'; echo' <input type="image" type="image" name="imageField" id="imageField" src="../images/send.gif" />'; echo'</li></ol></form>'; i guess this line is incorrect: action="{$_SERVER['PHP_SELF']}" . "?action=addcomment&id=$id" TNX. Quote Link to comment https://forums.phpfreaks.com/topic/221612-_serverphp_self/ Share on other sites More sharing options...
trq Posted December 14, 2010 Share Posted December 14, 2010 Variables are not interpolated within single quotes. Quote Link to comment https://forums.phpfreaks.com/topic/221612-_serverphp_self/#findComment-1147112 Share on other sites More sharing options...
NONAME_2 Posted December 14, 2010 Author Share Posted December 14, 2010 Hi , i changed but it has this error: Parse error: parse error, expecting `','' or `';'' echo" <form action=\"{$_SERVER['PHP_SELF']}" . "?action=addcomment&id=$id\" method="post" id="contactform" >"; Quote Link to comment https://forums.phpfreaks.com/topic/221612-_serverphp_self/#findComment-1147118 Share on other sites More sharing options...
trq Posted December 14, 2010 Share Posted December 14, 2010 Now you have a bunch of double quotes within your double quoted string. Quote Link to comment https://forums.phpfreaks.com/topic/221612-_serverphp_self/#findComment-1147119 Share on other sites More sharing options...
NONAME_2 Posted December 14, 2010 Author Share Posted December 14, 2010 Hi ,TNX for your reply. i test but can't find the wrong double quotes . Quote Link to comment https://forums.phpfreaks.com/topic/221612-_serverphp_self/#findComment-1147122 Share on other sites More sharing options...
MMDE Posted December 14, 2010 Share Posted December 14, 2010 Hi , i changed but it has this error: Parse error: parse error, expecting `','' or `';'' echo" <form action=\"{$_SERVER['PHP_SELF']}" . "?action=addcomment&id=$id\" method="post" id="contactform" >"; echo '<form action="?action=addcomment&id='.$id.'" method="post" id="contactform" >'; Quote Link to comment https://forums.phpfreaks.com/topic/221612-_serverphp_self/#findComment-1147125 Share on other sites More sharing options...
NONAME_2 Posted December 14, 2010 Author Share Posted December 14, 2010 Hi,free error but it doesn't work.TNX. Quote Link to comment https://forums.phpfreaks.com/topic/221612-_serverphp_self/#findComment-1147128 Share on other sites More sharing options...
trq Posted December 14, 2010 Share Posted December 14, 2010 Define doesn't work. Quote Link to comment https://forums.phpfreaks.com/topic/221612-_serverphp_self/#findComment-1147135 Share on other sites More sharing options...
NONAME_2 Posted December 14, 2010 Author Share Posted December 14, 2010 doesn't work means no-complete correct; it inserts to bank but : 1- i have an error: Notice: Undefined index: action in C:\wamp\www\.. 2- useless from method {$_SERVER['PHP_SELF']} my current code is: echo'<form action="?action=addcoment&id='.$id.'" method="post" id="contactform">'; echo' <ol>'; echo' <li>'; echo' <textarea id="message" rows="6" cols="50" name="comment"></textarea>'; echo' </li>'; echo' <li class="buttons">'; echo' <input type="image" type="image" name="imageField" id="imageField" src="../images/send.gif" />'; echo'</li></ol></form>'; } function addComent($id) { $tour_id=$id; //Include database connection details require_once('../config.php'); //Connect to mysql server $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } //insert the comment $query = "INSERT INTO tour_comments " . "VALUES('','$tour_id'," . "'{$_POST['comment']}')"; mysql_query($query); echo '<p class="success">TNX</p>'; } switch($_GET['action']) { case 'show': displayOneItem($_GET['id']); break; case 'addcoment': addComent($_GET['id']); break; default:; } Quote Link to comment https://forums.phpfreaks.com/topic/221612-_serverphp_self/#findComment-1147145 Share on other sites More sharing options...
MMDE Posted December 14, 2010 Share Posted December 14, 2010 You don't need to use $_SERVER['PHP_SELF'] if you're not going to another page, no need to really set the url. but you want to send get data that way, and that should be done the way you did. is the $id variable ever set?? =p anyways, we just get half of your error messages and half of your code... Quote Link to comment https://forums.phpfreaks.com/topic/221612-_serverphp_self/#findComment-1147148 Share on other sites More sharing options...
NONAME_2 Posted December 14, 2010 Author Share Posted December 14, 2010 Hi, my problem is : Notice: Undefined index: action in C:\wamp\www\.. TNX. Quote Link to comment https://forums.phpfreaks.com/topic/221612-_serverphp_self/#findComment-1147150 Share on other sites More sharing options...
kenrbnsn Posted December 14, 2010 Share Posted December 14, 2010 Please post the FULL error message. The error tells us/you which line is having the problem. Ken Quote Link to comment https://forums.phpfreaks.com/topic/221612-_serverphp_self/#findComment-1147151 Share on other sites More sharing options...
NONAME_2 Posted December 19, 2010 Author Share Posted December 19, 2010 Hi, Excuse me for my absent; Notice: Undefined index: action in C:\wamp\www\..\tourin.php on line 326 line 326 in my code is: switch($_GET['action']) { case 'show': //<-------------------------(: THIS LINE displayOneItem($_GET['id']); break; case 'addcoment': addComent($_GET['id']); break; default:; } TNX. Quote Link to comment https://forums.phpfreaks.com/topic/221612-_serverphp_self/#findComment-1149149 Share on other sites More sharing options...
johnny86 Posted December 19, 2010 Share Posted December 19, 2010 You shouldn't use $_GET or $_POST variables without sanitizing them somehow. Data that comes from user is always untrusted and should be processed before use. Same goes to $_SERVER['PHP_SELF'] which is user dependent too and shouldn't be trusted. Use $_SERVER['SCRIPT_NAME'] instead. Quote Link to comment https://forums.phpfreaks.com/topic/221612-_serverphp_self/#findComment-1149167 Share on other sites More sharing options...
NONAME_2 Posted December 19, 2010 Author Share Posted December 19, 2010 Hi , what do you mean; Plz show me in my code: echo" <form action=\"{$_SERVER['PHP_SELF']}" . "?action=addcomment&id=$id\" method="post" id="contactform" >"; Quote Link to comment https://forums.phpfreaks.com/topic/221612-_serverphp_self/#findComment-1149177 Share on other sites More sharing options...
johnny86 Posted December 19, 2010 Share Posted December 19, 2010 Well, for that line you should replace $_SERVER['PHP_SELF'] with $_SERVER['SCRIPT_NAME'] This is the reason: URL that client is at: www.yourdomain.com/something/form.php/../../../../something_not_to_access $_SERVER['PHP_SELF'] = /something/form.php/../../../../something_not_to_access $_SERVER['SCRIPT_NAME'] = /something/form.php This is why you should not use $_SERVER['PHP_SELF'] because it depends on the URL client enters. Quote Link to comment https://forums.phpfreaks.com/topic/221612-_serverphp_self/#findComment-1149178 Share on other sites More sharing options...
mmarif4u Posted December 19, 2010 Share Posted December 19, 2010 Put this at the top of your code, as i think you have warning and notices enabled in php.ini error_reporting(E_ALL ^ E_NOTICE); For the {$_SERVER['PHP_SELF']}, use the MMDE suggestion: echo '<form action="?action=addcomment&id='.$id.'" method="post" id="contactform" >'; Quote Link to comment https://forums.phpfreaks.com/topic/221612-_serverphp_self/#findComment-1149179 Share on other sites More sharing options...
NONAME_2 Posted December 19, 2010 Author Share Posted December 19, 2010 Hi all, i replace this: switch($_GET['action']) { case 'show': displayOneItem($_GET['id']); break; case 'addcoment': addComent($_GET['id']); break; default:; } with this: if(isset($_GET['action']) && $_GET['action'] == 'addcoment') { addComent($_GET['id']); } and Error: Notice: Undefined index: action in C:\wamp\www\..\tourin.php on line 326 GONE; i used the MMDE suggestion: echo '<form action="?action=addcomment&id='.$id.'" method="post" id="contactform" >'; and it works properly but i'm going to try johnny86 suggestion; TNX for your answers. Quote Link to comment https://forums.phpfreaks.com/topic/221612-_serverphp_self/#findComment-1149198 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.