PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Mon Mar 01, 2004 8:59 am
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. ";
}
?>
JayBird
Admin
Posts: 4524 Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:
Post
by JayBird » Mon Mar 01, 2004 9:14 am
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
JayBird
Admin
Posts: 4524 Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:
Post
by JayBird » Mon Mar 01, 2004 9:15 am
also on this line or die ("mysql_error());
you have an extra quote for some reason. Take it out!
mark
twigletmac
Her Royal Site Adminness
Posts: 5371 Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK
Post
by twigletmac » Mon Mar 01, 2004 9:19 am
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
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Mon Mar 01, 2004 9:40 am
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..
twigletmac
Her Royal Site Adminness
Posts: 5371 Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK
Post
by twigletmac » Mon Mar 01, 2004 9:58 am
So what's in the isset() bit?
Mac
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Mon Mar 01, 2004 10:08 am
Code: Select all
a= '';
if (isset($_POST['some']))
$a = '1';
}
}
if( $a == '1')
{
$host='';
ect..
} else {
//...
}
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Mon Mar 01, 2004 1:14 pm
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. ";
}
evangelinux
Forum Newbie
Posts: 4 Joined: Thu Mar 04, 2004 4:13 pm
Location: Charlotte, NC
Post
by evangelinux » Mon Mar 08, 2004 3:52 am
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
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Mon Mar 08, 2004 3:54 am
evangelinux
Forum Newbie
Posts: 4 Joined: Thu Mar 04, 2004 4:13 pm
Location: Charlotte, NC
Post
by evangelinux » Mon Mar 08, 2004 12:44 pm
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
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Mon Mar 08, 2004 12:58 pm
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 ");
}
}
?>
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Mon Mar 08, 2004 1:09 pm
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';
d3ad1ysp0rk
Forum Donator
Posts: 1661 Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA
Post
by d3ad1ysp0rk » Mon Mar 08, 2004 2:09 pm
your stuff is passed through $_POST, not $_GET
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Mon Mar 08, 2004 2:53 pm
That indeed is a stupid thing i did miss, however it didnt add anything
nor did it return the