Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 07-04-2009, 04:44 AM   #1 (permalink)
jnich104
Monkey N00B
 
jnich104's Avatar
 
Join Date: Jun 2008
Location: Nailsea
Posts: 108
jnich104 is on a distinguished road
Send a message via MSN to jnich104
Veribal Changing

If i have a form like
PHP Code:
<form action="change.php?change22" method="post">
  <
input name="construction" type="hidden" id="construction" value="$construction" /> 
  
Construction Mode 
  <
label>
  <
select name="op1" id="op1">
    <
option value="yes">Yes</option>
    <
option value="no">No</option>
    </
select>
  </
label>
</
form
how would i process that so that it would change a veribal $construction

PHP Code:
$costruction "yes" // or no ; 
i have looked and looked and i cant find out how???
__________________
Jamie Nicholls - Feel Free To Ask Questions
jnich104 is offline   Reply With Quote
Old 07-04-2009, 07:58 AM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,706
sde is on a distinguished road
what are you trying to do with the part of the action that is ?change22. i think you really need a value to assign to change22 to make it useful... or if that is the value, then add a key before it. i.e. ?change22=foo or ?foo=change22

you can access post variables like this: $_POST['construction'] and $_POST['op1']. Just note those array keys are based off the input "name" not the "id".

A good debugging technique is to print the $_POST array to see exactly what your form is sending. Note that this example would have to be placed above any code that prints to the screen because it contains a header function. You would place this at the top of change.php.
PHP Code:
<?php
// print debug output for data posted to this script

// only run if there is post data
if ($_POST) {
  
// set content type to text/plain so array is formatted nicely on screen
  
header('content-type: text/plain');

  
// now print the dump of the POST array
  
print_r($_POST);
}
?>
Now for an issue I see in your form. You are adding a variable inside plain html. PHP needs to know that you want to process that variable, so you need an opening PHP tag and to echo that variable. That line will work better like this:
PHP Code:
<input name="construction" type="hidden" id="construction" value="<?php echo $construction?>" />
Note with that, if your variable $construction contains any quotes, it will break the HTML form when printed. If you are not sanitizing $construction before it gets printed, you may want to consider doing so in that echo statement.

Here's an example on how to access the submission on change.php once it has been submitted :
PHP Code:
<?php
if ($_POST) {
  echo 
'The value of construction is: '$_POST['construction'];
  echo 
'<br />';
  echo 
'The value of op1 is: '$_POST['op1'];
  exit();
}
?>
__________________
Mike
sde is offline   Reply With Quote
Old 07-05-2009, 05:13 AM   #3 (permalink)
jnich104
Monkey N00B
 
jnich104's Avatar
 
Join Date: Jun 2008
Location: Nailsea
Posts: 108
jnich104 is on a distinguished road
Send a message via MSN to jnich104
Ok that kl, but after submiting the data, How do i make it change
PHP Code:
$construction "no"
if yes is submited then it would be

PHP Code:
$construction "yes"
If no is submited then it would be

PHP Code:
$construction "no"

Because my page read my main-config.php file to find infomation like site name and id construction mode is active or not so it nows if it need to redirect ect....


So i am making a admin page for it all and so it can be done with out having to upload pages from my home comp again and again
__________________
Jamie Nicholls - Feel Free To Ask Questions
jnich104 is offline   Reply With Quote
Old 07-05-2009, 07:04 AM   #4 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,706
sde is on a distinguished road
PHP Code:
<?php
$construction 
$_POST['op1'];
?>
__________________
Mike
sde is offline   Reply With Quote
Old 07-05-2009, 07:11 AM   #5 (permalink)
jnich104
Monkey N00B
 
jnich104's Avatar
 
Join Date: Jun 2008
Location: Nailsea
Posts: 108
jnich104 is on a distinguished road
Send a message via MSN to jnich104
I tryed that, and i need it to write that the my config page so that when it posted it will save on my config page so that it will stay intill the next time it is posted as differnent
__________________
Jamie Nicholls - Feel Free To Ask Questions
jnich104 is offline   Reply With Quote
Old 07-05-2009, 07:44 AM   #6 (permalink)
jnich104
Monkey N00B
 
jnich104's Avatar
 
Join Date: Jun 2008
Location: Nailsea
Posts: 108
jnich104 is on a distinguished road
Send a message via MSN to jnich104
I tryed using a fwrite
PHP Code:
<?php
$con 
$_POST['con'];
$filename '../require/main_config.php';
$somecontent "$construction = '".$con."'\n";

// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {

    
// In our example we're opening $filename in append mode.
    // The file pointer is at the bottom of the file hence
    // that's where $somecontent will go when we fwrite() it.
    
if (!$handle fopen($filename'a')) {
         echo 
"Cannot open file ($filename)";
         exit;
    }

    
// Write $somecontent to our opened file.
    
if (fwrite($handle$somecontent) === FALSE) {
        echo 
"Cannot write to file ($filename)";
        exit;
    }

    echo 
"Success, wrote ($somecontent) to file ($filename)";

    
fclose($handle);

} else {
    echo 
"The file $filename is not writable";
}
Which dident save the $construction = 'no'; it just save the = 'no';

So i dunno what to try.
__________________
Jamie Nicholls - Feel Free To Ask Questions
jnich104 is offline   Reply With Quote
Old 07-05-2009, 10:16 PM   #7 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,706
sde is on a distinguished road
if you're going to use $construction in double quotes, then you need to escape the $. PHP will try to inturprit them. In this case, the variable $construction has no value, which is why you're just gettng = 'noe';

PHP Code:
<?php
$somecontent 
"\$construction = 'foo'";
?>
one word of caution, make sure this app is secure since you are writing PHP content directly from a web form to a script that is going to be executed by PHP. It would be very easy for someone to inject PHP in that form and have their way with your website.
__________________
Mike
sde is offline   Reply With Quote
Old 07-06-2009, 02:24 PM   #8 (permalink)
jnich104
Monkey N00B
 
jnich104's Avatar
 
Join Date: Jun 2008
Location: Nailsea
Posts: 108
jnich104 is on a distinguished road
Send a message via MSN to jnich104
I have a mysql and php Login Script which is secureing it and i have a prob with it,

I am looking at it and trying to make this index page, have a form if not loged in

PHP Code:

    
//Start session
    
session_start();
    
    
//Check whether the session variable SESS_MEMBER_ID is present or not
    
if(!isset($_SESSION['SESS_MEMBER_ID']) || (trim($_SESSION['SESS_MEMBER_ID']) == '')) {
        echo 
'<form id="loginForm" name="loginForm" method="post" action="includes/login-exec.php">
      <table width="300" border="0" align="center" cellpadding="2" cellspacing="0">
        <tr>
          <td width="112"><b>Login</b></td>
            <td width="188"><input name="login" type="text" class="textfield" id="login" /></td>
          </tr>
        <tr>
          <td><b>Password</b></td>
            <td><input name="password" type="password" class="textfield" id="password" /></td>
          </tr>
        <tr>
          <td>&nbsp;</td>
            <td><input type="submit" name="Submit" value="Login" /></td>
          </tr>
        </table>
    </form>  '
;
        
    } else { 
    
    echo 
'Welcome '.$_SESSION['SESS_FIRST_NAME']}.' 123';
    exit;
    } 

But i am getting this error and cant see what wrong

PHP Code:
 
Parse error
parse errorexpecting `','' or `';' in C:wampwwwStoryincludesindex-auth.php on line 26 
__________________
Jamie Nicholls - Feel Free To Ask Questions
jnich104 is offline   Reply With Quote
Old 07-07-2009, 10:47 AM   #9 (permalink)
redhead
Super Moderator
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,878
redhead is on a distinguished road
PHP Code:
else { 
    
    echo 
'Welcome '.$_SESSION['SESS_FIRST_NAME']}.' 123';
    exit;
    } 
Take a closer look at the combination of [, ], { and } in this.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 07-07-2009, 01:49 PM   #10 (permalink)
jnich104
Monkey N00B
 
jnich104's Avatar
 
Join Date: Jun 2008
Location: Nailsea
Posts: 108
jnich104 is on a distinguished road
Send a message via MSN to jnich104
ohhh kk ty
__________________
Jamie Nicholls - Feel Free To Ask Questions
jnich104 is offline   Reply With Quote
Old 07-07-2009, 02:35 PM   #11 (permalink)
jnich104
Monkey N00B
 
jnich104's Avatar
 
Join Date: Jun 2008
Location: Nailsea
Posts: 108
jnich104 is on a distinguished road
Send a message via MSN to jnich104
i got it working now it says
PHP Code:
NoticeA session had already been started ignoring session_start() in C:wampwwwStorynewrequireindex-auth.php on line 4 
which the line is
PHP Code:
<?PHP
 
 
//Start session 
    
session_start(); 
     
    
//Check whether the session variable SESS_MEMBER_ID is present or not 
    
if(!isset($_SESSION['SESS_MEMBER_ID']) || (trim($_SESSION['SESS_MEMBER_ID']) == '')) { 
        echo 
'
        <form id="loginForm" name="loginForm" method="post" action="require/login-exec.php"> 
                 <input name="login" type="text" class="textfield" id="login" value="Username" />
                 <input name="password" type="password" class="textfield" id="password" value="password" />
                 <input type="submit" name="Submit" value="Login" />
</form>  '

         
    } else {  
     
    echo 
'<p class="mini_links">Welcome '.$_SESSION['SESS_FIRST_NAME'].'';
}; 
?>
but the page is which the error comes on is

PHP Code:
<?PHP require('require/main_config.php'); ?> 
<?PHP // LOGOUT
            //Start session
            
session_start();
    
            
//Unset the variables stored in session
            
unset($_SESSION['SESS_MEMBER_ID']);
            unset(
$_SESSION['SESS_FIRST_NAME']);
            unset(
$_SESSION['SESS_LAST_NAME']);
            unset(
$_SESSION['SESS_ADMIN']);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?PHP echo $site_name ?></title>
<link href="style/main.css" rel="stylesheet" type="text/css" />
</head>

<body>
<table width="900" border="0" cellpadding="0" cellspacing="0" align="center">
  <!--DWLayoutTable-->
  <tr>
    <td height="133" colspan="2" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0" class="header">
      <!--DWLayoutTable-->
      <tr>
        <td width="900" height="132">&nbsp;</td>
      </tr>
    </table>    </td>
  </tr>
  
  <tr>
    <td height="18" colspan="2" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
      <!--DWLayoutTable-->
      <tr>
        <td width="900" height="18" valign="top" class="bg"><div align="right">
          <?PHP include('require/index-auth.php'); ?>
          </div></td>
        </tr>
      
    </table></td>
  </tr>
  <tr>
    <td width="170" height="230" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
      <!--DWLayoutTable-->
      <tr>
        <td width="170" height="230">&nbsp;</td>
        </tr>
    </table></td>
  <td width="730" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
      <!--DWLayoutTable-->
      <tr>
        <td width="13" height="7"></td>
        <td width="703"></td>
        <td width="14"></td>
      </tr>
      <tr>
        <td height="223"></td>
        <td valign="top"><!--DWLayoutEmptyCell-->&nbsp;        </td>
          <td></td>
      </tr>

      <!--DWLayoutTable-->
    </table></td>
  </tr>
</table>
</body>
</html>
__________________
Jamie Nicholls - Feel Free To Ask Questions
jnich104 is offline   Reply With Quote
Old 07-08-2009, 12:20 AM   #12 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,706
sde is on a distinguished road
notices are not too important for php. on most servers, it is turned off. you can do that in the php.ini file by changing the error reporting.

there should be a few examples in the php.ini file for different settings. most common is to report all errors except notices.

to address that exact error though, php is automatically generating a session, so it's saying session_start is not required. it is good practice however to leave it there in case you port your app to a server that is not configured in such a way.
__________________
Mike
sde is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
changing file permission salmanjoo PHP 7 08-23-2005 12:32 PM
changing Field colors WmFenn HTML, XML, Javascript, AJAX 2 07-20-2005 12:00 PM
Text format changing DavH27 HTML, XML, Javascript, AJAX 3 11-09-2004 03:10 PM
Changing my IP address tomCollins Java 3 03-23-2003 09:54 AM
changing UID in /etc/passwd? Admin Linux / BSD / OS X 4 09-05-2002 06:46 AM


All times are GMT -8. The time now is 04:42 AM.


Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0 RC8 ©2007, Crawlability, Inc.





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting