Cheap Gas - Debt Consolidation - Credit Counseling - Arizona Pools
need help [Archive] - Threeboy Forums

PDA

View Full Version : need help


snow
12-15-2003, 09:49 PM
ok i'm trying to create a small backend right now just to post what game i'm playing now and what song i'm listening to but it won't take the input from the form. Here is the code.
[code:1]<?
include("config.php");

$connection = mysql_connect($dbhost,$dbuser,$dbpasswd)
or die ("couln't post");
$db = mysql_select_db($dbname,$connection)
or die ("couldn't select database");

function index (){
echo "
<form>
< method=post form action=post.php?cmd=post>
<table width=100% border=0 cellpadding=4 cellspacing=0>
<tr>
<td width=24% align=left valign=top>Gamename</td>
<td width=76%><input name=playing type=text id=playing</td>
</tr>
<tr>
<td align=left valign=top>current song</td>
<td><input name=listening type=text id=listening</td>
</tr>
<tr>
<td align=left valign=top></td>
<input type=\"hidden\" name=\"cmd\" value=\"results\">
<td><input type=submit name=cmd value=post></td>
</tr>
</table>
</form>";
}
function results ()
{
}

function post()
{
include("config.php");

$listening = $_post['listening'];
$playing = $_post['playing'];


$query = ("INSERT INTO about (listening,playing,createDate) VALUES
('$listening','$playing',Now())");

$result = mysql_query($query)
or die ("couldn't post.");
$ID = mysql_insert_id();

echo "thx for posting:
<ul>
<li>song: $listening
<li>game: $playing
<li>time: createDate";
}

switch($_REQUEST['cmd']){ //updated to work with register_globals "off";

default:
index();
break;

case "post":
post();
break;
}

?>
[/code:1]

snow
12-22-2003, 10:44 PM
can someone please help me.

12-23-2003, 12:54 AM
this is probably too advanced for the people of threeboy forums.

try going to http://www.tutorialforums.com

zubaz
12-23-2003, 09:09 AM
maybe it's too advanced for YOU shoa :P -- see down there in your switch with your cases? Well "post" needs to read like this.

[code:1]case "post":
post($_post);
break;

and then your post function has to reflect that...

function post($_post) {
blah blah my function
}[/code:1]

$_post is a global but it either needs to be declared or an input for the function for it to exist in there.

snow
12-23-2003, 02:10 PM
still can't get it working here it is updated[code:1]<?
include("config.php");

$connection = mysql_connect($dbhost,$dbuser,$dbpasswd)
or die ("couln't post");
$db = mysql_select_db($dbname,$connection)
or die ("couldn't select database");

function index (){
echo "
<form>
<method=post form action=post.php?cmd=post>
<table width=100% border=0 cellpadding=4 cellspacing=0>
<tr>
<td width=24% align=left valign=top>Gamename</td>
<td width=76%><input name=playing type=text id=playing</td>
</tr>
<tr>
<td align=left valign=top>current song</td>
<td><input name=listening type=text id=listening</td>
</tr>
<tr>
<td align=left valign=top></td>
<input type=\"hidden\" name=\"cmd\" value=\"results\">
<td><input type=submit name=cmd value=post></td>
</tr>
</table>
</form>";
}
function results ()
{
}

function post($_post)
{
include("config.php");

$listening = $_post['listening'];
$playing = $_post['playing'];


$query = ("INSERT INTO about (listening,playing,createDate) VALUES
('$listening','$playing',Now())");

$result = mysql_query($query)
or die ("couldn't post.");
$ID = mysql_insert_id();

echo "thx for posting:
<ul>
<li>song: $listening
<li>game: $playing
<li>time: createDate";
}

switch($_REQUEST['cmd']){ //updated to work with register_globals "off";

default:
index();
break;

case "post":
post($_post);
break;
}

?>[/code:1]

12-23-2003, 02:44 PM
maybe it's too advanced for YOU shoa :P

onoes! :(

zubaz
12-23-2003, 02:51 PM
are you sure that $_post has your variables? make sure those aren't empty - and if they aren't then send $_post('listening') itself to the function.

snow
12-23-2003, 08:11 PM
that's what happening, whenever i post it doesn't take the stuff i entered, but i know it's working because it posts the time and the date.

zubaz
12-23-2003, 08:31 PM
is registered globals turned on? in about 99% of servers, you can just use $listening and $playing as the variables. You'll still need to pass them to the function though. If THAT doesn't work try using the $_REQUEST array you used for the switch function. Like $_REQUEST['playing'] and whatnot.

brentech
12-23-2003, 10:43 PM
is registered globals turned on? in about 99% of servers, you can just use $listening and $playing as the variables. You'll still need to pass them to the function though. If THAT doesn't work try using the $_REQUEST array you used for the switch function. Like $_REQUEST['playing'] and whatnot.
i'm just going to start calling you masta

zubaz
12-24-2003, 11:26 AM
is registered globals turned on? in about 99% of servers, you can just use $listening and $playing as the variables. You'll still need to pass them to the function though. If THAT doesn't work try using the $_REQUEST array you used for the switch function. Like $_REQUEST['playing'] and whatnot.
i'm just going to start calling you masta
that is acceptable.

snow
01-04-2004, 09:04 PM
Ok i got the script to post now i was wondering how do you choose the latest entry from a database. i've got id and date attached to it.

zubaz
01-05-2004, 05:31 AM
you can sort by either one
[code:1]$query = mysql_query("SELECT * FROM `mytable` WHERE `stuffimlookingfor`='true' ORDER BY `id` DESC ");[/code:1]

[code:1]$query = mysql_query("SELECT * FROM `mytable` WHERE `stuffimlookingfor`='true' ORDER BY `date` DESC ");[/code:1]
and then your array is...
[code:1]$myArray = mysql_fetch_array($query);
$id = $myArray[id];
$name = $my Array[name];
etc.[/code:1]

I'd probably go with date, just because if for some reason the id pointer got reset, you wouldn't have made your whole program obselete. If you don't know what i'm talking about with the pointer, don't worry about it. You see where it says "DESC"? Just for future reference, the other option to put there is "ASC" meaning ascending. And also, pay attention to what quotes i used where, they DO matter. Just as a rule of thumb ` quotes are for names of things and ' quotes are for values.

snow
01-05-2004, 03:46 PM
just a question what is stuff i'm looking for.

zubaz
01-05-2004, 09:36 PM
the WHERE part isn't necessary, I just put in there just in case.

where I use it is stuff like `author`='zubaz' or something of the like regarding news posts. You can either remove the WHERE statement altogether or put it as "WHERE 1" which just returns true for everything.

SileNceR
01-06-2004, 04:17 AM
umm... it's your html at fault..

<form>
<method=post form action=post.php?cmd=post>

should be <form method=\"post\" action=\"post.php"><input type=\"hidden\" name=\"cmd\" value=\"post\">

also if u wanna do html blocks its easier to open them with ' not " that way u dont have to escape all ur damn "s

zubaz
01-06-2004, 06:05 AM
umm... it's your html at fault..

<form>
<method=post form action=post.php?cmd=post>

should be <form method=\"post\" action=\"post.php"><input type=\"hidden\" name=\"cmd\" value=\"post\">

also if u wanna do html blocks its easier to open them with ' not " that way u dont have to escape all ur damn "s
His method and action are fine, you can post to a compound url.

SileNceR
01-06-2004, 07:08 AM
k, w3c says quotes tho :P

still the form tag is seriously deformed in his version hehe