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 Quote Link to comment 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) ?> Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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> Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
947740 Posted May 6, 2008 Share Posted May 6, 2008 I thought it was mysql_close($con). Quote Link to comment 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 Quote Link to comment 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); } ?> Quote Link to comment 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 Quote Link to comment 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]']".')"; :'( Quote Link to comment 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]']."')"; Quote Link to comment 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.... Quote Link to comment 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"? Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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.