Jump to content
Timelord

Problema PHP+MySQL

Recommended Posts

Salutare!

Am un site cu o baza de date cu o tablea cu useri si vreau sa adaug o optiune prin care userul loggat sa poata adauga diferite detalii cum ar fi emailu' in campuri deja existente din tabela useri,dar n-am reusit,imi adauga informatiile dar nu pentru useri ci intr-un rand nou cu restul campurilor goale.Codul:

$query = mysql_query("INSERT INTO users  (email) VALUES('".$email."')");

Exista vreo modalitate de a rezolva problema fara sa creez o noua tabela?

Link to comment
Share on other sites

Fiindca nu e corect ceea ce faci, in loc sa updatezi detaliile userului logat, tu inserezi detalii pe un rand nou (gol) din tabelul de useri.

Normal ar fi ceva de genu :


$sql = "UPDATE users SET email = '{$email}' WHERE id = {$id_user_logat};";

Link to comment
Share on other sites

Sau mai simplu


<?php
$db = new MySQLi('localhost', 'nume_utilizator', 'parola', 'nume_baza_de-date');
if($db->connect_error) {
die("Connection failed: " . $db->connect_error);
}
$sql = $db->query("UPDATE `users` SET `email` = '{$email}' WHERE `id` = {$id_user_logat} LIMIT 1;");
if(!$sql->error) {
die("Query Error".$sql->error);

succes. este mult mai usor mysqli si eficient decat mysql

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...