snowdog Posted November 1, 2012 Share Posted November 1, 2012 (edited) Here is the input code <form action="process_add_staff.php" method="post"> <div class="form_default"> <fieldset> <legend>Add Staff</legend> <p> <label for="occupation">Choose Dealer</label> <select name="dealer_id"> <option>Choose Dealer</option> <?php // Load The dealers in for the franchisee include("include/db_connect.php"); //SESSION_START(); $franchise_id = $_SESSION['franchise_id']; // Query the database and get dealers $SQL = "SELECT * FROM dealers WHERE franchise_id = '$franchise_id' ORDER BY name ASC"; $result = mysql_query($SQL) or die(mysql_error()); while($run = mysql_fetch_array($result)) { ?><option value="<?php echo $run['id']; ?>"><?php echo $run["name"]; ?></option> <?php } ?> </select> </p> <p> <label for="name">First Name</label> <input type="text" name="first_name" class="sf" /> </p> <p> <label for="name">Last Name</label> <input type="text" name="last_name" class="sf" /> </p> <p> <label for="department">Department</label> <select name="department"> <option>Choose Department</option> <?php // Load The departments in // Query the database and get dealers $SQL = "SELECT * FROM departments WHERE franchise_id = '$franchise_id' ORDER BY department ASC"; $result = mysql_query($SQL) or die(mysql_error()); while($run = mysql_fetch_array($result)) { ?><option value="<?php echo $run['id']; ?>"><?php echo $run["department"]; ?></option> <?php } ?> </select> </p> <p class="number"> <label for="name">Phone Number</label> <input type="text" name="phone[]" class="sf" /> <select name="type[]"> <option value="1">Office</option> <option value="2">Cell</option> <option Value="3">Fax</option> </select> <a href="javascript:void();" class="add_phone">Add More</a> </p> <p> <label for="name">Phone Number</label> <input type="text" name="phone_1" class="sf" /> </p> <p> <label for="email">Email</label> <input type="text" name="email" class="sf" /> </p> <p> <button>Submit</button> </p> </fieldset> </div><!--form--> </form> and here is the process page. I have been trying to isolate the error but I just get a blank screen. I am trying to echo out the multiple phone numbers and types but nodda. <?php include("include/db_connect.php"); SESSION_START(); //$dealer_name = $_REQUEST['d_name']; //$d_address = $_REQUEST['d_address']; //$d_city = $_REQUEST['d_city']; //$d_country = $_REQUEST['d_country']; //$d_state_prov = $_REQUEST['d_state_prov']; //$d_zip = ereg_replace("[^0-9a-zA-Z]","", $_REQUEST['d_zip']); //$d_phone_1 = ereg_replace("[^0-9]", "", $_REQUEST['d_phone_1']); //$d_email = $_REQUEST['d_email']; //$franchise_id = $_SESSION['franchise_id']; //$username = $d_email; //$password = $d_phone_1; //$website = $_REQUEST['website']; //$SQL = "INSERT INTO dealers (franchise_id, name, address, city, state, zip, country, website, created, modified) VALUES ('$franchise_id','$dealer_name','$d_address','$d_city','$d_state_prov','$d_zip','$d_country','$website',NOW(),NOW())"; //$result = mysql_query($SQL) or die('Query failed: ' . mysql_error()); //$dealer_id = mysql_insert_id(); //$SQL = "INSERT INTO login (franchise_id,dealer_id,department_id,first,last,email,username,password,created,modified) VALUES ('$franchise_id','$dealer_id','1','$first_name','$last_name','$d_email','$username','$password',NOW(),NOW())"; //$result = mysql_query($SQL) or die('Query failed: ' . mysql_error()); // Redirect back to add_dealer.php //header('Location: add_staff.php?m=1') ; for( $i = 0; $i < count($_REQUEST['phone']); $i++ ) { echo(" $_REQUEST['type'][$i] = $_REQUEST['phone'][$i] <br >"); } ?> Any help would be great. Thanks Snowdog Edited November 1, 2012 by snowdog Quote Link to comment https://forums.phpfreaks.com/topic/270138-loop-problem/ Share on other sites More sharing options...
White_Lily Posted November 1, 2012 Share Posted November 1, 2012 Try to use error reporting. create a php.ini file and inside that type: display_errors = on error_reporting = -1 Quote Link to comment https://forums.phpfreaks.com/topic/270138-loop-problem/#findComment-1389144 Share on other sites More sharing options...
PFMaBiSmAd Posted November 1, 2012 Share Posted November 1, 2012 (edited) If you take a look at the color highlighting that the forum software did to your posted code (and you should be using a programming editor that does color highlighting too), you will notice that your sql query statements that are made up of more than one line are showing the second line as php code. You commented out the first line in a couple of your $sql statements, but the second line is now being treated as a line of php code by itself and is producing a php syntax error, which is a fatal parse error and your code never runs. You need to comment out all the lines of a multiple-line query statement. You need to have php's error_reporting set to E_ALL and display_errors set to ON in your master php.ini on your development system so that php will report and display all the errors it detects. If php is running as a cgi application and supports a local php.ini, you can put the settings into a local php.ini (you may have to repeat this in each folder where you make http requests to a file at, depending on how the server is setup to read local php.ini files.). If php is running as an Apache module, you can put equivalent settings (the syntax and values are different) into a .htaccess file. Because the php syntax error is in your main file, putting the two settings into your main code won't turn on the settings because your main code never runs. Edited November 1, 2012 by PFMaBiSmAd Quote Link to comment https://forums.phpfreaks.com/topic/270138-loop-problem/#findComment-1389153 Share on other sites More sharing options...
snowdog Posted November 1, 2012 Author Share Posted November 1, 2012 have done that, still not displaying, have asked tech support of my server company to look into this. Anyone see the problem. This could take tech awhile? Quote Link to comment https://forums.phpfreaks.com/topic/270138-loop-problem/#findComment-1389281 Share on other sites More sharing options...
Muddy_Funster Posted November 1, 2012 Share Posted November 1, 2012 can we see your code as it is now, after the changes PFMaBiSmAd suggested? Quote Link to comment https://forums.phpfreaks.com/topic/270138-loop-problem/#findComment-1389300 Share on other sites More sharing options...
PFMaBiSmAd Posted November 1, 2012 Share Posted November 1, 2012 This isn't a server issue, unless you had a problem setting the error_reporting/display_errors settings on your server. It's a problem in your code. You should be learning php and developing/debugging php code on a local development system. You will save a TON of time. Only complete and tested code should be put onto a live server. Quote Link to comment https://forums.phpfreaks.com/topic/270138-loop-problem/#findComment-1389322 Share on other sites More sharing options...
Muddy_Funster Posted November 1, 2012 Share Posted November 1, 2012 (edited) here's a thought, just before your for loop at the bottom of your process page add in var_dump($_POST); Edited November 1, 2012 by Muddy_Funster Quote Link to comment https://forums.phpfreaks.com/topic/270138-loop-problem/#findComment-1389328 Share on other sites More sharing options...
snowdog Posted November 1, 2012 Author Share Posted November 1, 2012 Here is the code <?php // include("include/db_connect.php"); // SESSION_START(); //$dealer_name = $_REQUEST['d_name']; //$d_address = $_REQUEST['d_address']; //$d_city = $_REQUEST['d_city']; //$d_country = $_REQUEST['d_country']; //$d_state_prov = $_REQUEST['d_state_prov']; //$d_zip = ereg_replace("[^0-9a-zA-Z]","", $_REQUEST['d_zip']); //$d_phone_1 = ereg_replace("[^0-9]", "", $_REQUEST['d_phone_1']); //$d_email = $_REQUEST['d_email']; //$franchise_id = $_SESSION['franchise_id']; //$username = $d_email; //$password = $d_phone_1; //$website = $_REQUEST['website']; //$SQL = "INSERT INTO dealers (franchise_id, name, address, city, state, zip, country, website, created, modified) // VALUES ('$franchise_id','$dealer_name','$d_address','$d_city','$d_state_prov','$d_zip','$d_country','$website',NOW(),NOW())"; //$result = mysql_query($SQL) or die('Query failed: ' . mysql_error()); //$dealer_id = mysql_insert_id(); //$SQL = "INSERT INTO login (franchise_id,dealer_id,department_id,first,last,email,username,password,created,modified) // VALUES ('$franchise_id','$dealer_id','1','$first_name','$last_name','$d_email','$username','$password',NOW(),NOW())"; //$result = mysql_query($SQL) or die('Query failed: ' . mysql_error()); // Redirect back to add_staff.php //header('Location: add_staff.php?m=1') ; for( $i = 0; $i < count($_REQUEST['phone']); $i++ ) { echo(" $_REQUEST['type'][$i] = $_REQUEST['phone'][$i] <br>"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/270138-loop-problem/#findComment-1389329 Share on other sites More sharing options...
Muddy_Funster Posted November 1, 2012 Share Posted November 1, 2012 (edited) I'm going to assume you are getting a blank page, not because of the level of error reporting, but simply because the $_REQUEST super global array is in fact empty (or at the very least, does not contain the key's that you are trying to output, but that should give an error/warning about undefined index values or some such). as you arn't attempting to send any information to the screen other than what would/should/could be in this array. try my suggestion above and let us know what you get back. Edited November 1, 2012 by Muddy_Funster Quote Link to comment https://forums.phpfreaks.com/topic/270138-loop-problem/#findComment-1389339 Share on other sites More sharing options...
snowdog Posted November 1, 2012 Author Share Posted November 1, 2012 (edited) Here is the output : array(0) { } and here is the code from previous page <?php include("include/header.php"); include("include/top_menu.php"); include("include/left_menu.php"); ?> <div class="maincontent"> <div class="breadcrumbs"> <a href="dashboard.html">Dashboard</a> <span>Add Staff</span> </div><!-- breadcrumbs --> <div class="left"> <h1 class="pageTitle">Add Staff</h1> <form action="process_add_staff.php" method="post"> <div class="form_default"> <fieldset> <legend>Add Staff</legend> <p> <label for="occupation">Choose Dealer</label> <select name="dealer_id"> <option>Choose Dealer</option> <?php // Load The dealers in for the franchisee include("include/db_connect.php"); //SESSION_START(); $franchise_id = $_SESSION['franchise_id']; // Query the database and get dealers $SQL = "SELECT * FROM dealers WHERE franchise_id = '$franchise_id' ORDER BY name ASC"; $result = mysql_query($SQL) or die(mysql_error()); while($run = mysql_fetch_array($result)) { ?><option value="<?php echo $run['id']; ?>"><?php echo $run["name"]; ?></option> <?php } ?> </select> </p> <p> <label for="name">First Name</label> <input type="text" name="first_name" class="sf" /> </p> <p> <label for="name">Last Name</label> <input type="text" name="last_name" class="sf" /> </p> <p> <label for="department">Department</label> <select name="department"> <option>Choose Department</option> <?php // Load The departments in // Query the database and get dealers $SQL = "SELECT * FROM departments WHERE franchise_id = '$franchise_id' ORDER BY department ASC"; $result = mysql_query($SQL) or die(mysql_error()); while($run = mysql_fetch_array($result)) { ?><option value="<?php echo $run['id']; ?>"><?php echo $run["department"]; ?></option> <?php } ?> </select> </p> <p class="number"> <label for="name">Phone Number</label> <input type="text" name="phone[]" class="sf" /> <select name="type[]"> <option value="1">Office</option> <option value="2">Cell</option> <option Value="3">Fax</option> </select> <a href="javascript:void();" class="add_phone">Add More</a> </p> <p> <label for="name">Phone Number</label> <input type="text" name="phone_1" class="sf" /> </p> <p> <label for="email">Email</label> <input type="text" name="email" class="sf" /> </p> <p> <button>Submit</button> </p> </fieldset> </div><!--form--> </form> <br /> </div><!--fullpage--> <br clear="all" /> </div><!--maincontent--> <?php include("include/footer.php"); ?> Edited November 1, 2012 by snowdog Quote Link to comment https://forums.phpfreaks.com/topic/270138-loop-problem/#findComment-1389345 Share on other sites More sharing options...
White_Lily Posted November 1, 2012 Share Posted November 1, 2012 theres your problem then , idont think the array has any values to output lol Quote Link to comment https://forums.phpfreaks.com/topic/270138-loop-problem/#findComment-1389346 Share on other sites More sharing options...
snowdog Posted November 1, 2012 Author Share Posted November 1, 2012 Thanks White, I do have problems with arrays just can't grasp my head around them sometimes. Am going to scour the previous page and see if I can find it. Knowing me it is something very simple and stupid that I have missed. Quote Link to comment https://forums.phpfreaks.com/topic/270138-loop-problem/#findComment-1389350 Share on other sites More sharing options...
snowdog Posted November 1, 2012 Author Share Posted November 1, 2012 Think I might have found it. I had Session_start() turned off on the input page and now I am getting this. array(7) { ["dealer_id"]=> string(2) "17" ["first_name"]=> string(5) "James" ["last_name"]=> string( "Clausner" ["department"]=> string(1) "3" ["phone"]=> array(1) { [0]=> string(10) "4164536935" } ["type"]=> array(1) { [0]=> string(1) "2" } ["email"]=> string(15) "james@james.com" } Quote Link to comment https://forums.phpfreaks.com/topic/270138-loop-problem/#findComment-1389352 Share on other sites More sharing options...
White_Lily Posted November 1, 2012 Share Posted November 1, 2012 problem sorted. now you just gotta figure out what to do with that array lol Quote Link to comment https://forums.phpfreaks.com/topic/270138-loop-problem/#findComment-1389354 Share on other sites More sharing options...
Muddy_Funster Posted November 1, 2012 Share Posted November 1, 2012 Your loop should now give output. As you are using post to send the data, you really should address the $_POST array directly (just replace $_REQUEST with $_POST) Quote Link to comment https://forums.phpfreaks.com/topic/270138-loop-problem/#findComment-1389357 Share on other sites More sharing options...
snowdog Posted November 1, 2012 Author Share Posted November 1, 2012 (edited) ok so the values are coming through properly now. I have eliminated everything out of the process page but the array loop and am getting no output . My guess is the area of problem is in the loop where I am trying to count the number of rows in the array. <?php include("include/db_connect.php"); SESSION_START(); for( $i = 0; $i < count($_POST['phone']); $i++ ) { echo(" $_POST['type'][$i] = $_POST['phone'][$i] <br>"); } //var_dump($_POST); ?> Edited November 1, 2012 by snowdog Quote Link to comment https://forums.phpfreaks.com/topic/270138-loop-problem/#findComment-1389364 Share on other sites More sharing options...
snowdog Posted November 1, 2012 Author Share Posted November 1, 2012 I have the right information coming through, the right count is there. But as soon as I uncomment the for loop it gives me the white screen of death. I can't find the stupid error. Here is the output array(7) { ["dealer_id"]=> string(2) "16" ["first_name"]=> string(5) "James" ["last_name"]=> string( "Clausner" ["department"]=> string(1) "3" ["phone"]=> array(3) { [0]=> string(10) "4168887467" [1]=> string(10) "9058336888" [2]=> string(10) "4164536935" } ["type"]=> array(3) { [0]=> string(1) "1" [1]=> string(1) "3" [2]=> string(1) "2" } ["email"]=> string(15) "james@james.com" } COUNT: 3 Here is the for loop code var_dump($_POST); $array_count = count($_POST['phone']); echo("<br><br>COUNT: $array_count "); for ($i = 0, $i < $array_count; $i++) { echo(" $i <br>"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/270138-loop-problem/#findComment-1389367 Share on other sites More sharing options...
snowdog Posted November 1, 2012 Author Share Posted November 1, 2012 (edited) ok now have gotten further, The error was a comma instead of a semi colon after $i=0. Now I am getting this array(7) { ["dealer_id"]=> string(2) "16" ["first_name"]=> string(5) "James" ["last_name"]=> string( "Clausner" ["department"]=> string(1) "3" ["phone"]=> array(2) { [0]=> string(10) "4168887467" [1]=> string(12) "905-833-6888" } ["type"]=> array(2) { [0]=> string(1) "1" [1]=> string(1) "1" } ["email"]=> string(15) "james@james.com" } COUNT: 2 The array row is: 0 The array row is: 1 but as soon as I add in, get white screen var_dump($_POST); $array_count = count($_POST['phone']); echo("<br><br>COUNT: $array_count <br><br><br>"); for ($i = 0; $i < $array_count; $i++) { echo("The array row is: $i <br>"); echo(" $_POST['type'][$i] = $_POST['phone'][$i] <br>"); } Edited November 1, 2012 by snowdog Quote Link to comment https://forums.phpfreaks.com/topic/270138-loop-problem/#findComment-1389384 Share on other sites More sharing options...
Barand Posted November 1, 2012 Share Posted November 1, 2012 When trying to echo array values (particularly multi-dim arrays) put them in {}s eg echo(" {$_POST['type'][$i]} = {$_POST['phone'][$i]} <br>"); Quote Link to comment https://forums.phpfreaks.com/topic/270138-loop-problem/#findComment-1389392 Share on other sites More sharing options...
snowdog Posted November 1, 2012 Author Share Posted November 1, 2012 Thank you very much, That worked Quote Link to comment https://forums.phpfreaks.com/topic/270138-loop-problem/#findComment-1389412 Share on other sites More sharing options...
Christian F. Posted November 1, 2012 Share Posted November 1, 2012 snowdog: In case you're still struggling with understanding arrays, think of them as a sheet of paper. 1 dimensional arrays ($array[X]) are like a lined paper, on which each line can have a different value. 2 dimensional arrays ($array[X][Y]) are like a squared (math) paper, where each box can have a different value. 3 dimensional arrays will be like a stack of squared paper, where Z denotes the position of the sheet from the top. You can even picture them as a shelf, if you'd like. The point is that an array is just a collection of compartments, that each hold a single value. The tricky part is that said value can also be an array, creating the multiple dimensions. However, if you keep the mental model simple and consistent, it should be very easy to understand them. Quote Link to comment https://forums.phpfreaks.com/topic/270138-loop-problem/#findComment-1389469 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.