/    Sign up×
Community /Pin to ProfileBookmark

MySQL: Query Was Empty

Anything wrong with my code, I keep getting “Query Was Empty”?

[code=php]
<?php

//DATABASE CONNECTION
include ‘includes/mysql/connection.php’;

//SELECT DATABAE
$dbname = uw_wipgfhprogram;

//CONNECT TO MYSQL DATABASE
$dbconn = mysql_connect ( $dbhost, $dbuser, $dbpass );

//CHECK IF CONNECTED
if (! $dbconn ) { die( ‘Could Not Connect: ‘ . mysql_error()); }

//SELECT DATABASE
mysql_select_db( $dbname, $dbconn );

//EXMAMPLE USER
$cn = ‘Christopher We.’;

//SELECT QUERY
$info = mysql_query( “SELECT * FROM `master_list` WHERE `cn` = ‘$cn'”, $dbconn );

//TIME/DATE
$g1_dt_signup = date( “Y-m-d H-i-s” );
$g1_dt_signup_output = date( “m/d/y” );

//INSERT QUERY
$gift_entry = mysql_query( “INSERT TO `master_list`

(

`g1_st`,
`g1_dt_signup`,
`g1_dt_signup_output`

) VALUES (

‘taken’,
‘$g1_dt_signup’
‘$g1_dt_signup_output’

)”, $dbconn );

//INSERT RESULTS
$result = mysql_query( $gift_entry ) or die( ‘Error: ‘ . mysql_error());

//CLOSE CONNECTION
mysql_close($dbconn) ?>
[/code]

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@NogDogOct 30.2006 — [code=php]
//INSERT QUERY
$gift_entry = mysql_query( "INSERT TO master_list

(

g1_st,
g1_dt_signup,
g1_dt_signup_output

) VALUES (

'taken',
'$g1_dt_signup'
'$g1_dt_signup_output'

)", $dbconn );

//INSERT RESULTS
$result = mysql_query( $gift_entry ) or die( 'Error: ' . mysql_error());
[/code]

In this section you are assigning the [b]results[/b] of a mysql_query() to the variable $gift_entry, then trying to use that result set pointer as a query in a second mysql_query() command.
Copy linkTweet thisAlerts:
@phpnstuffauthorOct 30.2006 — Spell it out for me in "Retarded Mode" ?
Copy linkTweet thisAlerts:
@NogDogOct 30.2006 — You have two mysql_query() commands. The first one executes the query which is given as a string literal in its parameter list, and assigns the return value to the variable $gift_entry. That value is going to either be a special variable type in PHP known as a "resource" (used to reference the query result in related commands) or FALSE if it failed.

You then call mysql_query() again, this time using the variable $gift_entry as the query parameter, but $gift_entry is NOT a query. What you probably want to do is:
[code=php]
//INSERT QUERY
$gift_entry = "INSERT TO master_list

(

g1_st,
g1_dt_signup,
g1_dt_signup_output

) VALUES (

'taken',
'$g1_dt_signup'
'$g1_dt_signup_output'

)";

$result = mysql_query( $gift_entry ) or die( 'Error: ' . mysql_error());
[/code]
Copy linkTweet thisAlerts:
@phpnstuffauthorOct 30.2006 — Can I do this?

[code=php]
//TIME/DATE
$g1_dt_signup = date( "Y-m-d H-i-s" );
$g1_dt_signup_output = date( "m/d/y" );


//INSERT QUERY
mysql_query( "INSERT INTO master_list (g1_st,g1_dt_signup,g1_dt_signup_output) VALUES ('taken','$g1_dt_signup','$g1_dt_signup_output') WHERE cn = 'Christopher We.'") or die(mysql_error());

//CLOSE CONNECTION
mysql_close($dbconn)
[/code]
Copy linkTweet thisAlerts:
@The_Little_GuyOct 30.2006 — You could try something like this:
[code=php]<?php

//DATABASE CONNECTION
include 'includes/mysql/connection.php';

//SELECT DATABAE
$dbname = uw_wipgfhprogram;

//CONNECT TO MYSQL DATABASE
$dbconn = mysql_connect ( $dbhost, $dbuser, $dbpass );

//CHECK IF CONNECTED
if (! $dbconn ) { die( 'Could Not Connect: ' . mysql_error()); }

//SELECT DATABASE
mysql_select_db( $dbname, $dbconn );

//EXMAMPLE USER
$cn = 'Christopher We.';

//SELECT QUERY
$info = mysql_query( "SELECT * FROM master_list WHERE cn = '$cn'", $dbconn );

//TIME/DATE
$g1_dt_signup = date( "Y-m-d H-i-s" );
$g1_dt_signup_output = date( "m/d/y" );

//INSERT QUERY
$gift_entry = mysql_query( "INSERT INTO master_list
(
g1_st,
g1_dt_signup,
g1_dt_signup_output
) VALUES (
'taken',
'$g1_dt_signup',
'$g1_dt_signup_output'
)", $dbconn );

//CLOSE CONNECTION
mysql_close($dbconn)[/code]
×

Success!

Help @phpnstuff 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.18,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

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