/    Sign up×
Community /Pin to ProfileBookmark

mysql ERROR No idea what it is (Newbie)

//connect to database
$con = mysql_connect (“localhost”,”u258029154_teddy”,”*******”);
if (!$con)
{
die (‘could not connect: ‘ . mysql_error());
}

$db_selected = mysql_select_db(“u258029154_smste”, $con);
if (!$db_selected) {
die (‘Can’t use foo : ‘ . mysql_error());

}

$i = 0;

while ($i != 8000) {

This is part of the code where I’m getting the error on my script anything stand out?

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@teddyg1989authorNov 25.2014 — You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 is the specific error
Copy linkTweet thisAlerts:
@teddyg1989authorNov 25.2014 — <!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>SMS Script</title>

</head>

<h1>SMS Script</h1>

<?PHP

set_time_limit (0) ;

//connect to database

$con = mysql_connect ("localhost","u258029154_teddy","*******");

if (!$con)

{

die ('could not connect: ' . mysql_error());

}


$db_selected = mysql_select_db("u258029154_smste", $con);
if (!$db_selected) {
die ('Can't use foo : ' . mysql_error());

}

$i = 0;

while ($i != 8000) {

//get latest number to send to

$result = mysql_query("SELECT * FROM numbers WHERE status=''")

or die (mysql_error());

$row = mysql_fetch_array($result);

$id = $row['id'];

$number = $row['number'];

if ($number > 4194949999) {

echo "ALL DONE";

mysql_close($con);

exit;

}

echo $number." - #" .$i;

//cycle through all 5 providers

ob_flush();

flush ();

usleep (2000000);

////1

mail($number."@messaging.com","Anonymous", "","", "-[email protected]/r/n");

echo " ...sprint ";

ob_flush();

flush();

$res = mysql_query("UPDATE number SET status='sent' Where id=$id") or die (mysql_error());

$numberupdate = $number + 1;

mysql_query("INSERT INTO numbers

(number) Values ('$numberupdate' ) ")

or die (mysql_error());

echo "...sent! <br />";

$i++;

}

echo "<BR />...ALL DONE! <br />";

mysql_close($con) ;

exit;
Copy linkTweet thisAlerts:
@NogDogNov 25.2014 — It would help if you told us which line in the script was throwing the error (which should be part of the actual PHP error output, right after the file name).

I'm going to guess (and it's just a guess right now) that MySQL has a reserved word "number", and that you need to quote your column name with "back-tick" quotes -- or maybe you meant to use table name numbers but left the "s" off in one of the update queries? (Note that it never hurts to quote any column/table name with back-ticks, so you might want to do it anyway just in case.)
Copy linkTweet thisAlerts:
@teddyg1989authorNov 25.2014 — It would help if you told us which line in the script was throwing the error (which should be part of the actual PHP error output, right after the file name).

I'm going to guess (and it's just a guess right now) that MySQL has a reserved word "number", and that you need to quote your column name with "back-tick" quotes -- or maybe you meant to use table name numbers but left the "s" off in one of the update queries? (Note that it never hurts to quote any column/table name with back-ticks, so you might want to do it anyway just in case.)[/QUOTE]


"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.or' at line 1"

And even when I tweeked and removed the error just moves to the next line of code. So no matter what I've done it says at line 1

Thank you for reaching out by the way.
Copy linkTweet thisAlerts:
@NogDogNov 25.2014 — That's the output from mysql_error(), but the die() command itself should have spewed something out that says something about a fatal error, and that lists the *.php file where it failed, with the line number right after the file name. That way we can narrow it down to which query failed. Also, a useful pattern is to output the query with the mysql_error() output, something like:

[code=php]
$sql = "SELECT * FROM some_table WHERE foo=1";
$result = mysql_query($sql);
if($result == false) {
die(mysql_error.PHP_EOL.$sql);
}
[/code]

(Hopefully doing something "nicer" than that in the live version so you don't spew DB info onto the live site. ? )

PS: the PHP MySQL extension (all those mysql_*() functions) is deprecated, and you really should be using the MySQL[b]i[/b] extension or the PDO extension, instead; but that's a whole other issue you probably don't want to deal with right now. ?
×

Success!

Help @teddyg1989 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 4.30,
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,
)...