Jump to content

mysqli fetch assoc warning


Go to solution Solved by ginerjm,

Recommended Posts

I realized when posting a new file to the database and it's it's folder that I needed to have a corresponding name ($name) which is entered into the form by the user.  After the initial form is run, I set up a query that should grab the $name variable listed on line 154 now that it exists.  That query starts on line 194.    After that query is run, I assigned a local variable to the appropriate row so I can utilize it with the script that uploads the chosen files to a different table created just for uploaded files.  I need this value inserted with the file so I can associate it with the RFI that the user will have created once he or she submits the form.  

 

When I submit form, the information that the user entered is successfully placed into the proper tables. The problem starts at line one 198 with two warnings.

 

Any ideas?

 

Thanks

CB

 

Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in B:\Programs\wamp\www\hsa\new_rfi.php on line 198

 

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in B:\Programs\wamp\www\hsa\new_rfi.php on line 205

 

Notice: Undefined variable: rfiNo in B:\Programs\wamp\www\hsa\new_rfi.php on line 215

<?php

	$conn = mysqli_connect("localhost","root","","hsa_project_hub");

	session_start(); 

	if(!$_SESSION['user_loginName']){
	header("location: index.php");
	}
	else {
		
?>
<link href='http://fonts.googleapis.com/css?family=Josefin+Sans' rel='stylesheet' type='text/css'>
<style>
	form label {
	float: left;
	width: 150px;
	margin-bottom: 5px;
	margin-top: 5px;
	padding: 5px;
}
.clear {
	display: block;
	clear: both;
	width: 100%;
}

#rfi_container {
	background: #F0F0F0;
	font-family: 'Josefin Sans', sans-serif;
	font-weight: bold;
	color: #8F0000;
}

#files {
	background: yellow;
	display:block;
}
</style>


<?php //Grab Session Variable
 $project_id = $_SESSION['project_id'];
 ?>
		


<!DOCTYPE HTML>

<html>

	<head>
		<title>New RFI</title>

	<link href="hsastyle.css" rel="stylesheet">

	</head>
		<body>
			<div id="main_container">
				<p><em>version 1.0 beta</em></p>
		
				<div id="banner">
			
					<div id="logo">
						<img src="images/hsa-logo.jpg" alt=HSA logo>
						
					</div>					
						<div id="logout"><H5><a href="logout.php">Log Out</a></H5></div>
						<div id="welcome"><h6>Welcome  <?php echo $_SESSION['firstName'];?></h6></div>
						<div id="project_name">		
						<strong><em><?php echo $_SESSION['projName']?></em></strong>
					</div>
					
										
				</div> <!--End Banner-->
				
				
			
				
			
				<div id="user_list">
					<FORM>
						<INPUT Type="BUTTON" Value="Back to RFI List" Onclick="window.location.href='rfi_list.php'">
					</FORM>
				</div>
	<div id="rfi_container">
				
		<!--Create RFI for user input-->
		
			<form id="form1" name="form1" method="post" action="new_rfi.php" enctype="multipart/form-data"><br>
				<br class="clear" />
				<label for="name">RFI NO.</label><input type="text" name="name" id="name" placeholder="Ex: 003" required="required" />
				<br class="clear" /> 
				<label for="subject">Subject</label><input type="text" name="subject" id="subject" placeholder="Ex: Discontinued floor finish" />
				<br class="clear" /> 
				<label for="date_submit">Date submitted:</label><input type="date" name="date_submit" id="date_submit" />
				<br class="clear" /> 
				<label for="needed_by">Date Needed by:</label><input type="date" name="needed_by" id="needed_by" />
				<br class="clear" /> 
				<label for="question">Question:</label><textarea name="question" id="question" required="required" cols="100" rows="5"></textarea>
				<br class="clear" />
				<label for="gc_rsp">Contractor Suggestion:</label><textarea name="gc_rsp" id="gc_rsp" cols="100" rows="5"></textarea>
				<br class="clear" /> 
				<label for="owner_rsp">Owner Response:</label><textarea name="owner_rsp" id="owner_rsp" cols="100" rows="5"></textarea>
				<br class="clear" /> 
				<label for="engr_rsp">Engineer Response:</label><textarea name="engr_rsp" id="engr_rsp" cols="100" rows="5"></textarea>
				<br class="clear" /> 
				<label for="arch_rsp">Architect Response:</label><textarea name="arch_rsp" id="arch_rsp" cols="100" rows="5"></textarea><br>			
				<br class="clear" />
				<label for="final_by">Final Response by:</label><select name="final_by" id="final_by">
					<option></option>
					<option value="Architect">Architect</option>
					<option value="Owner">Owner</option>
					<option value="Structural Engineer">Structural Engineer</option>
					<option value="MEP Engineer">MEP Engineer</option>
					<option value="Civil Engineer">Civil Engineer</option>
					<option value="Landscape Architect">Landscape Architect</option>
				</select>
				<br class="clear" /> 
				<label for="date_returned">Date Returned:</label><input type="date" name="date_returned" id="date_returned" /><br>
				<br class="clear" />
				<label for="status">Status:</label><select name="status" id="status">
					<option></option>
					<option value="CLOSED">CLOSED</option>
					<option value="at Architect">at Architect</option>
					<option value="at MEP Engineer">at MEP Engineer</option>
					<option value="at Structural Engineer">at Structural Engineer</option>
					<option value="at Civil Engineer">at Civil Engineer</option>
					<option value="at Landscape Architect">at Landscape Architect</option>
					<option value="at Owner">at Owner</option>
					<option value="at General Contractor">at General Contractor</option>
				</select>
				<br class="clear" /><br> 
				<input type="file" name="files[]" multiple="" />
				<br class="clear" /><br> 
				<center><input type="submit" name="submit_data" id="submit_data" value="Submit RFI" /></center>
				
			</form>
			
			<br>
			

			
	<?php
	
		
		
		

	//Enter info in database
		if(isset($_POST['submit_data'])){	
	
	//Getting the form information and saving in local variables 
		$name 			= mysqli_real_escape_string($conn,$_POST['name']);  
		$subject 		= mysqli_real_escape_string($conn,$_POST['subject']);  
		$date_submit 	= mysqli_real_escape_string($conn,$_POST['date_submit']);
		$needed_by 		= mysqli_real_escape_string($conn,$_POST['needed_by']); 
		$question		= mysqli_real_escape_string($conn,$_POST['question']);  
		$gc_rsp 		= mysqli_real_escape_string($conn,$_POST['gc_rsp']);  
		$owner_rsp 		= mysqli_real_escape_string($conn,$_POST['owner_rsp']);  
		$engr_rsp 		= mysqli_real_escape_string($conn,$_POST['engr_rsp']);  
		$arch_rsp 		= mysqli_real_escape_string($conn,$_POST['arch_rsp']);		 
		$final_by 		= mysqli_real_escape_string($conn,$_POST['final_by']);  
		$date_returned 	= mysqli_real_escape_string($conn,$_POST['date_returned']);  
		$status 		= mysqli_real_escape_string($conn,$_POST['status']); 

		
		// Creating local variable for query from Session variable
		$first_name = $_SESSION['firstName'];
		
		$sql = " INSERT INTO rfis ( id, name, subject, issued_by, date_submit, needed_by, question, gc_rsp, owner_rsp, engr_rsp, 
			arch_rsp, final_by, date_returned, status )  VALUES ( '$project_id', '$name', '$subject', '$first_name', '$date_submit', '$needed_by', '$question',
			'$gc_rsp', '$owner_rsp', '$engr_rsp', '$arch_rsp', '$final_by', '$date_returned', '$status' ) ";
			
		
			
		if (mysqli_query($conn, $sql)) {
			echo "Success with first query";
			//echo "<script>alert('RFI added successfully')</script>";
			//echo "<script>window.open('rfi_list.php','_self')</script>";
			//} else {
			//echo "Error: " . $sql . "<br>" . mysqli_error($conn);
		}
		
		
		}
	
		
		
?>
   
<?php	
	
	$sql = "select rfis.id,rfis.name\n"
    . "from rfis\n"
    . "where rfis.$project_id";
	$result=mysqli_query($conn,$sql);
	$row=mysqli_fetch_assoc($result);
	$i=0;
	
	

	$run = mysqli_query($conn, $sql);
	//assign values to local variables
	while($row=mysqli_fetch_array($run)){
	$rfiNo		=$row["name"];
	$i++;
	}
?>

<?php


	echo $project_id; //test echo
	echo $rfiNo;	//test echo
		
		//Choose files to be uploaded
		if(isset($_FILES['submit_data'])){
			$errors= array();
			foreach($_FILES['files']['tmp_name'] as $key => $tmp_name ){
				$rfi_fileName 	= $key.$_FILES['files']['name'][$key];
				$rfi_fileSize 	=$_FILES['files']['size'][$key];
				$file_tmp 		=$_FILES['files']['tmp_name'][$key];
				$rfi_fileType	=$_FILES['files']['type'][$key];	
				if($rfi_fileSize > 8097152){
					$errors[]='File size must be less than 8 MB';
				}		
				$query="INSERT into rfi_files (`rfi_id`,`rfi_project_id`,`rfi_fileName`,`rfi_fileSize`,`rfi_fileType`) VALUES('$rfiNo','$project_id','$rfi_fileName','$rfi_fileSize','$rfi_fileType'); ";
				$desired_dir="rfi_files";
				if(empty($errors)==true){
					if(is_dir($desired_dir)==false){
						mkdir("$desired_dir", 0700);		// Create directory if it does not exist
					}
					if(is_dir("$desired_dir/".$rfi_fileName)==false){
						move_uploaded_file($file_tmp,"rfi_files/".$rfi_fileName);
					}else{									//rename the file if another one exists
						$new_dir="rfi_files/".$rfi_fileName.time();
						 rename($file_tmp,$new_dir) ;				
					}
					mysqli_query($conn,$query);			
				}else{
						print_r($errors);
				}
			}
			if(empty($error)){
				echo "Success";
			}
		}
	
			
	
	
		?>
			
		
			
		
			
		
						
			<!--<div id="files"><a href="rfi_files<?php// echo $rfiFilename;?>"><?php //echo $rfiFilename;?></a></div>	USE LATER TO SHOW LINK FOR DOWNLOAD-->
			
		<?php } ?>
		
		<div><!--end of container-->
		
		
		
		</body>
		
		
</html>
Link to comment
https://forums.phpfreaks.com/topic/297469-mysqli-fetch-assoc-warning/
Share on other sites

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.