Ok :s

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
ericburnard
Forum Contributor
Posts: 104
Joined: Wed Jun 15, 2005 5:11 pm
Location: Chesterfield, UK

Ok :s

Post 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
Last edited by ericburnard on Tue Aug 02, 2005 7:37 pm, edited 1 time in total.
Deemo
Forum Contributor
Posts: 418
Joined: Sun Jan 18, 2004 11:48 am
Location: Washington DC

Post by Deemo »

Code: Select all

$query = "UPDATE pm SET new='old' WHERE id='$mail'";
User avatar
ericburnard
Forum Contributor
Posts: 104
Joined: Wed Jun 15, 2005 5:11 pm
Location: Chesterfield, UK

Post 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
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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
hansteam
Forum Newbie
Posts: 11
Joined: Tue Aug 02, 2005 2:52 pm
Location: Minnesota

Post 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";
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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..
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post 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';
User avatar
ericburnard
Forum Contributor
Posts: 104
Joined: Wed Jun 15, 2005 5:11 pm
Location: Chesterfield, UK

Post by ericburnard »

OK thanks for that. its now working good :D. 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 ?>
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

Relocation header("Location: newlocation.php"); (Note no output prior to this allowed (not even a space).

Close mysql_close
User avatar
ericburnard
Forum Contributor
Posts: 104
Joined: Wed Jun 15, 2005 5:11 pm
Location: Chesterfield, UK

Post 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
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

you are not using mysql_real_escape_string and have a typo on mysql_num_rows
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

*cough* un-ended code block..
User avatar
ericburnard
Forum Contributor
Posts: 104
Joined: Wed Jun 15, 2005 5:11 pm
Location: Chesterfield, UK

Post 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
Post Reply