SynGreis Posted January 24, 2017 Share Posted January 24, 2017 (edited) Notice: Undefined index: step in D:\xampp\htdocs\chrisauto\invoice.php on line 3Cant 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 January 24, 2017 by SynGreis Quote Link to comment Share on other sites More sharing options...
Barand Posted January 24, 2017 Share Posted January 24, 2017 If you can't remember the manual is there to jog your memory Quote Link to comment Share on other sites More sharing options...
SynGreis Posted January 24, 2017 Author Share Posted January 24, 2017 i have tried that... if(!isset($act)){$act = '';}else{$act = $_GET['act'];} i used to just do import_request_variables("GP"); but now its just being a douche.How can i do this correctly? Quote Link to comment Share on other sites More sharing options...
Barand Posted January 24, 2017 Share Posted January 24, 2017 You are getting an error on $_REQUEST['step'] So perhaps that is is the one you should be checking with isset() ? Quote Link to comment Share on other sites More sharing options...
SynGreis Posted January 24, 2017 Author Share Posted January 24, 2017 yea same error. I dod one for step and for act in another script. still the same thing. Quote Link to comment Share on other sites More sharing options...
NotionCommotion Posted January 24, 2017 Share Posted January 24, 2017 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. Quote Link to comment Share on other sites More sharing options...
SynGreis Posted January 25, 2017 Author Share Posted January 25, 2017 (edited) 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 January 25, 2017 by SynGreis Quote Link to comment Share on other sites More sharing options...
benanamen Posted January 25, 2017 Share Posted January 25, 2017 (edited) 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 January 25, 2017 by benanamen Quote Link to comment Share on other sites More sharing options...
SynGreis Posted January 25, 2017 Author Share Posted January 25, 2017 uhm...yea ofcourse im open to new ways. Its just i havent done php for a few years to be honest.... how would you handle this? Quote Link to comment Share on other sites More sharing options...
benanamen Posted January 25, 2017 Share Posted January 25, 2017 (edited) 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 January 25, 2017 by benanamen Quote Link to comment Share on other sites More sharing options...
SynGreis Posted January 25, 2017 Author Share Posted January 25, 2017 dude....this looks like a disaster just to do one query. And whats the alternative to $_REQUEST? Quote Link to comment Share on other sites More sharing options...
benanamen Posted January 25, 2017 Share Posted January 25, 2017 (edited) 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 January 25, 2017 by benanamen Quote Link to comment Share on other sites More sharing options...
SynGreis Posted January 25, 2017 Author Share Posted January 25, 2017 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. Quote Link to comment Share on other sites More sharing options...
SynGreis Posted January 25, 2017 Author Share Posted January 25, 2017 Solution if(!isset($_GET['step'])){$_GET['step'] = 'main';} not sure why it started working but it seems to be gone now.Please close this thread, Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted January 25, 2017 Share Posted January 25, 2017 im going away from web development. That might be the only good idea in this entire thread. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.