homer.favenir Posted May 6, 2008 Share Posted May 6, 2008 hi, please kindly check my query it has an error when executed <?php $sql="INSERT INTO tbl_exceed (address, city, phone) VALUES ('$_POST['$data[2]']', '$_POST['$data[3]']','$_POST['$data[4]']')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } mysql_close($con) ?> thanks Link to comment https://forums.phpfreaks.com/topic/104297-solved-simple-insert-in-table/ Share on other sites More sharing options...
dezkit Posted May 6, 2008 Share Posted May 6, 2008 <?php $sql="INSERT INTO tbl_exceed (address, city, phone) VALUES ('$_POST[\"$data[2]\"]','$_POST[\"$data[3]\"]','$_POST[\"$data[4]\"]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } mysql_close($con) ?> Link to comment https://forums.phpfreaks.com/topic/104297-solved-simple-insert-in-table/#findComment-534018 Share on other sites More sharing options...
homer.favenir Posted May 6, 2008 Author Share Posted May 6, 2008 error Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\xampp\htdocs\exceed\upload.php on line 26 Link to comment https://forums.phpfreaks.com/topic/104297-solved-simple-insert-in-table/#findComment-534021 Share on other sites More sharing options...
dezkit Posted May 6, 2008 Share Posted May 6, 2008 post the first 26 lines of your upload.php Link to comment https://forums.phpfreaks.com/topic/104297-solved-simple-insert-in-table/#findComment-534026 Share on other sites More sharing options...
homer.favenir Posted May 6, 2008 Author Share Posted May 6, 2008 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php // Connecting, selecting database $con = mysql_connect('asecasiasdi', 'root', 'itsysdev') or die('Could not connect: ' . mysql_error()); echo '<b>Step 1:</b> Connected successfully! <BR>'; $db = 'aai_dbexceed'; mysql_select_db($db) or die('Could not select database ('.$db.') because of : '.mysql_error()); echo '<b>Step 2:</b> Connected to ('.$db.') successful!<BR>'; ?> <?php $sql="INSERT INTO tbl_exceed (address, city, phone) VALUES ('$_post[\"$data[2]\"]', '$_post[\"$data[3]\"]', '$_post[\"$data[4]\"]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } mysql_close($con) ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/104297-solved-simple-insert-in-table/#findComment-534028 Share on other sites More sharing options...
947740 Posted May 6, 2008 Share Posted May 6, 2008 <?php // Connecting, selecting database $con = mysql_connect('asecasiasdi', 'root', 'itsysdev') or die('Could not connect: ' . mysql_error()); echo '<b>Step 1:</b> Connected successfully! <BR>'; $db = 'aai_dbexceed'; mysql_select_db($db) or die('Could not select database ('.$db.') because of : '.mysql_error()); echo '<b>Step 2:</b> Connected to ('.$db.') successful!<BR>'; ?> <?php $sql="INSERT INTO tbl_exceed (address, city, phone) VALUES ('$_post[\"$data[2]\"]', '$_post[\"$data[3]\"]', '$_post[\"$data[4]\"]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } mysql_close($con); ?> It was the last line in the code. Link to comment https://forums.phpfreaks.com/topic/104297-solved-simple-insert-in-table/#findComment-534033 Share on other sites More sharing options...
homer.favenir Posted May 6, 2008 Author Share Posted May 6, 2008 what line? i copy your script but it is still an error thanks Link to comment https://forums.phpfreaks.com/topic/104297-solved-simple-insert-in-table/#findComment-534035 Share on other sites More sharing options...
947740 Posted May 6, 2008 Share Posted May 6, 2008 I thought it was mysql_close($con). Link to comment https://forums.phpfreaks.com/topic/104297-solved-simple-insert-in-table/#findComment-534038 Share on other sites More sharing options...
homer.favenir Posted May 6, 2008 Author Share Posted May 6, 2008 can anyone knows what is the error in my script? <?php $sql="INSERT INTO tbl_exceed (address, city, phone) VALUES ('$_post[\"$data[2]\"]', '$_post[\"$data[3]\"]', '$_post[\"$data[4]\"]')"; if (!mysql_query($sql,$con)) mysql_close($con); ?> error message: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\xampp\htdocs\exceed\upload.php on line 26 Link to comment https://forums.phpfreaks.com/topic/104297-solved-simple-insert-in-table/#findComment-534337 Share on other sites More sharing options...
947740 Posted May 6, 2008 Share Posted May 6, 2008 <?php $sql="INSERT INTO tbl_exceed (address, city, phone) VALUES ('$_post[\"$data[2]\"]', '$_post[\"$data[3]\"]', '$_post[\"$data[4]\"]')"; if (!mysql_query($sql,$con)) { mysql_close($con); } ?> Link to comment https://forums.phpfreaks.com/topic/104297-solved-simple-insert-in-table/#findComment-534339 Share on other sites More sharing options...
saint959 Posted May 6, 2008 Share Posted May 6, 2008 <?php $sql="INSERT INTO tbl_exceed (address, city, phone) VALUES ('".$_post['$data[2]']."', '".$_post['$data[3]']".', '".$_post['$data[4]']".')"; if (!mysql_query($sql,$con)) { mysql_close($con); } ?> you could try that too. i did not test at all so there might be small errors but i think it should work Link to comment https://forums.phpfreaks.com/topic/104297-solved-simple-insert-in-table/#findComment-534344 Share on other sites More sharing options...
homer.favenir Posted May 6, 2008 Author Share Posted May 6, 2008 another same errror... :'( Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in C:\xampp\htdocs\exceed\upload.php on line 26 line 26 is ('".$_post['$data[2]']."', '".$_post['$data[3]']".', '".$_post['$data[4]']".')"; :'( Link to comment https://forums.phpfreaks.com/topic/104297-solved-simple-insert-in-table/#findComment-534347 Share on other sites More sharing options...
saint959 Posted May 6, 2008 Share Posted May 6, 2008 the last string concact is wrong. sorry ('".$_post['$data[2]']."', '".$_post['$data[3]']."', '".$_post['$data[4]']."')"; Link to comment https://forums.phpfreaks.com/topic/104297-solved-simple-insert-in-table/#findComment-534350 Share on other sites More sharing options...
homer.favenir Posted May 6, 2008 Author Share Posted May 6, 2008 it executed but no data were added. ??? this is the source of the $data[], how to insert the $data[2], $data[3], $data[4]? from this script to database above? <?php $text = $_REQUEST['fname']; $file = file("$text"); $a = $file; $state = $_REQUEST['state']; $newfile = $_REQUEST['txtfile']; $count = 0; foreach ($a as $row => $line) { //$data[0] = trim(substr($line, 0, 16))."<br />"; //$data[1] = trim(substr($line, 16,125))."<br />"; $data[2] = trim(substr($line,141, 55))."<br />"; $data[3] = trim(substr($line,196, 32))."<br />"; $data[4] = trim(substr($line,228, 14))."<br />"; //$data[5] = trim(substr($line,240, 2))."<br />"; if ($data[2]!= "<br />" or $data[3] != "<br />" or $data[4] != "<br />") $final[] = $data; $count++; } echo "There are " . $count . ": Records Found"; ?> <table width="100%" border="1"> <th bgcolor="#CCCCCC">ADDRESS</th><th bgcolor="#CCCCCC">CITY</th><th bgcolor="#CCCCCC">STATE</th><th bgcolor="#CCCCCC">PHONE</th><th bgcolor="#CCCCCC">ZIP CODE</th> <tr> <?php for($i = 0;$i <=$count; $i++) { $data = $final[$i];?> <td><?php echo $data[2];?></td> <td><?php echo $data[3];?></td> <td><?php echo $state;?></td> <td><?php echo $data[4];?></td> </tr> <?php } ?> please.... Link to comment https://forums.phpfreaks.com/topic/104297-solved-simple-insert-in-table/#findComment-534356 Share on other sites More sharing options...
saint959 Posted May 6, 2008 Share Posted May 6, 2008 hi, is this your entire script? you will need a form to post the data to the 'insert' script. what is it that you are trying to do? how does your database query get "executed"? Link to comment https://forums.phpfreaks.com/topic/104297-solved-simple-insert-in-table/#findComment-534357 Share on other sites More sharing options...
homer.favenir Posted May 6, 2008 Author Share Posted May 6, 2008 yes i have a form <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>UDAC</title> </head> <body> <form action="index.php" method="post" enctype="multipart/form-data"> <table border="0"> <tr><td><b>Filename:</b></td><td><input name="fname" type="text" /></td> <br /> <tr><td><b>State:</b> </td><td><input name="state" type="text" /></td> <tr><td colspan="2"><input name="submit" type="submit" value="load" /></td> </table> </form> </form> <form action="upload.php" method="GET" enctype="multipart/form-data"> <input name="submit" type="submit" value="save database" /> </form> <?php $text = $_REQUEST['fname']; $file = file("$text"); $a = $file; $state = $_REQUEST['state']; $newfile = $_REQUEST['txtfile']; $count = 0; foreach ($a as $row => $line) { //$data[0] = trim(substr($line, 0, 16))."<br />"; //$data[1] = trim(substr($line, 16,125))."<br />"; $data[2] = trim(substr($line,141, 55))."<br />"; $data[3] = trim(substr($line,196, 32))."<br />"; $data[4] = trim(substr($line,228, 14))."<br />"; //$data[5] = trim(substr($line,240, 2))."<br />"; if ($data[2]!= "<br />" or $data[3] != "<br />" or $data[4] != "<br />") $final[] = $data; $count++; } echo "There are " . $count . ": Records Found"; ?> <table width="100%" border="1"> <th bgcolor="#CCCCCC">ADDRESS</th><th bgcolor="#CCCCCC">CITY</th><th bgcolor="#CCCCCC">STATE</th><th bgcolor="#CCCCCC">PHONE</th><th bgcolor="#CCCCCC">ZIP CODE</th> <tr> <?php for($i = 0;$i <=$count; $i++) { $data = $final[$i];?> <td><?php echo $data[2];?></td> <td><?php echo $data[3];?></td> <td><?php echo $state;?></td> <td><?php echo $data[4];?></td> </tr> <?php } ?> </table> </body> </html> what im trying to do is i need to insert the data from here to the database. and the script that will insert the data to db is script above from previous post. Link to comment https://forums.phpfreaks.com/topic/104297-solved-simple-insert-in-table/#findComment-534370 Share on other sites More sharing options...
saint959 Posted May 6, 2008 Share Posted May 6, 2008 hi, sorry, i am afraid i am leaving the office now and will ony be back tomorrow. i hope i have helped a little and i hope you come right! Good luck Link to comment https://forums.phpfreaks.com/topic/104297-solved-simple-insert-in-table/#findComment-534374 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.