[RESOLVED] SQL query not responding correctly
heres my code:
PHP Code:
$sql ="UPDATE `smf_members` SET
`Quote1` = '" . $_POST['Quote1'] . "',
`Quote2` = '" . $_POST['Quote2'] . "',
`Quote3` = '" . $_POST['Quote3'] . "' WHERE `ID_MEMBER` =" . $_GET['user'] . " LIMIT 1 ;";
PHP Code:
<form action="http://sf.greyfyre.info/roed/changequote.php?C=1&user=<?php echo $_GET['user']; ?>" method="post" name="form1" id="form1">
<label>Quote1
<input name="Quote1" type="text" id="Quote1" value="<?php
mysql_close($sql);
echo $data['Quote1'];
?>
" size="40" maxlength="30" />
<label>Quote2
<input name="Quote2" type="text" id="Quote2" value="<?php
echo $data['Quote2'];
?>" size="40" maxlength="30" />
<label>Quote3
<input name="Quote3" type="text" id="Quote3" value="<?php
echo $data['Quote3'];
?>" size="40" maxlength="30" />
</label>
</p>
<label>Password
<input name="password" type="password" id="password" />
</label>
<input type="submit" name="Submit" value="Submit" /></p>
</form>
and heres my problem, some times the code will update a database, and sometimes it will only change quote3, is it something i am not doing right? (probably is but i thought i would come here first because im still learning php)
Re: SQL query not responding correctly
echo your SQL query to make sure that it's printing correctly and what you want.
also, I'd suggest making safe variables for your quotes, just in case some random character is screwing your query up. Something like this:
PHP Code:
$quote1 = mysql_real_escape_string($_POST['quote1']);
$quote2 = mysql_real_escape_string($_POST['quote2']);
$quote3 = mysql_real_escape_string($_POST['quote3']);
$sql ="UPDATE `smf_members` SET " .
"`Quote1`='$quote1', `Quote2`='$quote2', `Quote3`='$quote3' " .
"WHERE `ID_MEMBER`=" . $_GET['user'] . " LIMIT 1 ;";
mysql_query($sql);
Also, it's probably just a peeve of mine, but the code for your form is a bit hard to read with all the line breaks you make. If you don't know what I mean, it's that you can just put your PHP stuff on the same line and not return after <?php. It's not necessary, but it does make your code easier to read, if you ask me. Also, you don't need to use mysql_close() in the form like you do (unless you have it there for some special reason), the connection will close itself.
One last tip: instead of embedding the "user='thisuser'" in the URL using GET, I would suggest you just put a hidden input in the form with the value of the current user. This way, that user can't in any way edit that field. Something like this:
PHP Code:
<form action="http://sf.greyfyre.info/roed/changequote.php?C=1" method="post">
<input type="hidden" name="user" value="<?php echo $user; ?>">
Then, just reference the user as $_POST['user'] instead of $_GET['user'].
Re: SQL query not responding correctly
UPDATE `smf_members` SET `Quote1`='1 ', `Quote2`='1', `Quote3`='1' WHERE `ID_MEMBER`='1' LIMIT 1 ;
Is what i get (from a test) does that look right to anyone? And does the LIMIT 1 do anything, (like limit it to only 1 character?)
Re: SQL query not responding correctly
LIMIT 1 will limit it to one returned result, which is basically what you want if you want to only return one result, so that should be fine. anyway, your query syntax looks fine.
if you have phpMyAdmin installed on the server, you can try using that query within it. I can't see a reason why that might be happening for you :/ the most advice I could give would be to get rid of the ` quotes around field names (ie: Quote1 instead of `Quote1`), but phpMyAdmin adds those quotes when changing stuff so I still don't see what could be wrong @_@.
soo, if you do have phpMyAdmin installed, you could always just edit an existing record in your table and copy the SQL from it into your script, that way all of the SQL syntax you could have would be fine, and if it didn't work then it would most likely have something to do with your variables or with how your database is set up, maybe.
Re: SQL query not responding correctly
Quote:
Originally Posted by kows
if you have phpMyAdmin installed on the server, you can try using that query within it.
I got a friend to fix it, it turend out to be majorly the cache not changing the output properly, and then some other code error a bit further down the script,
Thankx guys for helping me :thumb: