Spraban9 Posted March 21, 2013 Share Posted March 21, 2013 hi friends this coding is field name are ok but if i press save button i get error like this"Database query failed: MySQL server has gone away" <?php // May 25, 2010 include("include/connection.php"); if (isset($_FILES['file']) && $_FILES['file']['size'] > 0) { // Temporary file name stored on the server $name1 = $_POST['name1']; $type = $_POST['type']; $model = $_POST['model']; $processor = $_POST['processor']; $memory = $_POST['memory']; $hd_size = $_POST['hd_size']; $vga = $_POST['vga']; $monitor_type = $_POST['monitor_type']; $monitor_size = $_POST['monitor_size']; $os = $_POST['os']; $price = $_POST['price']; $title = $_POST['title']; $city = $_POST['city']; $address = $_POST['address']; $description = $_POST['description']; $contact = $_POST['contact']; $postdate = date("F j, Y"); $tmpName = $_FILES['file']['tmp_name']; // Read the file $fp = fopen($tmpName, 'r'); $data = fread($fp, filesize($tmpName)); $data = addslashes($data); fclose($fp); $result = mysql_query("INSERT INTO computersale (name ,type ,model , processor ,memory ,hd_size ,vga ,monitor_type ,monitor_size ,os ,price ,title ,city ,address ,description ,contact ,postdate) VALUES ('$name1','$type', '$model' , '$processor', '$memory', '$hd_size', '$vga', '$monitor_type', '$monitor_size', '$os', '$price', '$title', '$city','$address' , '$description','$contact','$postdate','$data' )",$conn); if(!$result) { die("Database query failed: ". mysql_error()); } // Print results print "Thank you, your file has been uploaded."; } ?> </label> <form name="frmcompsa" method="post" enctype="multipart/form-data" action="compusaleup.php"> <div id="form"> <h2>Upload Computer Sales Ads </h2> <table width="537" height="485" id="font"; > <tr> <td width="126" height="35" id="font"><label class="style9"> Type</label></td> <td width="349"><input name="type" type="text" value="" width="250"/> </td> </tr> <tr> <td height="38" id="font"><label class="style9">Model</label></td> <td><input name="model" type="text" value="" /> <input name="name1" type="text" style="visibility:hidden" value="<?php echo $name ?>" /></td> </tr> <tr> <td height="34" id="font"><label class="style9">Processor</label></td> <td><input name="processor" type="text" value="" width="250"/></td> </tr> <tr> <td height="34" id="font"><label class="style9">Memory</label></td> <td> <input name="memory" type="text" value="" width="250"/> </td> </tr> <tr> <td height="44" id="font"><label class="style9">Hard disk</label></td> <td><input name="hd_size" type="text" value="" width="250"/></td> </tr> <tr> <td height="36" id="font"><label class="style9">Graphic Card</label></td> <td><input name="vga" type="text" value="" width="250" /> </td> </tr> <tr> <td height="38" id="font"><label class="style9">Monitor Type</label></td> <td><input name="monitor_type" type="text" value="" width="250"/></td> </tr> <tr> <td height="38" id="font"><label class="style9">Monitor Size</label></td> <td><input name="monitor_size" type="text" value="" width="250"/></td> </tr> <tr> <td height="36" id="font"><label class="style9">Operating System</label></td> <td><input name="os" type="text" value="" width="250" /></td> </tr> <tr> <td height="62"><label class="style9"> Price</label></td> <td><input name="price" type="text" value="" width="250" /></td> </tr> <tr> <td width="115" height="35"><label class="style9"> Ads title</label></td> <td width="407"><input name="title" type="text" width="250"value="" /></td> </tr> <tr> <td height="34"><label class="style9">Address</label></td> <td><textarea name="address" cols="40" rows="3"></textarea></td> </tr> <tr> <td height="36"><label class="style9">City</label></td> <td><input name="city" type="text" value="" width="250" /> <span style="font-size:13px" class="style10">SriLanka Only</span></td> </tr> <tr> <td height="62"><label class="style9">Description</label></td> <td><textarea name="description" cols="40" rows="3"></textarea></td> </tr> <tr> <td height="62"><label class="style9">Contact</label></td> <td><input name="contact" type="text" value="" width="250" /></td> </tr> <tr> <td height="38" class="style9" id="font">Upload Image</td> <td> <input type="file" name="file" id="file" /><br> </td> </tr> <tr> <td colspan="2"> <div align="center"> <input name="submit" type="submit" value="Submit"/> <input name="cancel" type="button" value="Cancel" /> </div></td> </tr> </table> </div></form> Quote Link to comment https://forums.phpfreaks.com/topic/275956-database-query-failed-mysql-server-has-gone-away/ Share on other sites More sharing options...
Solution Spraban9 Posted March 21, 2013 Author Solution Share Posted March 21, 2013 it working answer is <?php // May 25, 2010 include("include/connection.php"); if(isset($_FILES['file']) && $_FILES['file']['size'] > 0) { // Temporary file name stored on the server $name1 = $_POST['name1']; $type = $_POST['type']; $model = $_POST['model']; $processor = $_POST['processor']; $memory = $_POST['memory']; $hd_size = $_POST['hd_size']; $vga = $_POST['vga']; $monitor_type = $_POST['monitor_type']; $monitor_size = $_POST['monitor_size']; $os = $_POST['os']; $price = $_POST['price']; $title = $_POST['title']; $city = $_POST['city']; $address = $_POST['address']; $description = $_POST['description']; $contact = $_POST['contact']; $postdate = date("F j, Y"); $tmpName = $_FILES['file']['tmp_name']; // Read the file $fp = fopen($tmpName, 'r'); $data = fread($fp, filesize($tmpName)); $data = addslashes($data); fclose($fp); $result = mysql_query("INSERT INTO computersale (name ,type ,model,processor ,memory ,hd_size ,vga ,monitor_type ,monitor_size ,os ,price ,title ,city ,address ,description ,contact ,postdate,image) VALUES ('".$name1."','".$type."', '".$model."' , '".$processor."', '".$memory."', '".$hd_size."', '".$vga."', '".$monitor_type."', '".$monitor_size."', '".$os."', '".$price."', '".$title."', '".$city."','".$address."' , '".$description."','".$contact."','".$postdate."','$data' )",$conn); if($result){ $saved= " Enter the Verification code from your phone "; } else { $saved= "Cannot send Confirmation Verfication code to your contact number"; } }?> </label> Quote Link to comment https://forums.phpfreaks.com/topic/275956-database-query-failed-mysql-server-has-gone-away/#findComment-1420032 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.