/    Sign up×
Community /Pin to ProfileBookmark

PHP Stops Without Any Hint

Hello every one,

I have a code stop without any error or info:
A php code inserts records to a MyQL table successfully. The insert is very simple: three integers of a table. Below is the code:

[CODE]
$inssql = “INSERT INTO pppv(addrs, addre, LcID) VALUES({$ads}, {$ade},{$LcID})”;
echo “i={$i} ” . $inssql . “<br>”;
$result = mysqli_query($con,$inssql);
if (!$result) {
trigger_error(“Error: f-city.php query cities – {$inssql} – ” . mysqli_error($con) . “<br>”, E_USER_ERROR);
}
echo “i={$i} result={$result} ” . $inssql . “<br>”;
[/CODE]

Below is the last two results from one run:

[CODE]
i=2766 INSERT INTO pppv(addrs, addre, LcID) VALUES(36874, 368999,5 )
i=2766 result=1 INSERT INTO pppv(addrs, addre, LcID) VALUES(363744, 368639,5 )
i=2766 “36863744”,”36863999″,”5″
i=2767 INSERT INTO pppv(addrs, addre, LcID) VALUES(368640, 365023,554 )
[/CODE]

For a normal run, there are three output lines, two lines are produced by the above code, another after these two line. From the above output, 2766th record is a success one. But for 2767th, even it’s inserted into table successfully (it’s in the table, I checked), and no error log in the log, ii stopped before the 2nd echo. This keeps for every one, this run processed 2768 records, another for 3040 records, …. What is the problem for code to stop?

Thanks,

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@deathshadowOct 06.2014 — 1) check your server logs... not all fatal's have output.

2) turn on verbose/complete error reporting.
error_reporting(E_ALL);

3) STOP wasting code on double quotes and string additions on cases where they are slower and/or inappropriate.

4) for example, you're using mysqli, [b]USE IT[/b] -- one of the entire reasons to use mysqli or PDO instead of mysql_ is to not be blindly dumping variables into query strings directly. (lemme guess, still using the _real_escape_string nonsense?!?)

Also a lot of what you are doing would only need to be done ONCE if you were using prepared queries like a good little doobie instead of the outdated, outmoded, insecure and bandwidth (yes I said bandwidth) wasting practice of blindly dumping values into your query string. (particularly with the needlessly convoluted string method you're using of double quotes with brackets)

$statement = $con-&gt;prepare('
INSERT INTO pppv (
addrs, addre, LcID
) VALUES (
?, ?, ?
)
');

$statement-&gt;bind_param('sss', $ads, $ade, $LcID);

// start looping values here if doing this more than once with different values

echo $i, ' ', $ads, ' ', $ade, ' ', $LcID, ' - ';

if ($statement-&gt;execute()) {
echo 'Added Successfully&lt;br /&gt;';
} else {
echo 'Failed: ', $con-&gt;error(), '&lt;br /&gt;';
}

// end of loop for multiple values

$stmt-&gt;close();


Should be what you are doing if you're going to use mysqli -- otherwise you might as well go back to 2006 and use the mysql_ functions.

Prepare/exec is nice since the query is sent separate from the data, allowing you to perform multiple identical queries while only sending the data to the SQL engine... and since it's separate from the query it's auto-sanitized for free.
×

Success!

Help @wow 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

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