| Author |
Message |
Desbrina Jadeite

Joined: 11 Jun 2005 Posts: 2984 Location: Earth
|
Posted: Sat Nov 17, 2007 8:59 am Post subject: php/mysql problem |
|
|
| Code: | <?php
if(isset($_POST['Submit'])) {
$user = $_POST['name'];
$pass = $_POST['password'];
$pass = MD5($pass);
$sql = "SELECT *
FROM `memberlist`
WHERE `name` = '$user'
AND `password` = '$pass'";
$result = mysql_db_query($db_name, $sql, $con);
if (!$result) { echo( mysql_error());
echo "<br />Incorrect Username or password combination<br />" ;
} else {
while ($row = mysql_fetch_array($result)) {
$side = $row['side'];
$check = "SELECT name FROM game_clonewars WHERE name = '$_POST[name]'";
$check_r = mysql_db_query($db_name, $check, $con);
if ($check_r){
while ($row = mysql_fetch_array($check_r)) {
// User does exist, so lets update their current points
$update = "UPDATE game_clonewars set points = {$points} where name = '$_POST[name]' LIMIT 1";
echo "Points updated sucessfully";
mysql_db_query($db_name, $update, $con);
echo mysql_error();
}
} else {
// User doesn't exist, so lets add them
$add = "INSET INTO game_clonewars VALUES (NULL, '$_POST[name]', $points, '$side')";
print $add;
echo "User made and updated sucessfully";
mysql_db_query($db_name, $check, $con);
}
}
}
}
?> |
This is the code i'm having trouble with
Its supposed to check that a user exists in the memberlist table, if not give an error message.
If they exists then check to see if the user exists game_clonewars table, if not create then, if they do exist, then update
I'm sure the solution is a simple on, but at the moment, the code does nothing.
I can print the first sql statement ($sql) and the values are correct, but it doesn't progress any further. It show any errors either _________________ Midnight Tempest - A Sailor Moon TCG
Balanced Force - A Star Wars TCG
Caretaker - A Star Trek Voyager TCG |
|
| Back to top |
|
| |
Scott tutorialtoday.com

Joined: 24 Mar 2005 Posts: 2632 Location: Mississauga, Ontario
|
Posted: Sat Nov 17, 2007 9:59 am Post subject: Re: php/mysql problem |
|
|
| Code: | <?php
if(isset($_POST['Submit'])) {
$user = $_POST['name'];
$pass = $_POST['password'];
$pass = MD5($pass);
$sql = mysql_query("SELECT * FROM `memberlist` WHERE `name` = '".$user."' AND `password` = '".$pass."'") or die(mysql_error());
$result = mysql_num_rows($sql);
if ($result == 0) {
echo "<br />Incorrect Username or password combination<br />" ;
} else {
while ($row = mysql_fetch_array($sql)) {
$side = $row['side'];
$check = mysql_query("SELECT `name` FROM `game_clonewars` WHERE `name` = '".$_POST['name']."'") or die(mysql_error());
if (mysql_num_rows($check) == 1){
while ($row = mysql_fetch_array($check_r)) {
// User does exist, so lets update their current points
mysql_query("UPDATE `game_clonewars` set `points` = '".$points."' WHERE `name` = '".$_POST['name']."' LIMIT 1") or die(mysql_error());
echo "Points updated sucessfully";
}
} else {
// User doesn't exist, so lets add them
mysq_query("INSERT INTO `game_clonewars` VALUES (NULL, '".$_POST['name']."', '".$points."', '".$side."')") or die(mysql_error());
echo "User made and updated sucessfully";
}
}
}
}
?> |
Try that, I cleaned it up a bit and changed some of the functions used. Also, on the query to add them, the word "INSERT" was spelled wrong. _________________ Tutorial Management Script - Version 1.4 Released
TutorialToday - Up and running, submit your tutorials!
Linux Tutorials - Coming Soon |
|
| Back to top |
|
| |
Desbrina Jadeite

Joined: 11 Jun 2005 Posts: 2984 Location: Earth
|
Posted: Sat Nov 17, 2007 10:07 am Post subject: |
|
|
thanks, appaert from a spelling mistake on the third sql query (mysq_query should have been mysql_query) it works fine. Now i just have to do this for the other pages that have the same problem. (It worked a while ago, just not now)
I know this next question has nothing to do with the first, but is there a way of checking that a text field has only numbers in it, not text. Because of someone enters text instead of a number, the whole thing wouldn't work _________________ Midnight Tempest - A Sailor Moon TCG
Balanced Force - A Star Wars TCG
Caretaker - A Star Trek Voyager TCG |
|
| Back to top |
|
| |
spock iSpock

Joined: 23 Mar 2005 Posts: 2917 Location: The Netherlands
|
Posted: Sat Nov 17, 2007 2:41 pm Post subject: |
|
|
| Desbrina wrote: | | I know this next question has nothing to do with the first, but is there a way of checking that a text field has only numbers in it, not text. Because of someone enters text instead of a number, the whole thing wouldn't work |
http://nl3.php.net/is_numeric _________________ My new site
My OpenTTD data package |
|
| Back to top |
|
| |
|
|
|