0

I'm getting the error '1' at line 1, I'm a bit stumped with this one; I'm a complete noob and usually try to correct things without asking for help

It inputs all the data correctly into the db, but offers up this error.

There are a couple of other threads with the same question, the solution to one was: "That was the reason error appeared: you tried to call mysql_query with result of the last update query. Which was, as TRUE converted to String, just '1'."

$title = mysqli_real_escape_string($con, $_POST['title']);
$firstname = mysqli_real_escape_string($con, $_POST['firstname']);
$lastname = mysqli_real_escape_string($con, $_POST['lastname']);
$jobtitle = mysqli_real_escape_string($con, $_POST['jobtitle']);
$address = mysqli_real_escape_string($con, $_POST['address']);
$address2 = mysqli_real_escape_string($con, $_POST['address2']);
$address3 = mysqli_real_escape_string($con, $_POST['address3']);
$postcode = mysqli_real_escape_string($con, $_POST['postcode']);
$telephone = mysqli_real_escape_string($con, $_POST['telephone']);
$email = mysqli_real_escape_string($con, $_POST['email']);

(I know I should really make a prepared statement)

$sql = mysqli_query($con, "UPDATE users SET title='$title', firstname='$firstname', lastname='$lastname', jobtitle='$jobtitle', address='$address', address2='$address2', address3='$address3', postcode='$postcode', telephone='$telephone', email='$email' WHERE username='$user'");

if (!mysqli_query($con,$sql)) {
$result_array = mysql_fetch_assoc($qStuff);
die('Error: ' . mysqli_error($con));
}
Dharman
  • 30,962
  • 25
  • 85
  • 135
Honest Objections
  • 773
  • 1
  • 6
  • 13
  • 1
    You execute the query and put the result into $sql, and then you execute that result – Kickstart Jul 09 '14 at 08:16
  • 2
    Don't mix calls to `mysqli_*()` with calls to `mysql_*()` - the two aren't compatible. `UPDATE` doesn't return a result set. Lastly, you're using $qStuff but it's not initialised anywhere. –  Jul 09 '14 at 08:17
  • It is great that you remembered to appropriately escape your input data, but an even better and cleaner solution would be to use prepared statements. Alas, I am not familiar enough with MySQLi to tell exactly how that should be done, but this should be enough for you to help you search. – glglgl Jul 09 '14 at 08:20

1 Answers1

0

the following line stores the value "1" in $sql when the insertion is successful and 0 when failed.

$sql = mysqli_query($con, "UPDATE users SET title='$title', firstname='$firstname', lastname='$lastname', jobtitle='$jobtitle', address='$address', address2='$address2', address3='$address3', postcode='$postcode', telephone='$telephone', email='$email' WHERE username='$user'");

And you are trying to execute this

if (!mysqli_query($con,$sql)) 

here, the value of $sql is "1" which is not a valid query. That results in syntax error. Probably if you are trying to achieve this:

$sql = "UPDATE users SET title='$title', firstname='$firstname', lastname='$lastname', jobtitle='$jobtitle', address='$address', address2='$address2', address3='$address3', postcode='$postcode', telephone='$telephone', email='$email' WHERE username='$user'";
if(mysqli_query($con,$sql)){
    //do something if the operation is successful
}
Aravind
  • 609
  • 6
  • 14