Jump to content

Recommended Posts

Notice: Undefined index: step in D:\xampp\htdocs\chrisauto\invoice.php on line 3

Cant remember how to fix this. i tried isset, empty, !, cant remember...

<?PHP
include('header.php');
switch($_REQUEST['step']){
default:
echo '[<a href="invoice.php?step=new">Create a new invoice</a>]<br/><br/>';
$pullinvoice = mysql_query("SELECT iid, customer FROM invoice ORDER BY iid")or die('There is no invoices. Make one?');
echo '<table border="1" cellpadding="5" cellspacing="0"><tr><td>Invoice ID</td><td width="200">Customer</td><td>Options</td></tr>';
while($invoice = mysql_fetch_array($pullinvoice)){
echo '<tr><td>'.$invoice['iid'].'</td><td>'.$invoice['customer'].'</td><td>[<a href="invoice.php?step=edit&inv='.$invoice['iid'].'">Edit</a>] [<a href="invoice.php?step=delete&inv='.$invoice['iid'].'">Delete</a>]</tr>';
}
echo '</table>';
break;
case 'edit':
$info = mysql_query("SELECT * FROM invoice WHERE iid=".$_REQUEST['inv'])or die('Invalid Invoice. Does not exist.');
while($inf = mysql_fetch_array($info)){
 
}
break;
}
include('footer.php');
?>
Notice: Undefined index: step in D:\xampp\htdocs\chrisauto\invoice.php on line 3 Edited by SynGreis
Link to comment
https://forums.phpfreaks.com/topic/303020-_request-error-when-empty/
Share on other sites

Add this to your script:

echo('$_REQUEST<pre>'.print_r($_REQUEST,1).'</pre>');
echo('$_GET<pre>'.print_r($_GET,1).'</pre>');
echo('$_POST<pre>'.print_r($_POST,1).'</pre>');

var_dump() provides more info, but the above is all you need and will be simpler to read.

thats not the problem.....the problem is when there is nothing stored in step.

 

http://localhost/chrisauto/invoice.php <=== on this link

 

Notice: Undefined index: step in D:\xampp\htdocs\chrisauto\invoice.php on line 3 <=== getting this error.

 

heres the code.

<?PHP
include('header.php');
switch($_REQUEST['step']){
default:
echo '[<a href="invoice.php?step=new">Create a new invoice</a>]<br/><br/>';
$pullinvoice = mysql_query("SELECT iid, customer FROM invoice ORDER BY iid")or die('There is no invoices. Make one?');
echo '<table border="1" cellpadding="5" cellspacing="0"><tr><td>Invoice ID</td><td width="200">Customer</td><td>Options</td></tr>';
while($invoice = mysql_fetch_array($pullinvoice)){
echo '<tr><td>'.$invoice['iid'].'</td><td>'.$invoice['customer'].'</td><td>[<a href="invoice.php?step=edit&inv='.$invoice['iid'].'">Edit</a>] [<a href="invoice.php?step=delete&inv='.$invoice['iid'].'">Delete</a>]</tr>';
}
echo '</table>';
break;
case 'edit':
$info = mysql_fetch_array(mysql_query("SELECT * FROM invoice WHERE iid=".$_REQUEST['inv']))or die('Invalid Invoice. Does not exist.');
echo '<form action="invoice.php?step=update&inv='.$info['iid'].'" method="post">';
echo '<table cellpadding="5" cellspacing="0">';
echo '<tr><td>Customer</td><td><input type="text" name="customer" value="'.$info['customer'].'"></td></tr>';
echo '<tr><td valign="top">Bill Address</td><td><textarea rows="5" name="baddress">'.$info['baddress'].'</textarea></td></tr>';
echo '<tr><td>Make</td><td><input type="text" name="make" value="'.$info['make'].'"></td></tr>';
echo '<tr><td>Model</td><td><input type="text" name="model" value="'.$info['model'].'"></td></tr>';
echo '<tr><td>Year</td><td><input type="text" name="year" value="'.$info['year'].'"></td></tr>';
echo '<tr><td>ODO Read</td><td><input type="text" name="odoread" value="'.$info['odoread'].'"></td></tr>';
echo '<tr><td>VIN</td><td><input type="text" name="vin" value="'.$info['vin'].'"></td></tr>';
echo '<tr><td colspan="2"><center><input type="submit" value="Update"></center></td></tr></table></form>';
break;
case 'update':
echo $_REQUEST['baddress'];
mysql_query("UPDATE invoice SET customer='".$_REQUEST['customer']."', `baddress`='".$_REQUEST['baddress']."', make='".$_REQUEST['make']."', model='".$_REQUEST['model']."', year='".$_REQUEST['year']."', odoread='".$_REQUEST['odoread']."', vin='".$_REQUEST['vin']."' WHERE iid=".$_REQUEST['inv'])or die(mysql_error());
//Header("Location: invoice.php?step=edit");
break;
}
include('footer.php');
?>
Edited by SynGreis

What nobody has mentioned is that your code is obsolete and insecure and has been completely removed from Php. If you want to do this correctly and have the freedom to change code as required we can talk. If you are of the mindset that you just want what you have to "work", or "have to" use this code then you are on your own as far as I go. The code is just all kinds of wrong.

Edited by benanamen

Okay, for starters, study this PDO tutorial and let me know when you have a grasp of it and we will go from there. The very first thing you're going to do is use PDO instead of the obsolete mysql_* code.

 

https://phpdelusions.net/pdo

 

You are also going to stop using REQUEST and your going to stop echoing HTML. 

 

It would be a good idea to post an sql dump of your DB if you are able. You can also PM it to me.

1. I need to make sure it is correct

2. I can follow along with something I can run

 

* While not a problem, an id column is named id or id_somthingrelated. iid is a bit odd. (Yeah, i get that it probably stands for inventory id.)

Edited by benanamen

You don't seem to realize what your real problem is. This is a classic XY Problem. See my signature for an explanation. You either want to do it right or you don't. Your code, including what you didnt post is junk and not fixable. It requires a complete rewrite. If you just want it to "work" until you're on a server with current Php and it just plain won't work no matter what, then someone else can "help" you. What happened to "open to new ways"?

Edited by benanamen

the queries isnt an issue i just put a wrapper to make it conform. Im not redoing all my scripts to be PDO compatible. So im already set when php7 rolls out.

I am essentially on my way OUT of PHP. I barely use it. And im not sure when the next time i will use it after this little project. Ill be doing minor updates but nothing major enough to cause me to relearn things. Too busy and im going away from web development.

 

So. The request...All i need to know how is to deal with it when there is an empty string. IT will just not cooperate and i cant remember how i did it in the past.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.