Board index   FAQ   Search  
Register  Login
Board index PHP PHP Scripts

Why does this code doesn't update my database?

Links for php scripts

Moderators: macek, egami, gesf

Why does this code doesn't update my database?

Postby ismaelvc » Tue Jun 24, 2014 6:42 am

Hello everyone! Im a noob in PHP, and I can't make this program update my database. This is the code:

Code: Select all

<title>Actualizacion completada.</title>
<META name='robot' content='noindex, nofollow'>



$Id_Inv   = $_POST['Id_Inv'];
$Producto = $_POST['Producto'];
$Sabor    = $_POST['Sabor'];
$Cantidad = $_POST['Cantidad'];
$Id_Prov  = $_POST['Id_Prov'];

$conexion = mysql_connect('localhost', 'root', '12345');


$sSQL = mysql_query("Update inventario
                    WHERE Id_Inv= '{$Id_Inv}'");


echo "
<p>Los datos han sido actualizados con exito.</p>

<p><a href='javascript:history.go(-1)'>VOLVER ATRÁS</a></p>

<p><a href='javascript:history.go(-2)'>INICIO</a></p>




First I thought it was a matter of wrong string interpolation, (that I had to use {}, for correct interpolation), but doing, some tests, I don't think so anymore, do you guys have any idea? :help:

Thanks in advance!
New php-forum User
New php-forum User
Posts: 1
Joined: Tue Jun 24, 2014 6:38 am

Re: Why does this code doesn't update my database?

Postby robertoshayerlyra » Fri Jun 27, 2014 5:53 am

connections can be annoying.
The problem is figuring out the exact point where things go wrong.
Tip: Try to break your problems to find out exactly where the problem lies.
First: change your mixed sql expression for a full text expression:

"Update inventario SET Producto='abc', sabor='bacon', Cantidad='123', Id_Prov='456', WHERE Id_Inv= '890'"

Ops: there is a comma before WHERE??

Good luck
New php-forum User
New php-forum User
Posts: 2
Joined: Fri Jun 27, 2014 5:43 am

Re: Why does this code doesn't update my database?

Postby freshnet » Sat Oct 18, 2014 4:44 pm

Yeah that query doesn't look right (comma before where clause). See my signature(!) echo back the query and try running it in your query tool. I would strongly recommend using mysqli or PDO instead of the mysql extension, which is deprecated. PDO uses try{} catch{} blocks to check for errors, so if a query errors out, you can show the error while you're testing code.
User avatar
php-forum Active User
php-forum Active User
Posts: 278
Joined: Tue Feb 22, 2011 8:19 am
Location: Canada

Return to PHP Scripts

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.