0

I've prepared a statement for updating users address. However I am getting error 1064, and I just do not know what could be wrong anymore. I would appreciate help with this. Thanks! Also I am 100% sure the order matches my Database.

Error: query error: 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

Code:

$update = $conn->prepare("UPDATE `address` SET `firstName` = ?, `lastName` = ?, `phoneNum` = ?, `streetName` = ?, `streetNum` = ?, `country` = ?, `city` = ?, `postalCode` = ? WHERE `customerForeign` = ?");
$update->bind_param('sssssssii', $firstName, $lastName, $phoneNum, $streetName, $streetNum, $country, $city, $postalCode, $currentUserID);
$update->execute();
New contributor
Daniel Radosa is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
4
  • 1
    You need to post the error message in its entirety; don't expect people to look it up for you.
    – mustaccio
    Nov 25 at 16:26
  • the entire message im getting is: query error 1064 Nov 25 at 16:29
  • @DanielRadosa This is not error message but a small part of it. You must provide conplete and unchanged message text like it is produced by MySQL server.
    – Akina
    Nov 25 at 17:04
  • This is the most specifically I could print the error: query error: 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 Nov 25 at 17:42
0

near '' means that something went wrong at the "end" of the query. This might be unbalanced parens, missing quotes, etc. I don't see any obvious issue. Please provide the values you are substituting.

Obviously, you are not in Britain - where "postal codes" include letters. And, if you are in the US, you might worry about leading zeros on zipcodes.

1
  • Wow, I retard was grabbing wrong name from my form... Jesus! Thanks, I realized I should check my HTML form as well if I am grabbing right names. <3 Nov 25 at 18:45
0

In my HTML the name I pass into statement was mis-spelled. Form:

 <form action="<?php echo $_SERVER['PHP_SELF'] . "?" . $user_to_update ?>" method="POST">
            <input type="text" placeholder="First Name" name="firstNameU" style="width: 360px;" value="<?php echo $row['firstName'] ?>" required>
            <input type="text" placeholder="Last Name" name="lastNameU" style="width: 360px;" value="<?php echo $row['lastName'] ?>" required>
            <br>
            <input type="tel" pattern="^[0-9-+\s()]*$" placeholder="Phone +xxxxxxxxx" name="phoneNumU" style="width: 360px;" value="<?php echo $row['phoneNum'] ?>" required>
            <input type="street" placeholder="Street Name" name="streetNameU" style="width: 300px;" value="<?php echo $row['streetName'] ?>"  required>
            <input type="text" placeholder="Street Number" name="streetNumU" style="width: 300px;" value="<?php echo $row['streetNum'] ?>"  required>
            <br>
            <input type="number" placeholder="Postal Code: xxxxx" name="postalCodeU" style="width: 300px;" value="<?php echo $row['postalCode'] ?>" required>
            <input type="city" placeholder="City" name="cityU" style="width: 300px;" value="<?php echo $row['city'] ?>" required>
            <select type="country" name="countryU" id="countryU" style="width: 300px;"  required>
                <option value="<?php echo $row['country'] ?>"><?php echo $row['country'] ?></option>
                <option value="France">France</option>
                <option value="Slovakia">Slovakia</option>
                <option value="Denmark">Denmark</option>
                <option value="Germany">Germany</option>
                <option value="Italy">Italy</option>
            </select>
            <br>
            <input type="reset" name="clear" value="Clear Fields" style="color: white; background-color: red; float: left; border: none; width: 300px;">
            <input type="submit" name="update" value="Update Address" style="color: white; background-color: blue; float: right;">
        </form>

It was in the input type tel, where I was missing U at the end of the name.

New contributor
Daniel Radosa is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Your Answer

Daniel Radosa is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.