[SOLVED] $_POST var in mysql query

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
radium35
Forum Commoner
Posts: 50
Joined: Mon Nov 10, 2008 5:05 pm
Location: USA
Contact:

[SOLVED] $_POST var in mysql query

Post 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:
Last edited by radium35 on Wed Jul 08, 2009 1:48 pm, edited 1 time in total.
User avatar
genconv
Forum Commoner
Posts: 34
Joined: Sun Jul 05, 2009 9:27 am

Re: what? the

Post 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'");
 
User avatar
radium35
Forum Commoner
Posts: 50
Joined: Mon Nov 10, 2008 5:05 pm
Location: USA
Contact:

Re: what? the

Post by radium35 »

tried it but still get a blank page no dice
User avatar
radium35
Forum Commoner
Posts: 50
Joined: Mon Nov 10, 2008 5:05 pm
Location: USA
Contact:

Re: what? the

Post by radium35 »

it is weird because if i put hard code the values for example 'hello' instead of '$hello' it works....
User avatar
radium35
Forum Commoner
Posts: 50
Joined: Mon Nov 10, 2008 5:05 pm
Location: USA
Contact:

Re: what? the

Post 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());
Post Reply