Page 1 of 1

[SOLVED] $_POST var in mysql query

Posted: Wed Jul 08, 2009 11:20 am
by radium35
variables are not working in the mysql query? is it because they are $_POST?

if (!$link = mysql_connect('localhost', 'db', 'pass')) {
echo 'Could not connect to mysql';
exit;
}

if (!mysql_select_db('db', $link)) {
echo 'Could not select database';
exit;
}

echo $username="$_POST[username]" . "<br/>";
echo $newimage = $_FILES['uploaded']['name'] ;
echo $oldimage = "$_POST[imagename];". "<br/>";


mysql_query("UPDATE members SET image1='$newimage' WHERE username='$username' AND image1='$oldimage'");

:banghead:

Re: what? the

Posted: Wed Jul 08, 2009 11:36 am
by genconv
This code could work properly:

Code: Select all

 
<?php
if (!$link = mysql_connect('localhost', 'db', 'pass')) {
echo 'Could not connect to mysql';
exit;
}
 
if (!mysql_select_db('db', $link)) {
echo 'Could not select database';
exit;
}
$username= $_POST['username'];
$newimage = $_FILES['uploaded']['name'] ;
$oldimage = $_POST['imagename'] ;
 
mysql_query("UPDATE members SET image1='$newimage' WHERE username='$username' AND image1='$oldimage'");
 

Re: what? the

Posted: Wed Jul 08, 2009 1:28 pm
by radium35
tried it but still get a blank page no dice

Re: what? the

Posted: Wed Jul 08, 2009 1:32 pm
by radium35
it is weird because if i put hard code the values for example 'hello' instead of '$hello' it works....

Re: what? the

Posted: Wed Jul 08, 2009 1:47 pm
by radium35
SOLVED :drunk:

echo $username = $_POST['username'];
echo $newimage = $_FILES['uploaded']['name'];
echo $oldimage = $_POST['imagename'];




$result = mysql_query("UPDATE members SET image1='$newimage' WHERE image1='$oldimage'") or die(mysql_error());