0

updating SQL using PHP

The message to screen is:

object(mysqli)[1]
  public 'affected_rows' => null
  public 'client_info' => null
  public 'client_version' => null
  public 'connect_errno' => null
  public 'connect_error' => null
  public 'errno' => null
  public 'error' => null
  public 'field_count' => null
  public 'host_info' => null
  public 'info' => null
  public 'insert_id' => null
  public 'server_info' => null
  public 'server_version' => null
  public 'stat' => null
  public 'sqlstate' => null
  public 'protocol_version' => null
  public 'thread_id' => null
  public 'warning_count' => null
No rows updated 

My code is:

$connection = @mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);
if (mysqli_connect_error()) {
        die(`Connect Error: ` . mysqli_connect_error());
} else {
        echo `Successful connection to MySQL <br />`;

    $employ = $_POST['employer'];
    $address = $_POST['flat'];
    $login_name = $_POST['login_name'] ;
    var_dump($connection);

//    Insert employer and address into database row for logged in user.    

$query = "UPDATE members SET employer = `$employ`, flat = `$address` WHERE     login=`$login_name`";

if (!$result = $connection->query($query)) {
        echo "No rows updated <br />";
    } else {
            echo $result . " row(s) successfully updated<br />";
            }
    }



?>

The form I am getting the information from is:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>



<body>
<table width="100%" border="0" >
<tr>
<td colspan="2" style="background-color:#FFA500;">
</td>
</tr>

<td style="height:500px;width:400px; ">
<center>


<h2>Update</h2><br>


<form action="update.php" method="post">
<input type="hidden" name="login_name" value="$_SESSION['SESS_LOGIN']">

<p>employer <input type="text" name="employer"> </p>
<p>flat number <input type="text" name="flat"></p>
<p><input type="submit" value="Login" ></p>
</form>



</center>

</td>
</tr>

</table>

I've been trying to get this to work for days. The user logs into their profile and all of their information is then taken from the SQL database and then displayed onto the screen. The form above is to update their profile with specific information updating their row in the database for the next time they log in.

8
  • Please switch to prepared statements to prevent SQL injection. Commented Jun 6, 2013 at 17:06
  • Just curious ... did Marcel Korpel's suggestion resolve your issue? LOL Commented Jun 6, 2013 at 17:08
  • Hi @Marcel I'm not to worried about security at the moment as I am still learning and this wont actually go live. Thanks Commented Jun 6, 2013 at 17:08
  • Are you using PHP admin? Commented Jun 6, 2013 at 17:09
  • 1
    You should be worried about security! And these pages are seen by more people than just you and me; they might think this is a good example of programming a query. Commented Jun 6, 2013 at 17:09

1 Answer 1

1

Remove the "@" on your connect to see the error you get while connecting. as you see in your connection-object you don't habe a database-connection.

Sign up to request clarification or add additional context in comments.

2 Comments

Still no luck in getting it working unfortunately! Is there anything obvious that I am missing/not aware of?
As long as your $connection-object only got NULLs you don't have a db-connection. You should first make sure about getting a working db-connection, so check your host/user/password/db. Take a empty php file and only include your database-connector. As I see now your if must be "if($connection->mysqli_connect_error()).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.