Portal Home > Knowledgebase > Articles Database > What the problem here? PHP CODE


What the problem here? PHP CODE




Posted by 3okl, 06-06-2009, 05:30 AM
this code to insert new week to Champion when the week id not found in the Champion. the problem now i can't insert new week i don't know why. i try many times to fix it but nothing changed. HTML CODE

Posted by Neseema M M, 06-06-2009, 06:40 AM
There is no form tag in the html code given. If POST method is used how can we get id in $_GET array? If you want to get the value in select box named 'week' use $_POST['week']. ie. $id = $_POST['week']; It is not clear from which field in the form we get the value of 'curr' used in the line if($_POST['curr']!=""){

Posted by bear, 06-06-2009, 06:45 AM
If that's your whole form for for submitting, where is the following var defined? Also, is the field really "Currant" (a type of berry), or is it supposed to be "Current"? (I was too slow submitting, and less thorough)

Posted by Shinary, 06-08-2009, 02:49 PM
BAD IDEA! Never fully trust your user input like that. In this case you are blindly taking data from $_GET is using it to run a database query. There would be nothing stopping a user from passing in something like: Don't let a Bobby Tables incident happen, make sure to always sanitize your data before it goes into your database. There are a number of built in functions in PHP to help with this.

Posted by ghostweb, 06-09-2009, 01:29 PM
To avoid a Bobby Drop Tables situation refer to: http://us3.php.net/mysql_real_escape_string

Posted by fiona_mei, 06-09-2009, 09:48 PM
erm... hello everyone.... i am new here.... n yet, i still looking around in this forum to seek for help.... can anyone help me with this?? SQLMale ERROR"); $male = mysql_num_rows($rsMale); ?> SQLFemale ERROR"); $female = mysql_num_rows($rsFemale); print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; ?> --> i'll get this error... --> Warning: mysql_query(): 3 is not a valid MySQL-Link resource in C:\Program Files\xampp\htdocs\my_project\member_inbenefit.php on line 58 anyone help me?? i am new to php as well..... =)
DivisionRaceMaleFemaleTotal

Posted by tim2718281, 06-09-2009, 09:52 PM
Which is line 58?

Posted by fiona_mei, 06-09-2009, 10:03 PM
ooo... i left tat out... -->$rsMale = mysql_query($SQLMale, $dbConn) or die("
SQLMale ERROR
");

Posted by fiona_mei, 06-09-2009, 10:09 PM
forgot to mention this as well... in my code as posted earlier... i want to count total of members in my organisation according o their gender and division... tq...

Posted by tim2718281, 06-09-2009, 11:26 PM
OK, so that's giving you the error message "3 is not a valid MySQL-Link resource". Have you looked up the documentation for mysql_query ? It's here: http://uk.php.net/mysql_query Presumably $dbConn is not being set correctly. So you need to look at the code that's issuing mysql_connect.

Posted by fiona_mei, 06-10-2009, 12:32 AM
i've been using that connection for others function... and it works well.... it just that when it comes to count function, it cannot work well.... =(

Posted by larwilliams, 06-10-2009, 12:42 AM
I think this is your problem: include ("connectdb.php"); include ("closedb.php"); I assume this has the affect of opening and closing the database connection immediately. Take "include ("closedb.php");" and move that to the end of your code EDIT: do not include the quotes above

Posted by rasin, 06-10-2009, 12:48 AM
there is a line in the code include ("closedb.php"); what it contains ? if it contains mysql_close() statement.. then you need to change this code 'include ("closedb.php");' to bottom of the program,because mysql didnt get the pointer after the mysql_close() statement

Posted by fiona_mei, 06-10-2009, 01:23 AM
rasin.... it contains mysql_close...

Posted by fiona_mei, 06-10-2009, 01:28 AM
guys.... i love u all.... =) i clear the error already.. but i didn't the output.... =|

Posted by Neseema M M, 06-10-2009, 02:02 AM
If you want to get the count of members u can give count function in sql query and take result. Or you can give select (*) in the query and take mysql_num_rows($result). If we are giving count function in query and return the number of rows it will be always 1.

Posted by fiona_mei, 06-10-2009, 04:03 AM
erm... since i am new.... i didn't get what u said... huhu.... sorry... can u xplain more...? =|

Posted by Neseema M M, 06-10-2009, 04:21 AM
Try below code instead of above: Or

Posted by fiona_mei, 06-10-2009, 08:25 PM
neseema.... i've tried the above code.... tq =) but i can't use this as i need to count how many members based on their gender n division... "$SQLFemale = "SELECT (*) FROM membership WHERE gender = 'Female' AND race = '$race' AND division = '$division'"; $rsFemale = mysql_query($SQLFemale, $dbConn) or die("
SQLFemale ERROR
"); $female = mysql_num_rows($rsFemale);" n i've tried the 2nd option u gave... tis error pop out... -->Warning: Wrong parameter count for mysql_num_rows() in C:\Program Files\xampp\htdocs\my_project\member_inbenefit.php on line 58 any other option? =|

Posted by Neseema M M, 06-11-2009, 12:33 AM
Sorry... there is no need of '()' around '*'. So remove that braces. Try like this:

Posted by fiona_mei, 06-11-2009, 02:19 AM
as far as i concern... select *from will retrieve all the data... not count the data.... is tat right?

Posted by Neseema M M, 06-11-2009, 02:47 AM
You will get the count of data using the function mysql_num_rows(). Or Make sure referer field exists in the db.

Posted by fiona_mei, 06-11-2009, 08:30 PM
Neseema... i am glad tat i learnt a lot from u... =) but.... i still can't get the ans.... huhu.....=|

Get Member In Benefit : Race : Division:

SQLMale ERROR"); $male = mysql_fetch_array($rsMale); $count = $male ['count(referer)']; echo "Count = ".$count; -->here's my complete code... is there any error??

Posted by larwilliams, 06-11-2009, 08:37 PM
Is all that code in one file? If so, it won't work. Put the HTML stuff in one file and the PHP code in a second file, and update the tag to call the second file: example:

Posted by fiona_mei, 06-11-2009, 10:07 PM
hmmm.... yeap... 1 file.... i oso do other function under 1 file... but it works well....

Posted by foobic, 06-11-2009, 11:05 PM
Apart from that, the code is wide open to SQL injection - it would be dangerous to open it to the public until you fix this. As a general rule, always sanitize user inputs as soon as you can. eg. If your "in_benefit" input can only take the values "A", "N" or "Y", you could use: (for extra brownie points, loop through the values in the array to create the select options)

Posted by fiona_mei, 06-12-2009, 02:37 AM
haha... am so happy.... i finally can count the members... without everyone help, i could have failed.... =) hehe..... erm.... then how can i display the data in the table? my table--> |division | race | male | female | total | can anyone help me? =)



Was this answer helpful?

Add to Favourites Add to Favourites    Print this Article Print this Article

Also Read