Page 1 of 2

$_server[php_self]

Posted: Mon Mar 01, 2004 8:59 am
by ol4pr0
Oke i keep on messing this up... ( some more, but this part i cant seem to get it right. )

Show me ones and for all how to do this !

Code: Select all

<form action=$_SERVER['php_self']; method=post>
<input type=text name=some maxlenght=10>
<input type=submit name=submit value=submit>
</form>

if (isset(..........)
	{
$host = 'localhost';
$usr = 'root';
$pwd = '';
$db = 'somedb';
$link = mysql_connect($host, $usr)
 or die ("mysql_error());
$result = mysql_select_db($db)
 or die (mysql_error());

$query ="INSERT INTO sometable (some_field) VALUES  ('".$_POST['some']."')"; 

$result = mysql_query($query);
if (!$query)
{
	die ("query couldnt be processed");
	}
}
else {
	"Some text message. ";
}
?>

Posted: Mon Mar 01, 2004 9:14 am
by JayBird
what exactly is the problem you are having.

One thing i see is that $_SERVER['php_self']; should be $_SERVER['PHP_SELF'];

(CaSe-SeNsItIvE)

Mark

Posted: Mon Mar 01, 2004 9:15 am
by JayBird
also on this line or die ("mysql_error());

you have an extra quote for some reason. Take it out!

mark

Posted: Mon Mar 01, 2004 9:19 am
by twigletmac
Probably PHP's case sensitivity catching you out ($_SERVER['PHP_SELF'] not $_SERVER['php_self']) but there's a few other issues with the code you posted (I guess it's probably just pseudo code but my rehash follows below):

Code: Select all

<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
	<input type="text" name="some" maxlength="10">
	<input type="submit" name="submit" value="submit">
</form>

<?php

if (isset(..........)) {
	$host = 'localhost';
	$usr = 'root';
	$pwd = '';
	$db = 'somedb';

	$link   = mysql_connect($host, $usr) or die(mysql_error());
	$result = mysql_select_db($db) or die(mysql_error());

	$query  = "INSERT INTO sometable (some_field) VALUES  ('".$_POST['some']."')";
	$result = mysql_query($query);

	// want to test $result not $query
	if (!$result) {
	   die('query couldnt be processed');
	} else {
		echo 'Some text message.';
	} 
}

?>
Mac

Posted: Mon Mar 01, 2004 9:40 am
by ol4pr0
my problem is that i dont get errors but it doesnt add anything in the db either..

and i want to get rid of the globals turned on in php.ini.

just just a simple example on how to have this done in the correct way would do fine. yea i know about the php_self... it was just for the example. ;-)

( i did use echo $query for debuggin purpose. which comes up fine.

http://some.net/submit=?some=? is also there..

Posted: Mon Mar 01, 2004 9:58 am
by twigletmac
So what's in the isset() bit?

Mac

Posted: Mon Mar 01, 2004 10:08 am
by ol4pr0

Code: Select all

a= '';

if (isset($_POST['some']))

	$a = '1';
}
}

if( $a == '1')
	{
$host='';
ect..

} else {


//...
}

Posted: Mon Mar 01, 2004 1:14 pm
by ol4pr0

Code: Select all

// unless something wrong with this...

$host = 'localhost';
$usr = 'root';
//$pwd = '';
$db = 'somedb';
$tb = 'info';

$link = mysql_connect($host, $usr)
 or die ("cant connect");
$result = mysql_select_db($db, $link)
 or die (mysql_error());

$query ="INSERT INTO ".$tb." (some1, some2, some3) VALUES  ('".$_POST['some1']."','".$_POST['some2']."','".$_POST['some3']."')"; 

$result = mysql_query($query);
ECHO $query;
if (!$query)
{
	die ("query couldnt be processed");
	}

else {
	"sorry. ";
}

Jumping In Late

Posted: Mon Mar 08, 2004 3:52 am
by evangelinux
I recognize that I'm jumping in late on this thread, but would someone please tell me where I can get an explanation of the $PHP_SELF variable?

Between the two books I have on PHP/MySQl actually say squat about it. One makes extensive use of it, but I can't for the life of me understand how to modify it. In just a simple example I tried out, I succesfully sent my input to the URL bar, or, using the POST method, to completely out of sight and out of mind! Even though I had the result code to echo the output to the browser, it just kept it stored hidden away.

Thanks

Posted: Mon Mar 08, 2004 3:54 am
by markl999

Posted: Mon Mar 08, 2004 12:44 pm
by evangelinux
Well, that certainly helped me to see the rest of the predefined variables in PHP. However, the info there wasn't very useful in terms of the example they offered. Apparently, I did understand that the variable is meant to open the browser window back on itself. What I seem to lack is an understanding of how to implement the variable in my code.

Thanks

Posted: Mon Mar 08, 2004 12:58 pm
by ol4pr0
And still cant figure out why this doesnt work
Yes i tried the <?php $_SERVER['PHP_SELF']; ?> in the action=' '

Code: Select all

<form name="jobs" method="post" action="jobadd.php">
 <table width="300" border="0" align="center" cellpadding="2" cellspacing="2">
  <tr>
   <td colspan="2" bgcolor=eeeeee>
    <div align=center><b>Adding a job</b></div>
   </td>
  </tr>
 <tr bgcolor=ffffff>
 <td>
 <div align=right></div>
 </td>
 <td>
 <input type=hidden name='jobid'>
 </td>
 </tr>
<tr bgcolor=ffffff>
<td>
<div align=right>Function</div>
</td>
<td>
<input type='text' name='funtion' maxlenght=100>
</td>
</tr>

 <tr bgcolor=ffffff>
 <td>
 <div align=right>descripcion</div>
 </td>
 <td>
 <input type='text' name='desc' maxlength=100>
 </td>
 </tr>
  <tr bgcolor=ffffff>
 <td>
 <div align=right>other</div>
 </td>
 <td>
 <input type='text' name='other' maxlength=100>
 </td>
 </tr>
 <tr bgcolor=ffffff>
 <td colspan="2">
 <center>
 <input type=submit name=submit value=submit>
 </center>
 </td>
 </tr>
 </table>
</form>
</body>
</html>
<?
include ("../../incfiles/config.inc");

if (isset($_GET['submit'])) {

        $jobstb = 'info';

        $link = mysql_connect($jhost, $jusr, $jpwd)
                 or die ( "Execute error: " .mysql_error());
        $result = mysql_select_db($jdb, $link)
                 or die ( "Execute error: " .mysql_error());

$query ="INSERT INTO ".$jobstb." (jobid, description other) VALUES  ('".$_POST['jobid']."','".$_POST['desc']."','".$_POST['other']."')";

$result = mysql_query($query);
ECHO $query; 
if (!$query)
{
        die ("query couldnt be processed");
}

else { ("sorry ");

  }
 }
?>

Posted: Mon Mar 08, 2004 1:09 pm
by ol4pr0
Oh.. this is whats in the config.inc

Code: Select all

// for jobs page

$jhost = '127.0.0.1';
$jusr = '3423kxi0';
$jpwd = 'xxx';
$jdb = 'jobs';

Posted: Mon Mar 08, 2004 2:09 pm
by d3ad1ysp0rk
your stuff is passed through $_POST, not $_GET

Posted: Mon Mar 08, 2004 2:53 pm
by ol4pr0
That indeed is a stupid thing i did miss, however it didnt add anything

nor did it return the

Code: Select all

echo $query;