Click here to Skip to main content
15,311,561 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
PHP
";print_r($_REQUEST);exit;
	$sliderName		= $_REQUEST['sliderName'];
	//echo "<pre>";print_r($_REQUEST);
	$sliderDesc		= $_REQUEST['sliderDesc'];
	//echo "<pre>";print_r($_REQUEST);
	$sliderPhoto	= $_FILES['sliderPhoto']['name'];
		$path		= 'images/'.$sliderPhoto;
		move_uploaded_file($_FILES['sliderPhoto']['tmp_name'], $path);
	//echo "<pre>";print_r($_REQUEST);
	$date			= date('Y-m-d h:i:s');
	//echo $date;	
		
	$insert = "INSERT INTO tbl_slider(fld_sliderName, fld_slider_Description, fld_added_Date) VALUES('$sliderName', '$sliderDesc', '$date')";
	mysql_query($insert);
		//echo $insert;
		
}
?>

<div id="page-wrapper">

        <div class="row">
          <div class="col-lg-12">
            <h3>Add Slider</h3>
            
          </div>
        </div><!-- /.row -->

        <div class="row">
          <div class="col-lg-6">
		   
            <div class="alert alert-dismissable alert-danger" id="emsdiv" style="display:none;">
              <button type="button" class="close" data-dismiss="alert">×</button>
              Oh snap! <span id="emspan"></span>
            </div>
          
            <div class="alert alert-dismissable alert-success" id="smsdiv" style="display:none;">
              <button type="button" class="close" data-dismiss="alert">×</button>
              Well done!<span id="emspan"></span>
            </div>
         
            <form name="frm" method="post" action="" onSubmit="return validate();" enctype="multipart/form-data">
			<input type="hidden" name="add" value="image">
              
			  <div style="clear:both;"></div>
			  
			  <div class="form-group">
                <label style=" float:left; width:200px;padding-top:4px;">Product Name:</label>
                <input type="text" name="sliderName" id="sliderName" value="" style="width:248px;"/>
              </div>
			  
			  <div class="form-group">
                <label style=" float:left; width:200px;padding-top:4px;">Product description:</label>
				<textarea rows="3" cols="34" name="sliderDesc" id="sliderDesc" ></textarea>
              </div>
			  
			  <div class="form-group">
                <label style=" float:left; width:200px;padding-top:4px;">Product Photo:</label>
                <input type="file" name="sliderPhoto" id="sliderPhoto" value="" />
             </div>
			  			  
			  <div style="clear:both; height:15px;"></div>
              
        	<div class="form-group">
    	        <label style=" float:left; width:200px; padding-top:4px;"></label>
			  	<input type="submit" class="btn btn-default" name="submit" value="Save"/>  
           		<a href="list-gallery.php"><input type="button" class="btn btn-default" value="Cancel"/></a>
			</div> 
            
			  <div style="clear:both;"></div>  
            </form>
			
          </div>
          
        </div><!-- /.row -->

      </div>


What I have tried:

data inserted but not showing in mysql database. please have a solution
Posted
Updated 6-Jul-20 9:16am
v2
Comments
DerekT-P 6-Jul-20 5:43am
   
Your statements are mutually exclusive: "data inserted" and "not showing in database". Those can't both be true. So examine each one in turn: was the insert really successful? How do you know? Then: Why do I think the data isn't in the d/b now?

Is the insert part of a transaction? One cause of the behaviour you describe is that the insert is "successful" but the transaction is then rolled back, so the new data isn't in the d/b. Depending on your settings you may have transactions turned on by default and if you don't commit, your insert gets un-inserted when the transaction times out. Try hard-coding the insert statement and running again to check whether it's that, or some data-related or other issue. Are you certain you're looking at the right database? (If you have multiple databases it's easy enough to get connection strings muddled up so you're inserting into one database then checking another!). Is your query of the database correct for checking the insertion? Are you selecting all data, or just using a d/b tool to view the data; these often limit results to the first 200 or 500 rows, so maybe your data is there but not returned in the default "data table" view. Is there an auto-increment field defined on the table; if so, are there gaps in the numbering? (This may also point to a transaction having been rolled back). Finally, you're doing the INSERT all wrong - this is wide open to SQL Injection attacks. Never just "inline" data to be inserted or updated, especially if that data has come in via a web request. Your code above will break if the data ever contains a single quote. (Break, if you're lucky - or allow someone to gain full access to all your data, if not!)
Richard Deeming 6-Jul-20 6:58am
   
Your code is vulnerable to SQL Injection[^]. NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.

PHP: SQL Injection - Manual[^]
CHill60 6-Jul-20 9:18am
   
If it's "not showing" in the database then it wasn't inserted! What makes you think it was successful?
Richard MacCutchan 6-Jul-20 9:29am
   
It is possible that your INSERT statement failed to do what you wanted. Unfortunately you did not bother to check whether it succeeded or not so you will never know.
ZurdoDev 6-Jul-20 10:45am
   
Either you are getting an error, the code is not running, you are pointing to the wrong database, or it actually is going into the database. You'll need to do some digging.
Herman<T>.Instance 6-Jul-20 13:53pm
   
No errortracking, you're asking for it

1 solution

Your update (v2, 5hrs 20min before this comment) seems to have added a partial line before the code that inserts the record:
";print_r($_REQUEST);exit;
This snippet has no closing curly bracket so under whatever circumstances that bit of code gets executed, the code will do as you instruct and EXIT the code without attempting the database insertion. There will be no error message as no error has been encountered. The data's not being inserted in the database because the code isn't being run.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900