Jump to content
Larry Ullman's Book Forums

fishswim

Members
  • Content Count

    9
  • Joined

  • Last visited

Posts posted by fishswim


  1. Hello

    On page 368 MySQL second edition

    when i write this script out and send it through the browser ...

     

    Warning mysqli_fetch array() expects parameter 1 to be mysqli_result, boolean given /file/string/file/string

     

    I have gone into the PHP web site and type in mysqli_fetch_array to look at the syntax and the page i am directed to shows, mysqli_result::fetch_array

     

    and the calls in the PHP manual page for mysqli_result::fetch_array are the same as in the script in the book.

    $query = SELECT etc
    
    $r or result = mysqli_query($link, $query);
    
    The warning in the browser is from this line of the script in the book
    
    list($num_records) = mysqli_fetch_array($result, MYSQLI_NUM);
    ---------------------------------------------
    if i reconstruct the call to:
    
    list ($num_records = mysqli_fetch_array($result, MYSQLI_NUM));
    
    the warning`s change to one warning:
    
    syntax error, unexpected '=' expecting ',' or ')'
    
    if i use a , the results are fatal error: cannot use function return value in write context.
    
    and if a remove the , and close ) the list() call:
    Parse error, syntax error, unexpected mysql_fetch_array expexting '='
    
    and then its back to parameter 1 expecting to be mysql_result, boolean given.  
    
    
    
    
     

    I also added the script from the PHP manual

    mysqli::real_connect

    and it works as a stand alone when called by the browser,

     

    Does any one have any suggestions

    Thank you.


  2. I am working with PHP Third edition and MySQL second edition - both show php mysql scripts.

     

    working with PHP for the web, third edition, page 373, modify the script to accept value from form field 

    and then and to receive data from database.

     

    I have re worked this many times over and am frustrated to the point of brain freeze.

     

    what can i do to receive the business name associated with zip code in database.

    any assistance ? thank you.

    <?php
    if ( isset($_POST['submitted']) ) {
    
       $baz = $_POST['zip'];
    
       $dbc = mysql_connect('localhost', 'usr_name', 'password');
       mysql_select_db('data_base_name');
    
    //$query = 'SELECT biz_name FROM retail_client WHERE zip_code = 99201';
    //$query = 'SELECT biz_name FROM retail_client WHERE zip_code = \'$baz\' ';
    
    
    // error message: mysql_query() expects parameter 2 to be resource,
    
    
    if($r = mysql_query('$dbc' 'SELECT biz_name FROM retail_client WHERE zip_code = 99201')) {
    
    while ($row = mysql_fetch_array($r) {
    
    print "<p> {$row['biz_name']} </p>";
    
    } // while
    } // two
    } //ONE 
    
    print ' <form action="this_script.php" method="post">
    
    <p>Zip code:
     
    <input type="text" name="zip" size="10" /></p>
    
    <input type="submit" name="submit" value="go" />
    
    <input type="hidden" name="submitted" value="true" />
     
    </form> ';
    
    ?>
     

  3. There is received this error notice.

    Notice: Undefined index: temp_name
    

    and the if conditional in the script as written in the end user`s script and book shows:

    if(move_uploaded_file($_FILES['thefile']['temp_name'], "../t_testUploads/{$_FILES['thefile']['name']}"))
    

    I do see in the ini file:

    upload_tmp_dir = /Applications/MAMP/tmp/php
    

    before i attempt to place the value of /Applications/MAMP/tmp/php in place of temp_name.

    so the actual question here is,

    will placing the ini file value of /Applications/MAMP/tmp/php in place of temp_index do the trick.

     

    note, i am working a graveyard shift so the brain and action is in a state of ask questions first. normally i would just jump and see what happens.

     

    Thank you.


  4. I am working thru chapter 8, page 214 and supplementing my own code to see what works.

     

    If i have a separate conditional for each $_POST[] array first_name, last_name, email etc and then place the

    conditional to print out the values at the bottom before the closing bracket that began with the first initial conditional, i do receive error messages as shown below in the first code example.

     

    Why would that be.

    If each conditional to print out the value from the $POST array can print out its value in its own conditional, following a conditional using the same index in its own conditional.

    Or put another way.

    If there is one value from a html form in a post array and that value can be accessed in a conditional.

    why is that value not available several conditional`s below its first iteration.

     

    does this particular situation have something to do with " stack " or is the stack, [deal with] functions only.

     

    Thank you in advance for any response.

     

     

    // the error messages:
    
    //Notice: Undefined index: first_name in /somewhere/ qC_stickyRegister.php on line 73
    
    //Notice: Undefined index: last_name in /somewhere/qC_stickyRegister.php on line 78
    
    //Notice: Undefined index: email in /somewhere/qC_stickyRegister.php on line 83
    
    
    if(!empty($_POST['submitted']))
    	{
    		$problem = FALSE;
    
    		if(empty($_POST['first_name']))
    		{
    			$problem = TRUE;
    			print'<p class="error">Please enter a first name.</p>';
    		} 	
    		//----------------------------------------
    		if(empty($_POST['last_name']))
    		{
    			$problem = TRUE;
    			print'<p class="error">Please enter a last name</p>';
    		}
    		//---------------------------------------
    		if(empty($_POST['email']))
    		{
    			$problem = TRUE;
    			print'<p class="error">Please enter your e mail address</p>';
    		}
    		//-------------------------------------------
    		if(empty($_POST['password1']))
    		{
    			$problem = TRUE;
    			print'<p class="error">Please provide a password.</p>';
    		} 
    		//-----------------------------------------
    		if($_POST['password1'] != $_POST['password2'])
    		{
    			$problem = TRUE;
    			print'<p class="error">Your passwords do not match.</p>';
    		}
         //------------------------------------------------------------------------------
    
    		if(!$problem)
    		{
    			print'<p>Registration is good.</p>';
    			$_POST = array();
    		} else {
    			print'<p class="error">Something went wrong</p>';
    		}
    // ----------CONDITIONALS TO PRINT OUT THE VALUES ------------------	
    
    		if($_POST['first_name'] == TRUE)
    		{
    			$Fname = $_POST['first_name'];
    			print "<p>If the following information is correct please press proceed. <br />First Name: $Fname <br />";
    		}
    
    		if($_POST['last_name'] == TRUE)
    		{
    			$Lname = $_POST['last_name'];
    			print "Last Name: $Lname <br />";
    		}
    
    		if($_POST['email'] == TRUE)
    		{
    			$mailE = $_POST['email'];
    			print "E mail Address: $mailE </p>";
    		}
    
    	}
    

     

     

    And This Does Work ...

     

    if(!empty($_POST['submitted']))
    	{
    		$problem = FALSE;
    		//------------------------------	
    		if(empty($_POST['first_name']))
    		{
    			$problem = TRUE;
    			print'<p class="error">Please enter a first name.</p>';
    		} 
    		//-------------------------------
    		if($_POST['first_name'] == TRUE)
    		{
    			$Fname = $_POST['first_name'];
    			print "<p>If the following information is correct please press proceed. <br />First Name: $Fname <br />";
    		}
    //----------------------------------------------------------------
    		if(empty($_POST['last_name']))
    		{
    			$problem = TRUE;
    			print '<p class="error"Please enter a Last name</p>';
    		}
    		//-------------------------------
    		if($_POST['last_name'] == TRUE)
    		{
    			$Lname = $_POST['last_name'];
    			print "Last Name: $Lname <br />";
    		}
    //------------------------------------------------------------------------------
    		if(empty($_POST['email']))
    		{
    			$problem = TRUE;
    			print'<p class="error">Please enter your e mail address</p>';
    		}
    		//--------------------------------
    		if($_POST['email'] == TRUE)
    		{
    			$mailE = $_POST['email'];
    			print "E mail Address: $mailE </p>";
    		}
    //--------------------------------------------------------------------------			
    		if(empty($_POST['password1']))
    		{
    			$problem = TRUE;
    			print'<p class="error">Please provide a password.</p>';
    		} 
    
    		if($_POST['password1'] != $_POST['password2'])
    		{
    			$problem = TRUE;
    			print'<p class="error">Your passwords do not match.</p>';
    		}
    
    		if(!$problem)
    		{
    			print'<p>Registration is good.</p>';
    			$_POST = array();
    		} else {
    			print'<p class="error">Something went wrong</p>';
    		}
    	}
    
    
    

×
×
  • Create New...