mysqli php insert issue parameter error

code is insert page from a four page form:

[php]

<?php include("login.php"); ?> <?php session_start(); $firstname = $_SESSION['firstname']; $lastname = $_SESSION['lastname']; $email = $_POST['email']; $phone = $_SESSION['phone']; $eighteen_or_older = $_SESSION['eighteen_or_older']; $manager_contact = $_POST['manager_contact']; $greeted_promptly = $_SESSION['greeted_promptly']; $timely_completion = $_SESSION['timely_completion']; $satisfied = $_POST['satisfied']; $recommend = $_POST['recommend']; //Send to DB-------------------------------------- //MySQL Database Connect-------------------------- include 'login.php'; if ($stmt = $mysqli->prepare("INSERT service (`firstname`, `lastname`, `email`, `phone`, `greeted_promptly`, `timely_completion`, `satisfied`, `recommend`, `eighteen_or_older`, `manager_contact`) VALUES (?, ?, ?, ?,?, ?, ?,?, ?, ?)")) { $stmt->bind_param("sssissssss", '$firstname', '$lastname', '$email', '$phone', '$greeted_promptly', '$timely_completion', '$satisfied', '$recommend', '$eighteen_or_older', '$manager_contact'); $stmt->execute(); //echo $stmt->affected_rows.'Success: Inserted into Database'; $stmt->close(); } ?> [/php]

error is

PHP Fatal error: Cannot pass parameter 2 by reference (error references the line near bottom beginning with statement bind param)

Thoughts? Thanks.

When using quotes around the variables (’$firstname’) you’re effectivly making these strings. So PHP isn’t trying to send the value of $firstname, it sends the actual text/string “$firstname”

Remove the quotes.

Thanks i tried that earlier
Says firstname can not be null
That is the new error
?

then $firstname ($_SESSION[‘firstname’]) is null

Yeah i thought so but it isn’t
Tried moving the assignment of var to various places in the code
No help
Tried making everything a string no help
Read online for hours including mysql and php manuals
Stumped

So when debugging at line 33 ($stmt->bind_param("sss…) $firstname is a valid value?

Valid as in?
There is a place for it in database
There is a cometed form space for it
It is spelledcorrectly
I may need to validate some other wAy?
Is that what valid means in this scenario?
I really dont know i could be missing something

Add var_dump($firstname); directly before line 33. Is the value null or the name of the logged in user?

If it is null you need to figure out why the session data isn’t coming across. Try to var_dump($_SESSION) and see if it gives any clues about what’s wrong

Thanks i will try that

here is my new error

PHP Warning: mysqli_stmt::execute() [mysqli-stmt.execute]: (23000/1048): Column ‘firstname’ cannot be null in /home/esc2/public_html/feedback_form_process.php on line 34

here is my new code

[php]

<?php include("login.php"); ?> <?php session_start(); //the session is the email address //MySQL Database Connect-------------------------- include 'login.php'; //Send to DB------------------------------ $firstname = $_SESSION['firstname']; $lastname = $_SESSION['lastname']; $email = $_POST['email']; $phone = $_SESSION['phone']; $eighteen_or_older = $_SESSION['eighteen_or_older']; $manager_contact = $_POST['manager_contact']; $greeted_promptly = $_SESSION['greeted_promptly']; $timely_completion = $_SESSION['timely_completion']; $satisfied = $_POST['satisfied']; $recommend = $_POST['recommend']; $stmt = $mysqli->stmt_init(); if ($stmt->prepare("INSERT INTO service (firstname, lastname, email, phone, greeted_promptly, timely_completion, satisfied, recommend, eighteen_or_older, manager_contact) VALUES (?, ?, ?, ?,?, ?, ?,?, ?, ?)")) { var_dump($firstname); $stmt->bind_param('ssssssssss', $firstname, $lastname, $email, $phone, $greeted_promptly, $timely_completion, $satisfied, $recommend, $eighteen_or_older, $manager_contact); $stmt->execute();} ?> [/php]

the code above is the fourth page of a four page form, the fourth page is the submit portion
pages one through three are below

[php]

Service Feedback Form Page 1

Please answer four questions about your service today:

Before we start, please enter your email address:


1 of 4. Were you greeted promptly upon arrival today?

Yes


No

2 of 4. Was your service completed within the promised time?

Yes


No

[/php]

[php]

<?php session_start(); $_SESSION['email'] = $_POST['email']; ?> Service Feedback Form Page 2

Proceeding...:

3 of 4. Was the work completed to your satisfaction?

Yes


No

4 of 4. Will you recommend us to friends?

Yes


No

[/php]

[php]

<?php session_start(); $_SESSION['email'] = $_POST['email']; ?>

Your First Name:

Your Last Name:

Your Phone Number, Optional:

Are you at least 18 years old?

Yes

No

Would you like to be contacted by a manager?

Yes

No

By clicking submit below you agree to our contest terms.

[/php]

starts on the form page one, goes to page two, three then the final form to submit. they are loaded reverse order…sorry.
the database table is set up to exactly match the form input, all changed to strings (varchar) to make this test easy…still won’t work. Thanks for any help.

Debugging and figuring out why stuff dont work is a big part of what we as programmers do. You must figure out why session-firstname is empty, its close to impossible for us to know.

In order to figure it out you will have to do what I wrote in the last post. Dump out the value.

If the session-firstname value is null, then go to where you save it and check there

My db table? No data inserted. Is that what u mean?

value came back NULL
tried Print_r ($_SESSION); and it says Array ( [email] => )
I am asking myself if I have ever gotten binding params to work with php/mysqli

From what I’m seeing online not many people have
Seems like it is tough to get to work…

BTW the email is the session id…

This has nothing to do with mysqli, it’s that you don’t have the data in the session that you think you got there. It obviously isn’t possible to bind $_SESSION[‘firstname’] when there is no $_SESSION[‘firstname’].

And email as the session ID sounds like a bad idea. What if I change my cookie to say I’ve got your email? Will I be accepted into your session?

And binding params can be really easy, check out my PDO tutorial to see just how easy it can be

I am not using pdo should i be?
I started dumping vars like u suggeste
Thanks for that
I now believe it is in the sessions
Something is not getting passed from first two pages of form
Thx

You should use PDO or mysqli, I usually recommend PDO as it’s more versatile. But for normal use mysqli is just as good.

For this issue you need to figure out why you have no session data. Stop worrying about parameterized queries, you might’ve hd them correct all along :stuck_out_tongue:

ok here is the new code…still won’t work but i think it is close

three page form…first three pages are:

[php]

Service Feedback Form Page 1

Enter To Win:

Please answer four quick questions about your service today:

Before we start, what is your email address:


1 of 4. Were you greeted promptly upon arrival today?

Yes


No

2 of 4. Was your service completed within the promised time?

Yes


No

[/php]

[php]

<?php $greeted_promptly = $_GET['greeted_promptly']; $timely_completion = $_GET['timely_completion']; $greeted_promptly = $_POST['greeted_promptly']; $timely_completion = $_POST['timely_completion']; ?> <?php session_start(); ?> Service Feedback Form Page 2

Proceeding...

3 of 4. Was the work completed to your satisfaction?

Yes


No

4 of 4. Will you recommend us to friends?

Yes
No

[/php]

[php]

<?PHP $satisfied = $_GET['satisfied']; $recommend = $_GET['recommend']; $satisfied = $_POST['satisfied']; $recommend = $_POST['recommend']; ?> <?php session_start(); ?>

Your First Name:

Your Last Name:

Your Phone Number, Optional:

Are you at least 18 years old?

Yes

No

Would you like to be contacted by a manager?

Yes

No

By clicking submit below you agree to our contest terms.

[/php]

and submit form

[php]

<?PHP $satisfied = $_GET['satisfied']; $recommend = $_GET['recommend']; $satisfied = $_POST['satisfied']; $recommend = $_POST['recommend']; ?> <?php session_start(); ?>

Your First Name:

Your Last Name:

Your Phone Number, Optional:

Are you at least 18 years old?

Yes

No

Would you like to be contacted by a manager?

Yes

No

By clicking submit below you agree to our contest terms.

[/php]

prints out this

array(0) {
}
string(3) “GGG”
string(2) “GG”
NULL
string(1) “G”
NULL
string(3) “yes”
NULL
NULL
NULL
NULL
string(5) “email”

I may have forgotten to post the new submit page I’m using. I saw that also. Thanks.

[php]

<?php include("login.php"); ?> <?php session_start(); //MySQL Database Connect-------------------------- include 'login.php'; //Send to DB------------------------------ echo '
';
var_dump($_SESSION);
echo '
'; $firstname = $_GET['firstname']; $lastname = $_GET['lastname']; $email = $_GET['email']; $phone = $_GET['phone']; $eighteen_or_older = $_GET['eighteen_or_older']; $manager_contact = $_GET['manager_contact']; $greeted_promptly = $_GET['greeted_promptly']; $timely_completion = $_GET['timely_completion']; $satisfied = $_GET['satisfied']; $recommend = $_GET['recommend']; $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $email = $_POST['email']; $phone = $_POST['phone']; $eighteen_or_older = $_POST['eighteen_or_older']; $manager_contact = $_POST['manager_contact']; $greeted_promptly = $_POST['greeted_promptly']; $timely_completion = $_POST['timely_completion']; $satisfied = $_POST['satisfied']; $recommend = $_POST['recommend']; echo '
';
var_dump($firstname);
echo '
'; echo '
';
var_dump($lastname);
echo '
'; echo '
';
var_dump($email);
echo '
'; echo '
';
var_dump($phone);
echo '
'; echo '
';
var_dump($eighteen_or_older);
echo '
'; echo '
';
var_dump($manager_contact);
echo '
'; echo '
';
var_dump($greeted_promptly);
echo '
'; echo '
';
var_dump($timely_completion);
echo '
'; echo '
';
var_dump($satisfied);
echo '
'; echo '
';
var_dump($recommend);
echo '
'; $stmt = $mysqli->stmt_init(); if ($stmt->prepare("INSERT INTO service (firstname, lastname, email, phone, greeted_promptly, timely_completion, satisfied, recommend, eighteen_or_older, manager_contact) VALUES (?, ?, ?, ?,?, ?, ?,?, ?, ?)")) { echo '
';
var_dump(email);
echo '
'; $stmt->bind_param("ss ss ss ss ss", $firstname, $lastname, $email, $phone, $greeted_promptly, $timely_completion, $satisfied, $recommend, $eighteen_or_older, $manager_contact); $stmt->execute();} ?> [/php]

the problem is that the items entered in the first two pages aren’t getting into the form submit
but i don’t know why

I only have ten…

Sponsor our Newsletter | Privacy Policy | Terms of Service