Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 07-17-2002, 08:12 PM   #1 (permalink)
Geetazz
Registered User
 
Join Date: Jun 2002
Posts: 12
Geetazz is on a distinguished road
Send a message via AIM to Geetazz
Lightbulb A Couple PHP & MySQL Questions

The first question I have is what is wrong with this script. This is my first one so there may be a lot of problems.

PHP Code:
<?php
/*program: myaccount.php
Desc: Allows users to see and update there information.
*/
?>
<html><head></head><body>
<enter>My Account</enter><p> This is where you see and update your information. If you don't see a star next to information it means you can't change this. Here is your information.<p>
$dbhost="localhost";
$dbuser="username";
$dbpass="password";
$dbname="name";

function dbConnect($db="") {
    global $dbhost, $dbuser, $dbpass;
    
    $dbcnx = @mysql_connect($dbhost, $dbuser, $dbpass)
        or die("The site database appears to be down.");

    if ($db!="" and !@mysql_select_db($db))
        die("The site database is unavailable.");
    
    return $dbcnx;
}
<?php
$query
="SELECT username, kennel, dspoints, job, email FROM member echo " Your Username is $username<br>
*
Your kennel name is $kennel <br>
You have $dspoints <br>Your job is $job <br>*Your email is $email <p><p>
"Here you can change the information that has star<p>
<from action="
checkall.php method=
'past'>
<
table border="0" width="100%">
Kennel  Name <input type='text' name='kennel'
size='25' maxlength='25' value='$kennel'>
<
p>Email<input type'text' name='email'
size='25'=maxlength='25' value='$kennel'> <p>Email<input type='text' name='email' size='25' maxlength='25' value='$email'> { if (!ereg("^.+@.\\..+$",$email));
$result mysql_query($query)
or die (
"couldn't execute query.");
echo 
"member info has been updated<br>";
}
?>
-----------------------------------------------------------------------------------
The second problem I have is making my auction script. I will just go step by step on what is going to happen and what I need.

1. I am going to put the images that is up for auction in a table.

2 Below the table it is going to have the highest bid for the item and the time left to bid. If you click on the picture it takes you to a page with more infomation: like highest bidder, who put this up for auction, and a form to bid.

I would like to make it where if the time is up it say auction for this item is over. I would also like to make it so that the highest bidder for an item can not bid until someone bids higher than them. Also, I would like them to only be allowed to bid how many points they have, not higher. They have points when they join. (I call the points dspoints)

I don't need a script for all of this I just need to know how can I do this. I just need to know what functions, variables, or whatever I need.
-----------------------------------------------------------------------------------
My last problem is decreasing numbers. I want to have the number of items left on the site(like number of apples left). Then when someone clicks on a item and fills out a form the number of items will decrease.

I know it is a lot but I would greatly appreciate the help!
Geetazz is offline   Reply With Quote
Old 07-18-2002, 02:03 AM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,710
redhead is on a distinguished road
Re: A Couple PHP & MySQL Questions

Quote:
Originally posted by Geetazz
The first question I have is what is wrong with this script. This is my first one so there may be a lot of problems.

PHP Code:
<?php
/*program: myaccount.php
Desc: Allows users to see and update there information.
*/
?>
{1}-Remove the ?> here, and put in a echo " then go to {2a} Else go to {2b}
Quote:
PHP Code:
<html><head></head><body>
<
enter>My Account</enter><pThis is where you see and update your information. If you don't see a star next to information it means you can't change thisHere is your information.<p
{2a}-If {1} was chosen, put in a "; here and go to {3}
{2b}- put in a <?php here and go to {3}
Quote:
PHP Code:
$dbhost="localhost";
$dbuser="username";
$dbpass="password";
$dbname="name";

function 
dbConnect($db="") {
    global 
$dbhost$dbuser$dbpass;
    
    
$dbcnx = @mysql_connect($dbhost$dbuser$dbpass)
        or die(
"The site database appears to be down.");

    if (
$db!="" and !@mysql_select_db($db))
        die(
"The site database is unavailable.");
    

    return 
$dbcnx;

{3}-Delete the <?php
Quote:
PHP Code:
<?php
$query
="SELECT username, kennel, dspoints, job, email FROM member
there needs some form of ending the $query with a "; in the end.
Quote:
PHP Code:
echo " Your Username is $username<br>
*Your kennel name is $kennel <br>
You have $dspoints <br>Your job is $job <br>*Your email is $email <p><p>
"
Here you can change the information that has star<p>
<
from action="checkall.php method=
'past'>
<table border="
0" width="100%">
Kennel  Name <input type='text' name='kennel'
size='25' maxlength='25' value='$kennel'>
<p>Email<input type= 'text' name='email'
size='25'=maxlength='25' value='$kennel'> <p>Email<input type='text' name='email' size='25' maxlength='25' value='$email'> { if (!ereg("
^.+@...+$",$email));
$result = mysql_query($query)
or die ("
couldnt execute query.");
echo "
member info has been updated<br>";
}
?> 
That last part here, realy needs a look through.. all the intended " that should be for ie: border="0" needs to be escaped, ie: \" else they will have effect on the string which echo is trying to echo to your browser.

Plus the mysql_query neds to be executed befor the refference to $kenel, $email etc. plus you need to use a form of: $rows=mysql_fetch_array($result) and then, when using the $kenel etc in the text, fetch it like: $rows->KENEL or $rows[kenel]

Quote:
-----------------------------------------------------------------------------------
The second problem I have is making my auction script. I will just go step by step on what is going to happen and what I need.

1. I am going to put the images that is up for auction in a table.
have a img_link_item in the table assigned to the current Item, if it's NULL display, No current Image for this item as a link to the info page, if there is something assigned to it, use <img src='$img_link_item'> as the link.
Quote:
2 Below the table it is going to have the highest bid for the item and the time left to bid. If you click on the picture it takes you to a page with more infomation: like highest bidder, who put this up for auction, and a form to bid.
$result=mysql_query("SELECT * FROM items_bid WHERE item_id='$some_id' ORDER BY bids DESC LIMIT 0,2");
selects the two highest bids.
For the time thing, use some form of unix timestamp for the expirering date, then do a if (time() > $expire_stamp){ echo "Sorry no more bids";}
Quote:
I would like to make it where if the time is up it say auction for this item is over. I would also like to make it so that the highest bidder for an item can not bid until someone bids higher than them. Also, I would like them to only be allowed to bid how many points they have, not higher. They have points when they join. (I call the points dspoints)
Store the $USER_ID along with the bids, then in the link, parse the $USER_ID assigned to the highest bid to the "yes make your bid" page, and here have a small check: if($url_user_id == $current_user_id){ echo "Sorry you allready have the highest bid, you're not allowed any more bids at this point";}
Quote:
I don't need a script for all of this I just need to know how can I do this. I just need to know what functions, variables, or whatever I need.
Thank you.... I wasn't sure, when I started to answer, and frankly I thought it was gonna be a HUGE reply if I should come up with the solutions to these..
Quote:
-----------------------------------------------------------------------------------
My last problem is decreasing numbers. I want to have the number of items left on the site(like number of apples left). Then when someone clicks on a item and fills out a form the number of items will decrease.
$size=mysql_num_rows($result);
echo "Currently serving $size items";

Quote:
I know it is a lot but I would greatly appreciate the help!
Well atleast this is my review... I guess mmilano can give some more info.. I don't have the time at this point.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is online now   Reply With Quote
Old 07-18-2002, 09:23 AM   #3 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,487
sde is on a distinguished road
wow, .. a marathon reply =) redhead went through more than i would.

you are closing your php tag under the comments near the top, yet you continue to use php.

that is the most obvious error. if you're gonna post questions on your php code, it makes it a lot easier for us if you post the error you get.

learning how to debug is a must. take it 1 line at a time. when you excecute that script, you will probably get an error on the screen.

first, .. find the line where the error is, .. and examine that line, and all surrounding lines.

if you can't figure it out and want someones help in any forum, do them a favor and post ONLY that area of code you ar currently working on with the error and also post the error that php generates.

after you fix that area of code, repeat the dubugging steps above. it will be less confusing for you and us both. it's so much easier to answer 1 question at a time.

please don't let this deter you from posting .. i hope you will post more questions.. just remember you can get more precise answers with more precise questions.

ooh, i think i feel a "how to ask" sticky post comming on =)

take care, hope to see some more posts soon
sde is offline   Reply With Quote
Old 07-18-2002, 10:42 AM   #4 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,710
redhead is on a distinguished road
Quote:
Originally posted by mmilano
wow, .. a marathon reply =) redhead went through more than i would.
Well, once I got started I couldn't see how to get out of it, without going through it all..
Quote:

ooh, i think i feel a "how to ask" sticky post comming on =)
There allready is one: http://www.tuxedo.org/~esr/faqs/smart-questions.html

--edit--
Forgot one simple instruction.. "If you dont recieve an answer, then either the bug is too obvius, or it's too difficult."

But Geetazz, fell free to ask, as you can see we like to answer questions here And remember: "The only stupid question, is the unasked question."
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001

Last edited by redhead; 07-18-2002 at 10:51 AM.
redhead is online now   Reply With Quote
Old 07-18-2002, 03:00 PM   #5 (permalink)
Geetazz
Registered User
 
Join Date: Jun 2002
Posts: 12
Geetazz is on a distinguished road
Send a message via AIM to Geetazz
I appreciate the help!!

I am sorry for posting the whole script. I had an error in the beginning of the script and I could not fix it. Then when I took it out I had another and another thing wrong with it. I did not want to bother anyone with ten different post. So I posted the whole script. But I know for the future to try and be more specific. I really really appreciate the help from both of you. I am glad that redhead took the time to do all of that. I am also glad that mmilano explain to me what I was doing wrong instead of banning me from posting. THANKS!!!!!

P.S. Do codenewbie have a smaller banner? Because when I open up my site there will be a page to thank you and I would like to put the banner up. The banner will also be on my main page. If you do please either post the url for the graphic here or email me at geetazz@aol.com with it.

Thanks again!!!
Greg
Geetazz is offline   Reply With Quote
Old 07-19-2002, 07:28 AM   #6 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,487
sde is on a distinguished road
cool, i'll make a banner and post it here =)

don't feel bad if you make a bunch of posts .. besides making it easier to answer, it will make it easier for others who are searching the threads for similar answers .

thanks getazz .. did you get it working?
sde is offline   Reply With Quote
Old 07-19-2002, 04:31 PM   #7 (permalink)
Geetazz
Registered User
 
Join Date: Jun 2002
Posts: 12
Geetazz is on a distinguished road
Send a message via AIM to Geetazz
One little problem with the script

I only had a chance to try the myaccount script because I could not get it to work. This is what I have and the error says phase error on line 22. Which is where I have query. Did I put the stuff that redhead said to put at the end in the wrong place?

PHP Code:
$query "SELECT username, kennel, dspoints, job, email FROM member/"
$rows=mysql_fetch_array($result)
$rows[usernamekenneldspointsjobemail]
echo 

$result = mysql_query($query) ;
Your Username is $username<br>*Your kennel name is $kennel <br>
You have $dspoints<br>Your job is $job <br>*Your email is $email <p><p>"
Here you can change the information that has star<p
<
form action="checkall.php method= 'past'> 
Kennel Name <input type='text' name='kennel' 
size='25' maxlength='25' value='$kennel'> 
<p>Email<input type= 'text' name='email' 
size='25'=maxlength='25' value='$kennel'> <p>Email<input type='text' name='email' size='25' maxlength='25' value='$email'> { if (!ereg("
^.+@...+$",$email)); 
or die ("
couldnt execute query."); 
echo "
member info has been updated<br>"; 

?> 
I hope I post this question right.

Last edited by Geetazz; 07-19-2002 at 04:38 PM.
Geetazz is offline   Reply With Quote
Old 07-20-2002, 01:00 AM   #8 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,710
redhead is on a distinguished road
Re: One little problem with the script

Quote:
Originally posted by Geetazz
I only had a chance to try the myaccount script because I could not get it to work. This is what I have and the error says phase error on line 22. Which is where I have query. Did I put the stuff that redhead said to put at the end in the wrong place?

PHP Code:
$query "SELECT username, kennel, dspoints, job, email FROM member/"
$rows=mysql_fetch_array($result)
$rows[usernamekenneldspointsjobemail]
echo 

$result = mysql_query($query) ; 
Ok, this last part is just plain wrong.. (Is it a typo with the / after "member" ? )
Remove the $rows[username,kennel,dspoints,job,email]
and place the $result=mysqlquery($query); outside the echo " part.
Quote:
PHP Code:
Your Username is $username<br>*Your kennel name is $kennel <br
Here you use it like:
Your Username is $row[username]<br>*Your kennel name is $row[kennel]<br> That was how I ment for you to use either the $row[identifyer] or $row->IDENTIFYER Same goes for the rest of the refferences in the page.
Quote:
PHP Code:
You have $dspoints<br>Your job is $job <br>*Your email is $email <p><p>"
Here you can change the information that has star<p> 
<form action="
checkall.php method'past'
Why is there a " infront of checkall.php ?? There are still some missplaced " in this part, that will confuse echo
Quote:
PHP Code:
Kennel Name <input type='text' name='kennel' 
size='25' maxlength='25' value='$kennel'
<
p>Email<input type'text' name='email' 
size='25'=maxlength='25' value='$kennel'> <p>Email<input type='text' name='email' size='25' maxlength='25' value='$email'> { if (!ereg("^.+@.\..+$\",$email)); 
or die ("
couldnt execute query."); 
echo "
member info has been updated<br>"; 

?> 
Why are you using a if(!ereg()) statement within your echo string ? And where is the closing "; to indicate theres no more for echo to display ? And how come most of the closing " escaped ?
I usualy use ' for every intended " that is used for settings and the like, and try _not_ to use too many " in my text. If I need to use it, then I make sure its escaped.

I would move the if(!ereg()) up just befor the echo starts, and use $row[email] in the test condition.. That way you would've made sure all the conditions are met, befor trying to display anything.

Any way, since the $query parsed to mysql_query() is only a fetching request, I very much doubt that the echo "member info has been updated<br>"; statement will be true.
But happy hacking
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is online now   Reply With Quote
Old 07-22-2002, 09:16 PM   #9 (permalink)
Geetazz
Registered User
 
Join Date: Jun 2002
Posts: 12
Geetazz is on a distinguished road
Send a message via AIM to Geetazz
little confused about email stuff

PHP Code:
$query "SELECT username, kennel, dspoints, 
job, email FROM member"

$rows mysql_fetch_array($result);
$result mysql_query($query);
if(!
ereg("^.+@...+$",$email));
echo 
"Your username is $row[username]<br>
*Your kennel name is $row[kennel]<br>
You have $row[dspoints]<br>
Your job is $row[job]<br>
*Your email is $row[email]<p>"

I have changed this part about 15 times and the only thing that don't work is the stuff to do with email. Where it says your email is there is a problem. But whenever I change that there is something wrong with the if() thing.
Geetazz is offline   Reply With Quote
Old 07-23-2002, 05:52 AM   #10 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,487
sde is on a distinguished road
i think there there are to lines that are out of order:

PHP Code:
$result mysql_query($query);
$rows mysql_fetch_array($result); 
try that .. $result is the query .. that should happen first, .. then fetch the rows of the query after.
sde is offline   Reply With Quote
Old 07-23-2002, 06:56 AM   #11 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,710
redhead is on a distinguished road
Re: little confused about email stuff

Quote:
Originally posted by Geetazz
PHP Code:
if(!ereg("^.+@...+$",$email)); 
You have a ; after the if condition, meaning if (true) do ; meaning theres not realy an action if the condition in the if statement should be true.

And what mmilano said is to be done.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is online now   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
HTML form preview then INSERT using PHP & MySQL SteveSoler PHP 13 08-27-2008 10:47 PM
Simple PHP MySQL code: confused. easilyi Everything SQL ( MySQL, MSSQL, DB2, Postgre, Oracle, etc...) 4 10-24-2004 07:53 PM
cant connect to mysql databases using php eran PHP 11 08-07-2004 08:02 AM
csv file to mysql using php jayteema PHP 10 07-02-2004 11:20 AM
Help with setting up mySQL and PHP Ilya020 PH