Jump to content


Photo

problem with putting info in MySQL.


  • Please log in to reply
6 replies to this topic

#1 foreverhex

foreverhex
  • Members
  • PipPipPip
  • Advanced Member
  • 91 posts

Posted 18 July 2006 - 05:25 AM

I have made this code and Im still new at MySQL so I apoligize if it looks buggy. But when you go to submit the info it wont switch any thing and makes the name value 0? Here is the code, any ideas why?

<?php

include 'db.php';

//Grab the reviewed user info

$user = $_POST['user'];
$password = $_POST['password'];
$name = $_POST['name'];
$email = $_POST['email'];
$age = $_POST['age'];
$sex = $_POST['sex'];
$location = $_POST['location'];
$medium = $_POST['medium'];
$interests = $_POST['interests'];
$homepage = $_POST['homepage'];

//New Password check
if ((!$password)) {

$sql = mysql_query("UPDATE users SET name='$name' AND email='$email' AND age='$age' AND sex='$sex' AND location='$location' AND medium='$medium' AND interests='$interests' WHERE user='$user'");

}

else {
$newpassword =md5($password);

$sql = mysql_query("UPDATE users SET password='$newpassword' AND name='$name' AND email='$email' AND age='$age' AND sex='$sex' AND location='$location' AND medium='$medium' AND interests='$interests' WHERE user='$user'");

if(!$sql) {
echo "There has been an error while trying to modify your account. Please report a bug in the forums or try again later.";
}
}

echo 'You information has been updated!';
?>


#2 toplay

toplay
  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 18 July 2006 - 05:28 AM

Replace all the 'AND' in the update with commas. See the UPDATE syntax in the manual:

http://dev.mysql.com.../en/update.html


#3 foreverhex

foreverhex
  • Members
  • PipPipPip
  • Advanced Member
  • 91 posts

Posted 18 July 2006 - 01:24 PM

So you never want to put AND 's? That worked thanks!

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 18 July 2006 - 02:45 PM

You only to use AND in a query you are comparing somthing to something else, such as within a WHERE clause

#5 foreverhex

foreverhex
  • Members
  • PipPipPip
  • Advanced Member
  • 91 posts

Posted 18 July 2006 - 08:02 PM

AHH! I see, so an example would be WHERE user='$user' AND email='$email' . Thats good to know thanks!

#6 Chevy

Chevy
  • Members
  • PipPipPip
  • Advanced Member
  • 163 posts

Posted 18 July 2006 - 08:07 PM

Yup and you can use it in any other statement

example

if ($user==Bob AND password==bobby){


#7 foreverhex

foreverhex
  • Members
  • PipPipPip
  • Advanced Member
  • 91 posts

Posted 18 July 2006 - 08:12 PM

Kick ass! There are some many things I still need to learn but I need to screw up to figure out that I need to know these things.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users