/    Sign up×
Community /Pin to ProfileBookmark

Missing something simple with this insert statement??

I have been at this thing for a few hours now and ready to blow up in frustration!! I have debuged this code line by line; I can connect to mysql, I can connect to the database, I can successfully get the file, and I can echo each data value within the loop. but when i try to run the whole script I get a blank web page and no information is being but into the table; I don’t even get a mysql error message.

<?
//open connection
$con = mysql_connect(“localhost”, “admin”, “111111”);
if (!$con) {
echo “Mysql could not connect”;
} else { echo “Working Connection<br />”; }
//select database
$db = mysql_select_db(“realtynet”);
if (!$db) {
echo “Database could not be established”;
} else { echo “Sees the Database<br />”; }
// Get a file into an array
$lines = file(‘WordPro_PROP_1_ACRProp_full_dat_20081208_130000.txt’);
if (!$lines) {
echo “could not get the file”;
} else { echo “File gotten successful”; }
// Loop through the $lines array to get each line
foreach ($lines as $line_num => $line) {
//explode, trim, addslashes to the $line
$trim = trim($line);
$addslashes = addslashes($trim);
$data = explode(‘|’,$addslashes);
// compose the sql string
$sql = mysql_query(‘INSERT INTO WordPro_PROP_1_ACRProp_full_dat SET 1 = ‘$data[0]’, 2 = ‘$data[1]’, 3 = ‘$data[2]’, 4 = ‘$data[3]’, 5 = ‘$data[4]’, 6 = ‘$data[5]’, 7 = ‘$data[6]’, 8= ‘$data[7]’, 9 = ‘$data[8]’, 10 = ‘$data[9]’, 11 = ‘$data[10]’, 12 = ‘$data[11]’, 13 = ‘$data[12]’, 14 = ‘$data[13]’, 15 = ‘$data[14]’, 16 = ‘$data[15]’, 17 = ‘$data[16]’, 18 = ‘$data[17]’, 19 = ‘$data[18]’, 20 = ‘$data[19]’, 21 = ‘$data[20]’, 22 = ‘.$data[21]’, 23 = ‘$data[22]’, 24 = ‘$data[23]’, 25 = ‘$data[24]’, 26 = ‘$data[25]’, 27 = ‘$data[26]’, 28 = ‘$data[27]’, 29 = ‘$data[28]’, 30 = ‘$data[29]’, 31 = ‘$data[30]’, 32 = ‘$data[31]’, 33 = ‘$data[32]’, 34 = ‘$data[33]’, 35 = ‘$data[34]’, 36 = ‘$data[35]’, 37 = ‘$data[36]’, 38 = ‘$data[37]’, 39 = ‘$data[38]’, 40 = ‘$data[39]’, 41 = ‘$data[40]’, 42 = ‘$data[41]’, 43 = ‘$data[42]’, 44 = ‘$data[43]’, 45 = ‘$data[44]’, 46 = ‘$data[45]’, 47 = ‘$data[46]’, 48 = ‘$data[47]’, 49 = ‘$data[48]’, 50 = ‘$data[49]’, 51 = ‘$data[50]’, 52 = ‘$data[51]’, 53 = ‘$data[52]’, 54 = ‘$data[53]’, 55 = ‘$data[54]’, 56 = ‘$data[55]’, 57 = ‘$data[56]’, 58 = ‘$data[57]’, 59 = ‘$data[58]’, 60 = ‘$data[59]’, 61 = ‘$data[60]’, 62 = ‘$data[61]’, 63 = ‘$data[62]’, 64 = ‘$data[63]’, 65 = ‘$data[64]’, 66 = ‘$data[65]’, 67 = ‘$data[66]’, 68 = ‘$data[67]’, 69 = ‘$data[68]’, 70 = ‘$data[69]’, 71 = ‘$data[70]’, 72 = ‘$data[71]’, 73 = ‘$data[72]’, 74 = ‘$data[73]’, 75 = ‘$data[74]’, 76 = ‘$data[75]’, 77 = ‘$data[76]’, 78 = ‘$data[77]’, 79 = ‘$data[78]’, 80 = ‘$data[79]’, 81 = ‘$data[80]’, 82 = ‘$data[81]’, 83 = ‘$data[82]’, 84 = ‘$data[83]’, 85 = ‘$data[84]’, 86 = ‘$data[85]’, 87 = ‘$data[86]’, 88 = ‘$data[87]’, 89 = ‘$data[88]’, 90 = ‘$data[89]’, 91 = ‘$data[90]’, 92 = ‘$data[91]’, 93 = ‘$data[92]’, 94 = ‘$data[93]’, 95 = ‘$data[94]’, 96 = ‘$data[95]’, 97 = ‘$data[96]’, 98 = ‘$data[97]’, 99 = ‘$data[98]’, 100 = ‘$data[99]’, 101 = ‘$data[100]’, 102 = ‘$data[101]’, 103 = ‘$data[102]’, 104 = ‘$data[103]’, 105 = ‘$data[104]’, 106 = ‘$data[105]’, 107 = ‘$data[106]’, 108= ‘$data[107]’, 109 = ‘$data[108]’, 110 = ‘$data[109]’, 111 = ‘$data[110]’, 112 = ‘$data[111]’, 113 = ‘$data[112]’, 114 = ‘$data[113]’, 115 = ‘$data[114]’, 116 = ‘$data[115]’, 117 = ‘$data[116]’, 118 = ‘$data[117]’, 119 = ‘$data[118]’, 120 = ‘$data[119]’, 121 = ‘$data[120]’, 122 = ‘.$data[121]’, 123 = ‘$data[122]’, 124 = ‘$data[123]’, 125 = ‘$data[124]’, 126 = ‘$data[125]’, 127 = ‘$data[126]’, 128 = ‘$data[127]’, 129 = ‘$data[128]’, 130 = ‘$data[129]’, 131 = ‘$data[130]’, 132 = ‘$data[131]’, 133 = ‘$data[132]’, 134 = ‘$data[133]’, 135 = ‘$data[134]’, 136 = ‘$data[135]’, 137 = ‘$data[136]’, 138 = ‘$data[137]’, 139 = ‘$data[138]’, 40 = ‘$data[139]’, 141 = ‘$data[140]’, 142 = ‘$data[141]’, 143 = ‘$data[142]’, 144 = ‘$data[143]’, 145 = ‘$data[144]’, 146 = ‘$data[145]’, 147 = ‘$data[146]’, 148 = ‘$data[147]’, 149 = ‘$data[148]’, 150 = ‘$data[149]’, 151 = ‘$data[150]’, 152 = ‘$data[151]’, 153 = ‘$data[152]’, 154 = ‘$data[153]’, 155 = ‘$data[154]’, 156 = ‘$data[155]’, 157 = ‘$data[156]’, 158 = ‘$data[157]’, 159 = ‘$data[158]’, 160 = ‘$data[159]’, 161 = ‘$data[160]’, 162 = ‘$data[161]’, 163 = ‘$data[162]’, 164 = ‘$data[163]’, 165 = ‘$data[164]’, 166 = ‘$data[165]’, 167 = ‘$data[166]’, 168 = ‘$data[167]’, 169 = ‘$data[168]’, 170 = ‘$data[169]’, 171 = ‘$data[170]’, 172 = ‘$data[171]’, 173 = ‘$data[172]’, 174 = ‘$data[173]’, 175 = ‘$data[174]’, 176 = ‘$data[175]’, 177 = ‘$data[176]’, 178 = ‘$data[177]’, 179 = ‘$data[178]’, 180 = ‘$data[179]’, 181 = ‘$data[180]’, 182 = ‘$data[181]’, 183 = ‘$data[182]’, 184 = ‘$data[183]’, 185 = ‘$data[184]’, 186 = ‘$data[185]’, 187 = ‘$data[186]”) or die(‘ERROR :’.mysql_error());

//execute your sql
//if (!$sql) {
//echo ‘ERROR : ‘.mysql_errno() .’>’. mysql_error().”;
//} else { echo “Query Successfull!<br />”; }
//close the connection
$close = mysql_close($con);
}
?>

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@aj_nscDec 09.2008 — Perhaps it's a parsing error in your php code then and perhaps you have error reporting turned off on your local server.

No offense, but that's one hell of an ugly looking query. I believe the problem lies in the fact that php variables can only be parsed out of a string, if the string itself is in double quotes. Ref: http://theserverpages.com/php/manual/en/language.types.string.php#language.types.string.syntax.double

So, just for fun, why don't you try putting a " at the beginning and end of your query instead of a '

Hope it works, good luck!


EDIT: Wait, hahaha! I just caught this out of the corner of my eye:

[code=php]
22 = '.$data[21]',
[/code]


Looks like you made an attempt to concatenate this variable into the string, but never followed through on it, get rid of the .
Copy linkTweet thisAlerts:
@MindzaiDec 09.2008 — You also have about a thousand single quotes inside your single quoted string ?

It's always wise to develop with error_reporting set to E_ALL.

Also if you REALLY need to use that exact query you could generate it in a for loop pretty easily and be sure of consistency.
×

Success!

Help @jblackwelder spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...