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
neon068
Forum Newbie
Posts: 10 Joined: Fri Feb 25, 2005 10:37 am
Post
by neon068 » Fri Feb 25, 2005 10:48 am
Ok, I'm new to both the DevNetwork forums and PHP so flame away
Anyways, I'm trying to make a small script but I suck so I can't get it to work.
What it supposed to do is just find a person in a database via an id number provided in the address bar (i.e. edit.php?id=7 ), edit it, then thats it. It will get everything fine but when I try to submit, it comes up with the echo 'the request is missing data';
Any help would be greatly appreciated!
Here's the code...
Code: Select all
<?
include_once ( 'config.php' );
if ( isset ( $_REQUESTї'id'] ) && ! empty ( $_REQUESTї'id'] ) )
{
if ( strtolower ( $_SERVERї'REQUESTED_METHOD'] ) == 'post' )
{
$query = array ();
if ( isset ( $_POSTї'firstname'] ) && ! empty ( $_POSTї'firstname'] ) )
{
$queryї] = "firstname = '" . mysql_real_escape_string ( $_POSTї'firstname'] ) . "'";
}
if ( isset ( $_POSTї'lastname'] ) && ! empty ( $_POSTї'lastname'] ) )
{
$queryї] = "lastname = '" . mysql_real_escape_string ( $_POSTї'lastname'] ) . "'";
}
if ( isset ( $_POSTї'email'] ) && ! empty ( $_POSTї'email'] ) )
{
$queryї] = "email = '" . mysql_real_escape_string ( $_POSTї'email'] ) . "'";
}
if ( ! empty ( $query ) )
{
$result = "UPDATE clients SET " . implode ( ', ', $query ) . " WHERE id = '" . mysql_real_escape_string ( $_REQUESTї'id'] ) . "'";
mysql_query ( $result ) or die ( 'UPDATE ERROR: ' . mysql_error () );
echo '<b>Thank you! client UPDATED Successfully!<br>';
echo '<meta http-equiv=Refresh content=2;url=index.php>';
}
else
{
echo 'the request did not contain any valid data, try again';
echo '<meta http-equiv=Refresh content=2;url=' . $SERVERї'PHP_SELF'] . '?id=' . $_REQUESTї'id'] .'>';
}
}
else
{
$result = "SELECT firstname, lastname, email FROM clients WHERE id = " . (int)$_REQUESTї'id'];
$r = mysql_query ( $result ) or die ( 'SELECT ERROR: ' . mysql_error () );
if ( mysql_num_rows ( $r ) > 0 )
{
$form = mysql_fetch_assoc ( $r );
?>
<h3>Edit Clients</h3>
<form method="post" action="<?=$_SERVERї'PHP_SELF'];?>">
<input type="hidden" name="id" value="<?=$formї'id'];?>">
firstname: <input name="firstname" size="50" maxlength="50" value="<?=htmlentities($formї'firstname']);?>">
<br>
lastname: <input name="lastname" size="50" maxlength="50" value="<?=htmlentities($formї'lastname']);?>">
<br>
email: <input name="email" size="50" maxlength="50" value="<?=htmlentities($formї'email']);?>">
<br>
<input type="submit" name="submit" value="Update Client">
</form>
<?
}
else
{
die ( 'QUERY ERROR: the id is not valid' );
}
}
}
else
{
echo 'the request is missing data';
}
?>
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Feb 25, 2005 10:54 am
check to make sure the id is being printed in the form's html. I suspect that you don't have short-tags on.
anjanesh
DevNet Resident
Posts: 1679 Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India
Post
by anjanesh » Fri Feb 25, 2005 10:56 am
Try using $_GET['id'];
neon068
Forum Newbie
Posts: 10 Joined: Fri Feb 25, 2005 10:37 am
Post
by neon068 » Fri Feb 25, 2005 11:00 am
I tryed using the following...
Code: Select all
<?php
$id = (int)$_REQUESTї'id'];
?>
<input type="hidden" name="id" value="<?=$id?>">
and this didn't work, unless I put it somewhere I shouldn't have. What I think is happening is that I'm not selecting the "id" column in the query, so $form['id'] does not have a value. But I am not sure how to fix it
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Feb 25, 2005 11:08 am
do anything? if so, you have short-tags off.
neon068
Forum Newbie
Posts: 10 Joined: Fri Feb 25, 2005 10:37 am
Post
by neon068 » Fri Feb 25, 2005 12:03 pm
nope... nothing works... here is a test of the script...
http://serasfinancial.com/testing/edit.php?id=1
id 1 and 2 work if you want to try it. This is the current code i'm using...
Code: Select all
<?
include_once ( 'config.php' );
$id = $_GETї'id'];
if ( isset ( $_REQUESTї'id'] ) && ! empty ( $_REQUESTї'id'] ) )
{
if ( strtolower ( $_SERVERї'REQUESTED_METHOD'] ) == 'post' )
{
$query = array ();
if ( isset ( $_POSTї'firstname'] ) && ! empty ( $_POSTї'firstname'] ) )
{
$queryї] = "firstname = '" . mysql_real_escape_string ( $_POSTї'firstname'] ) . "'";
}
if ( isset ( $_POSTї'lastname'] ) && ! empty ( $_POSTї'lastname'] ) )
{
$queryї] = "lastname = '" . mysql_real_escape_string ( $_POSTї'lastname'] ) . "'";
}
if ( isset ( $_POSTї'email'] ) && ! empty ( $_POSTї'email'] ) )
{
$queryї] = "email = '" . mysql_real_escape_string ( $_POSTї'email'] ) . "'";
}
if ( ! empty ( $query ) )
{
$result = "UPDATE clients SET " . implode ( ', ', $query ) . " WHERE id = '" . mysql_real_escape_string ( $_REQUESTї'id'] ) . "'";
mysql_query ( $result ) or die ( 'UPDATE ERROR: ' . mysql_error () );
echo '<b>Thank you! client UPDATED Successfully!<br>';
echo '<meta http-equiv=Refresh content=2;url=index.php>';
}
else
{
echo 'the request did not contain any valid data, try again';
echo '<meta http-equiv=Refresh content=2;url=' . $SERVERї'PHP_SELF'] . '?id=' . $_REQUESTї'id'] .'>';
}
}
else
{
$result = "SELECT firstname, lastname, email FROM clients WHERE id = " . (int)$_REQUESTї'id'];
$r = mysql_query ( $result ) or die ( 'SELECT ERROR: ' . mysql_error () );
if ( mysql_num_rows ( $r ) > 0 )
{
$form = mysql_fetch_assoc ( $r );
?>
<h3>Edit Clients</h3>
<form method="post" action="<?=$_SERVERї'PHP_SELF'];?>">
<?
$id = (int)$_REQUESTї'id'];
?>
<input type="hidden" name="id" value="<?=$id?>">
firstname: <input name="firstname" size="50" maxlength="50" value="<?=htmlentities($formї'firstname']);?>">
<br>
lastname: <input name="lastname" size="50" maxlength="50" value="<?=htmlentities($formї'lastname']);?>">
<br>
email: <input name="email" size="50" maxlength="50" value="<?=htmlentities($formї'email']);?>">
<br>
<input type="submit" name="submit" value="Update Client">
</form>
<?
}
else
{
die ( 'QUERY ERROR: the id is not valid' );
}
}
}
else
{
echo 'the request is missing data';
}
?>
I'll give you a big cookie if you can fix this!
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Feb 25, 2005 12:07 pm
the link requires http auth.
neon068
Forum Newbie
Posts: 10 Joined: Fri Feb 25, 2005 10:37 am
Post
by neon068 » Fri Feb 25, 2005 12:11 pm
Sorry... I forgot about that. It's
test/test123
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Feb 25, 2005 12:19 pm
hmmm just noticed.. you are using $_SERVER['REQUESTED_METHOD'] which doesn't exist.. $_SERVER['REQUEST_METHOD'] does however.
neon068
Forum Newbie
Posts: 10 Joined: Fri Feb 25, 2005 10:37 am
Post
by neon068 » Fri Feb 25, 2005 2:14 pm
ARG! thats it... Stupid error!
Thanks... here's your cookie!