Need help with mySQL programming!

arod324

Golden Member
Jan 21, 2001
1,182
0
0
Okay, I've been working with php and mysql, and right now I CANNOT get this script to work. This is my "hours2.php page, and on the previous page, people would submit their student ID number.. which is the variable $id2.
I was able to get people to enter all of the information into the database, but I wanted for them to be able to look up their CAS hours ONLY if they typed in their student number, thus the script below. It has been giving me the "Warning: Supplied argument is not a valid MySQL result resource in /home/nguyenhv/public_html/hours2.php on line 18 error", which is the line that the "WHILE command starts on
Here is my script......
If you want to see my page, it's @ 216.173.213.132/~nguyenhv/cas.html ..... and hours.php
You can test the database by entering some info on the cas.html page, and then visiting the hours.php page.
<html>
<body>
<?
$student == $id2;

mysql_pconnect(&quot;localhost&quot;,&quot;nguyenhv&quot;,&quot;password&quot;) OR DIE
(&quot;Unable to connec to the SQL server&quot; .mysql_error());
mysql_select_db(&quot;nguyenhv&quot;);

if ($student == $id2)
{
$member = mysql_query(&quot;SELECT * FROM CAS WHERE ID='$student';&quot;) OR DIE
(&quot;Quack. You Screwed up:&quot;.mysql_error());
$data = mysql_fetch_array($member);
}
echo &quot;<table align=center border=1>&quot;;
echo &quot;<br>&quot;;
WHILE ($data=mysql_fetch_array($member)) {
echo &quot;<font color=black>&quot;
.&quot;<tr>&quot;
.&quot;<td>$data[Last]</td>&quot;
.&quot;<td>$data[First]</td>&quot;
.&quot;<td>$data[ID]</td>&quot;
.&quot;<td>$data[Hours]</td>&quot;
.&quot;<td>$data[Month]</td>&quot;
.&quot;<td>$data[Year]</td>&quot;
.&quot;<td>$data[Org]</td>&quot;;
}
echo &quot;</table>&quot;;

?>
</body>
</html>

If you guys could give me ANY help, it would be greatly appreciated.
Thanks,
arod324
 

RedRooster

Diamond Member
Sep 14, 2000
6,596
0
76
it seems like the id2 value isn't getting passed to the hours2.php page.
have you tried changing the form action on your cas.php page to be
hours2.php?id='$id'
or something like that.
that way, when the hours2.php page loads, student will get the id2 value assigned properly and then your query will work.
 

arod324

Golden Member
Jan 21, 2001
1,182
0
0
This is part of my cas.php page....
<form action=hours2.php method=post>
<input type=text size=4 maxlength=4 name=id2>
<br>
<input type=submit value=&quot;See your CAS hours&quot;>
How would you change this? Thanks for your input.
 

RedRooster

Diamond Member
Sep 14, 2000
6,596
0
76
change the line
<form action=hours2.php method=post>
to
<form action=hours2.php?id2='$id2' method=post>

if that doesn't work, take out the single quotes.

and on your hours2.php page, the very first line that says $student==$id2 maybe should only have one = sign, just so the assignment takes place. although I'm not sure why you make the assignment when the page is loaded and then run the if statement right after comparing the two, they're always going to be equal. but that doesn't matter, as long as it runs.
 

arod324

Golden Member
Jan 21, 2001
1,182
0
0
WHOOHOO, I just fixed it (I actually didn't try what you did). I was SOOO stuck on line 18, that I didn't look at the first couple lines... but when you mentioned that the $id2 variable wasn't working... I checked all the way at the top. I accidentally wrote &quot;$student==$id2&quot;... but when I changed it to &quot;$student=$id2,&quot; it worked!!!
Damn scripting and it's technicalities.
 

arod324

Golden Member
Jan 21, 2001
1,182
0
0
K, I have a new problem. It will not recognize the first set of values for each student number. So when I enter values for &quot;ID&quot; 123, the first value is always ignored (I can tell by looking at the database and see what is actually displayed.
 

RedRooster

Diamond Member
Sep 14, 2000
6,596
0
76
Hehe, I think I did mention trying to change that double = to a single. :)

Go through this second problem though and say what you're trying to do and what pages are involved. I'm not sure I understand.
I'll have a look and see what I can come up with.
 

arod324

Golden Member
Jan 21, 2001
1,182
0
0
Well, I read your first post, fixed it, and then read your second post :). Add a couple of names/ID's to the cas.html page. On the hours.php page, you will see the ENTIRE database with all of the numbers. On the hours2.php page, it will show only the number that you search for. The problem is, that on the hours2.php page, it will not show the first entry for each student number.
[edit] I am also having a problem with getting the date to work
here's a part of the script on cas.php
<?
$date=&quot;CURDATE()&quot;;

mysql_query(&quot;INSERT INTO CAS
(Last,First,StudentID,Hours,Month,Year,Org,Entrydate)
VALUES

('$last','$first','$number','$hours','$month','$year','$org','$date')&quot;)
OR DIE (&quot;query Failed: &quot;.mysql_error());
?>
The only thing that I am not sure about, is if the CURDATE() is the proper function to make it insert the current date...... (I got that function from www.mysql.com's tutorial thing)
 

RedRooster

Diamond Member
Sep 14, 2000
6,596
0
76
it would seem that the hours2.php page isn't showing ANY students if you search for anything other than NULL. the hours2.php page needs a value for id2 when it loads, or student won't get a value, and it turn the query won't work because it has no value to search for. That's why null works, but no other integer does.

as for the date, i think curdate is an sql funciton rather than a php function. try:
$date = date( &quot;Ymd&quot;, time() );
for your variable assignment. might work?
 

arod324

Golden Member
Jan 21, 2001
1,182
0
0
You can get stuff to display on the hours2.php page, if you go THROUGH the cas.php page and enter the number there. But I'm going to change it so that the link for the hours2.php page is somewhere else... since everytime you go to the cas.php page directly, it'll be null everything.
 

RedRooster

Diamond Member
Sep 14, 2000
6,596
0
76
I like how you have it now, by going to the hours2.php page from the see.php page.
What I would try if I were you, is in the see.php page, have the <form> tag within php and echo the form tag out so it can see php variables. Then, append the value of the id2 field to the hours2.php link on the form action.
So, something like:
<?
echo(&quot;<form action='hours2.php?id2=$id2' method=post>&quot;);
?>

so then, when you go to the hours2.php page after hitting the submit button, you wouldn't need the $student=$id2 assignment, or the IF statement even, you'd just to that SELECT query based on the value of $id2(passed in on the location bar from the previous page, which the php page will be able to see).
Is this any good?

Email me your see.php, hours.php, and hours2.php pages if you want, maybe by looking at the code I could figure out a different way of doing it as well.

Email