Page 1 of 1
Ok :s
Posted: Tue Aug 02, 2005 6:53 pm
by ericburnard
i created this code from the mysql manual on their site but it dosnt seem to want to work. what it is ment to do is when the id is stated in the url (as blah.php?mail=14) it replaces what is in the table coloum new for the row with id 14 , for the word Old.
Code: Select all
<?php
// Connecting, selecting database
mysql_connect('localhost', '****', '************')
or die('Could not connect: ' . mysql_error());
mysql_select_db('madashat_mail') or die('Could not select database');
$username = mysql_real_escape_string($_GET['user']);
$mail = $_GET['mail'];
$query = "UPDATE pm SET new=old WHERE id='$mail'";
$result = mysql_query($query) or die(mysql_error());
?>
Help
Sorry if it sounds confusing it was kindof hard to write :s
Thanks
Eric
Posted: Tue Aug 02, 2005 6:58 pm
by Deemo
Code: Select all
$query = "UPDATE pm SET new='old' WHERE id='$mail'";
Posted: Tue Aug 02, 2005 7:21 pm
by ericburnard
thanks for that. i now have another thaught. i am wanting to display on my main page saying how many NEW emails the user has got. i dont have much of an idea of where to start on this one so i dont have much of a dtarting poit sorry :s
Any help would be great.
Thanks again
Eric
Posted: Tue Aug 02, 2005 7:35 pm
by shiznatix
dude seriously quickly remove your username and password for your mysql db that is a bad idea to post those in a script. put ****** inplace of them
Posted: Tue Aug 02, 2005 7:53 pm
by hansteam
Code: Select all
<?php
// Connecting, selecting database
mysql_connect('localhost', '****', '************')
or die('Could not connect: ' . mysql_error());
mysql_select_db('madashat_mail') or die('Could not select database');
$username = mysql_real_escape_string($_GET['user']);
$mail = $_GET['mail'];
$query = "SELECT * FROM pm WHERE username='username' AND new='old'";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
$i++;
}
echo "You have " . $i . " new messages";
?>
Posted: Tue Aug 02, 2005 7:58 pm
by feyd
the COUNT() aggregator works well to find how many were found.. a lot more efficient than doing a selection and just counting them manually..
Posted: Wed Aug 03, 2005 3:21 am
by CoderGoblin
Following on from feyd's comment... When using count rather than using
count(*) use count(fieldname) single field. For large tables this speeds things up considerably especially if the column is an indexed integer.
Code: Select all
SELECT COUNT(id) FROM pm WHERE username='username' AND new='old';
Posted: Wed Aug 03, 2005 5:28 am
by ericburnard
OK thanks for that. its now working good

. I now have another question (i think its pointless making lots of new topics when i can just use this one, Stops the board being filled with my problems :p).
i have my login script which uses the else funcltion. it checks the username and password and thenif they are incorrect it includes the login form so they can login again. if they are correct then it includes the members home page. what i am wanting it to do is send them to another pages after they have sucesfully logged in. how could i do that ??
i bet its really simple :S
Thanks
Eric
[EDIT] oh and also how can i disconnect from a database so that i can connect to another one without closing the php tags ?>
Posted: Wed Aug 03, 2005 5:45 am
by CoderGoblin
Relocation
header("Location: newlocation.php"); (Note no output prior to this allowed (not even a space).
Close
mysql_close
Posted: Wed Aug 03, 2005 6:38 am
by ericburnard
aggghhhh!!! :S i have just gone and delete my login script and only have my first copy as backup :S i have tried it and it only wants to throw back this error -
Code: Select all
Parse error: parse error, unexpected $ in /home/madashat/public_html/eric/login.php on line 25
this is my code, anybody know whats wrong with it????
Code: Select all
<?php
mysql_connect('localhost', '*******', '****')
or die('Could not connect: ' . mysql_error());
mysql_select_db('madashat_users') or die('Could not select database');
$username = $_POST['username'];
$password = $_POST['password'];
$query = "SELECT * FROM users WHERE username = '$username' AND password = '$password'";
$result = mysql_query($query);
if (mysql_numrows($result) != 1) {
$error = "Bad Login";
include "header.inc";
include "login.html";
} else {
header("Location: http://eric.madashatters.com/nm.php");
?>
<?
include('http://eric.madashatters.com/footer.inc');
?>
thanks again
Eric
Posted: Wed Aug 03, 2005 9:14 am
by timvw
you are not using mysql_real_escape_string and have a typo on mysql_num_rows
Posted: Wed Aug 03, 2005 5:09 pm
by feyd
*cough* un-ended code block..
Posted: Wed Aug 03, 2005 6:08 pm
by ericburnard
dam im stupid lol, i have just look through it before reading the replys and found loads of stuff wrong lol. Thanks for pointing them okt
thanks again
Eric