Page 1 of 2
help with update profile script..
Posted: Tue Nov 25, 2003 10:36 am
by charmedp3
hi, i need help with this script..it takes very long to load and give this error
Fatal error: Maximum execution time of 30 seconds exceeded in /home/charmed/public_html/bhs2/edit.php on line 21
===============================================
$dbserver="127.0.0.1"; // Server to connect to, leave this unchanged
$dbuser="123"; // Username, change this to whatever you need
$dbpass="123"; // Same for pass
$db="123"; // Database name, u need to change this
// End settings
mysql_connect($dbserver,$dbuser,$dbpass);
$sql = "SELECT Username, Password, Email, Name, Age, hobbies FROM $db";
while ($row = mysql_fetch_array) {
$Username = $row['username'];
$Password = $row['password'];
$Email = $row['email'];
$Name = $row['name'];
$Age = $row['age'];
$hobbies = $row['hobbies'];
}
?>
<html>
<head>
<title>adad</title>
</head>
<body>
<form method="POST" ACTION="editpro.php">
<p>Username : <input type="text" NAME="username" VALUE ="<? echo "$username"; ?>" size=35 maxlength=50></p>
<p>Password : <input type="text" NAME="password" VALUE ="<? echo "$password"; ?>" size=35 maxlength=50></p>
<p>Email : <input type="text" NAME="email" VALUE ="<? echo "$email"; ?>" size=35 maxlength=50></p>
<p>Name : <input type="text" NAME="name" VALUE ="<? echo "$name"; ?>" size=35 maxlength=50></p>
<p>Age : <input type="text" NAME="age" VALUE ="<? echo "$age"; ?>" size=35 maxlength=50></p>
<p>Hobbies : <input type="text" NAME="hobbies" VALUE ="<? echo "$hobbies"; ?>" size=35 maxlength=50></p>
<br><br>
<input type="Submit" name="submit" VALUE="Update Profile"><br><br>
</form>
</body>
</html>
===============================================
EDITPRO.PHP
$dbserver="127.0.0.1"; // Server to connect to, leave this unchanged
$dbuser="charmed_bhs"; // Username, change this to whatever you need
$dbpass="bhs"; // Same for pass
$db="charmed_bhs"; // Database name, u need to change this
// End settings
mysql_connect($dbserver,$dbuser,$dbpass);
mysql_select_db($db);
$sql = "SELECT myuser, mypass, myemail, myname, myage, myhobbies FROM $db";
while ($row = mysql_fetch_array) {
$sql = "UPDATE $db SET
myuser = '$_POST[myuser]',
mypass = '$_POST[mypass]',
myemail = '$_POST[myemail]',
myname = '$_POST[myname]',
myage = '$_POST[myage]',
myhobbies = '$_POST[myhobbies]',
$result = @mysql_query($dbserver,$dbuser,$dbpass); or die(mysql_error());
?>
<html>
<head>
<title>adad</title>
</head>
<body>
<p>Username : <? echo "$_POST[myuser]"; ?></p>
<p>Password : <? echo "$_POST[mypass]"; ?></p>
<p>Email : <? echo "$_POST[myemail]"; ?></p>
<p>Name : <? echo "$_POST[myname]"; ?></p>
<p>Age : <? echo "$_POST[myage]"; ?></p>
<p>Hobbies : <? echo "$_POST[myhobbies]"; ?></p>
<br><br>
<input type="Submit" name="submit" VALUE="Update Profile"><br><br>
</body>
</html>
plz help
Posted: Tue Nov 25, 2003 11:01 am
by d3ad1ysp0rk
First off, enclose your code with [ php] [ /php] tags from now on (w/o spaces), it makes it easier to read.
Code: Select all
while ($row = mysql_fetch_array) {
$Username = $row['username'];
$Password = $row['password'];
$Email = $row['email'];
$Name = $row['name'];
$Age = $row['age'];
$hobbies = $row['hobbies'];
}
change to
Code: Select all
while ($row == mysql_fetch_array) {
$Username = $row['username'];
$Password = $row['password'];
$Email = $row['email'];
$Name = $row['name'];
$Age = $row['age'];
$hobbies = $row['hobbies'];
}
Posted: Tue Nov 25, 2003 11:04 am
by charmedp3
i got this error
Parse error: parse error in /home/charmed/public_html/bhs2/editpro.php on line 35
===============================================
editpro.php
// Global settings, please change these
$dbserver="127.0.0.1"; // Server to connect to, leave this unchanged
$dbuser="charmed_bhs"; // Username, change this to whatever you need
$dbpass="bhs"; // Same for pass
$db="charmed_bhs"; // Database name, u need to change this
// End settings
mysql_connect($dbserver,$dbuser,$dbpass);
mysql_select_db($db);
$sql = "SELECT myuser, mypass, myemail, myname, myage, myhobbies FROM $db";
while ($row = mysql_fetch_array) {
$sql = "UPDATE $db SET
myuser = '$_POST[myuser]',
mypass = '$_POST[mypass]',
myemail = '$_POST[myemail]',
myname = '$_POST[myname]',
myage = '$_POST[myage]',
myhobbies = '$_POST[myhobbies]',
$result = @mysql_query($dbserver,$dbuser,$dbpass); or die(mysql_error());
?>
<html>
<head>
<title>adad</title>
</head>
<body>
<p>Username : <? echo "$_POST[myuser]"; ?></p>
<p>Password : <? echo "$_POST[mypass]"; ?></p>
<p>Email : <? echo "$_POST[myemail]"; ?></p>
<p>Name : <? echo "$_POST[myname]"; ?></p>
<p>Age : <? echo "$_POST[myage]"; ?></p>
<p>Hobbies : <? echo "$_POST[myhobbies]"; ?></p>
<br><br>
<input type="Submit" name="submit" VALUE="Update Profile"><br><br>
</body>
</html>
Posted: Tue Nov 25, 2003 11:14 am
by infolock
Changed somethings in your code.
#1, you wasn't calling the query you wanted to fetch from, so i added that.
#2, you were trying to echo the variable word instead of it's value, so I removed the " 's that surrounded them. You may need to delete some of the comments i placed in it. I mainly did it like this to let you see where I changed something, and to give you an idea what was wrong with it.
Code: Select all
<?
############
## This is ok ##
######### #
$dbserver="127.0.0.1"; // Server to connect to, leave this unchanged
$dbuser="123"; // Username, change this to whatever you need
$dbpass="123"; // Same for pass
$db="123"; // Database name, u need to change this
// End settings
mysql_connect($dbserver,$dbuser,$dbpass);
$sql = "SELECT Username, Password, Email, Name, Age, hobbies FROM $db";
##################
## Problem starts here ##
#################
// you forgot to tell it what query to fetch from. so added $sql
while ($row = mysql_fetch_array($sql)) {
$Username = $row['username'];
$Password = $row['password'];
$Email = $row['email'];
$Name = $row['name'];
$Age = $row['age'];
$hobbies = $row['hobbies'];
}
?>
<html>
<head>
<title>adad</title>
</head>
<body>
#########################
## Chaned some of the code here ##
#########################
<form method="POST" ACTION="editpro.php">
<p>Username : <input type="text" NAME="username" VALUE ="
<? echo $username; // when calling variables, don't use " or ' marks in an echo statement...
?>" size=35 maxlength=50></p>
<p>Password : <input type="text" NAME="password" VALUE ="<? echo $password; ?>" size=35 maxlength=50></p>
<p>Email : <input type="text" NAME="email" VALUE ="<? echo $email; ?>" size=35 maxlength=50></p>
<p>Name : <input type="text" NAME="name" VALUE ="<? echo $name; ?>" size=35 maxlength=50></p>
<p>Age : <input type="text" NAME="age" VALUE ="<? echo $age; ?>" size=35 maxlength=50></p>
<p>Hobbies : <input type="text" NAME="hobbies" VALUE ="<? echo $hobbies; ?>" size=35 maxlength=50></p>
<br><br>
<input type="Submit" name="submit" VALUE="Update Profile"><br><br>
</form>
</body>
</html>
===============================================
EDITPRO.PHP
$dbserver="127.0.0.1"; // Server to connect to, leave this unchanged
$dbuser="charmed_bhs"; // Username, change this to whatever you need
$dbpass="bhs"; // Same for pass
$db="charmed_bhs"; // Database name, u need to change this
// End settings
mysql_connect($dbserver,$dbuser,$dbpass);
mysql_select_db($db);
$sql = "SELECT myuser, mypass, myemail, myname, myage, myhobbies FROM $db";
###########
## Problem ##
##########
// again, forgot to tell it where to fetch from, so added $sql
while ($row = mysql_fetch_array($sql)) {
$sql = "UPDATE $db SET
myuser = '$_POST[myuser]',
mypass = '$_POST[mypass]',
myemail = '$_POST[myemail]',
myname = '$_POST[myname]',
myage = '$_POST[myage]',
myhobbies = '$_POST[myhobbies]',
$result = @mysql_query($dbserver,$dbuser,$dbpass); or die(mysql_error());
?>
<html>
<head>
<title>adad</title>
</head>
<body>
<p>Username : <? echo $_POST[myuser]; ?></p>
<p>Password : <? echo $_POST[mypass]; ?></p>
<p>Email : <? echo $_POST[myemail]; ?></p>
<p>Name : <? echo $_POST[myname]; ?></p>
<p>Age : <? echo $_POST[myage]; ?></p>
<p>Hobbies : <? echo $_POST[myhobbies]; ?></p>
<br><br>
<input type="Submit" name="submit" VALUE="Update Profile"><br><br>
</body>
</html>
hope this helps.
Posted: Tue Nov 25, 2003 11:17 am
by charmedp3
now got this error
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/charmed/public_html/bhs2/edit.php on line 17
Posted: Tue Nov 25, 2003 11:21 am
by infolock
it's saying that this line :
Code: Select all
<?
$sql = "SELECT Username, Password, Email, Name, Age, hobbies FROM $db";
?>
is incorrect. Did you check your field names and make sure you are selecting the correct ones in your query? you can try adding an error control at the end of your query,a nd you can also try escaping out of the query to insert the variable like this :
Code: Select all
<?php
$sql = "SELECT Username, Password, Email, Name, Age, hobbies FROM ".$db."" or die(mysql_error());
?>
try that and see what happens.
edit : sorry, hope that helps, but i gotta go to class. i'll check back in about an hour and see how you are doing. if you have the same error but on a different line, try changing your second query like you did this one..
Posted: Tue Nov 25, 2003 11:29 am
by charmedp3
can you help me see wat variaable to put..coz my friend use alot different variable...
===============================================
register.php
// Global settings, please change these
$dbserver="127.0.0.1"; // Server to connect to, leave this unchanged
$dbuser="charmed_bhs"; // Username, change this to whatever you need
$dbpass="123"; // Same for pass
$db="charmed_bhs"; // Database name, u need to change this
// End settings
if($_POST['check']=="Register"){
mysql_connect($dbserver,$dbuser,$dbpass);
mysql_select_db($db);
$_SESSION['myuser']=$username;$_SESSION['mypass']=$password;$_SESSION['myemail']=$email;$_SESSION['myname']=$myname;$_SESSION['myage']=$age;$_SESSION['myhobbies']=$hobbies;
if (!$username) {echo "<font face=verdana size=2>You did not provide a username!<br></font>"; $signup="no";}
if (!$password) {echo "<font face=verdana size=2>You did not provide a password!<br></font>"; $signup="no";}
if (!$email) {echo "<font face=verdana size=2>You did not provide a email address!<br></font>"; $signup="no";}
if (!$name) {echo "<font face=verdana size=2>You did not enter your name!<br></font>"; $signup="no";}
if (!$age) {echo "<font face=verdana size=2>You did not enter your age!<br></font>"; $signup="no";}
if (!$hobbies) {echo "<font face=verdana size=2>You did not enter your hobbies!</font>"; $signup="no";}
if ($signup=="no"){echo "<font face=verdana size=2><br><br><--<a href=register.php>Go</a> back and try again</font>";}
else {
$query="SELECT * FROM users WHERE username='$username'";
$result=mysql_query($query); $num_rows = mysql_num_rows($result);
if ($num_rows!="0"){mysql_close(); echo "<br><center><font face=verdana size=2>User exists.<br><br>Please go [<a href=./register.php>back</a>] and try again</font></center>";}
else {
mysql_query("INSERT INTO users (Username,Password,Email,Name,Age,Sex,Hobbies) VALUES ( '$username','$password','$email','$name','$age','$sex','$hobbies')"); mysql_close();
echo "<br><br><center><font face=verdana size=2>Username '$username' has been successfully added to our member database.<br>Thank you for verifying as a member of BHS<br></font><br>";}}}
// Form code
else{
echo "<form action=register.php method=post><font face=verdana size=2>Username : </font><input type=text name=username value=$myuser><font face=verdana size=2><br>Password : </font><input type=password name=password value=$mypass><font face=verdana size=2><br>Email : </font><input type=text name=email value=$myemail><font face=verdana size=2><br>Name : </font><input type=text name=name value=$myname><font face=verdana size=2><br>Age : </font><input type=text name=age value=$myage><font face=verdana size=2><br>Sex : </font><select name=sex><option>Male</option><option>Female</option></select><font face=verdana size=2><br>Hobbies : </font><input type=text name=hobbies value=$myhobbies><br><br><input type=submit name=check value=Register><input type=reset value=Reset name=reset></form>";}
?>
===============================================
member.php
$dbserver="127.0.0.1"; // Server to connect to, leave this unchanged
$dbuser="charmed_bhs"; // Username, change this to whatever you need
$dbpass="123"; // Same for pass
$db="charmed_bhs"; // Database name, u need to change this
// End settings
mysql_connect($dbserver,$dbuser,$dbpass);
mysql_select_db($db);
$query="SELECT * FROM users"; $result=mysql_query($query);
$num_rows = mysql_num_rows($result);
for($i=0;$i<$num_rows;$i++){
$users[$i]=mysql_result($result, $i, "username");}
sort ($users);
reset ($users);
while (list ($key,$val) = each ($users)) {echo "<font face=verdana size=2><a href=view.php?user=$val>$val</a><br></font>";}
mysql_close();
?>
===============================================
view.php
$dbserver="127.0.0.1"; // Server to connect to, leave this unchanged
$dbuser="charmed_bhs"; // Username, change this to whatever you need
$dbpass="123"; // Same for pass
$db="charmed_bhs"; // Database name, u need to change this
// End settings
mysql_connect($dbserver,$dbuser,$dbpass);
mysql_select_db($db);
if (!$user) {echo "<br>No user specified<br><br>";}
else{
$query="SELECT * FROM users WHERE username='$user'"; $result=mysql_query($query);
$user=mysql_result($result, 0, "username"); echo "<br><b><center><font face=verdana size=2>Viewing Profile of $user</center><br></b>Username : $user<br></font>";
$email=mysql_result($result, 0, "email"); echo "<font face=verdana size=2>Email : <a href=mailto email>$email</a><br></font>";
$name=mysql_result($result, 0, "name"); echo "<font face=verdana size=2>Name : $name<br></font>";
$age=mysql_result($result, 0, "age"); echo "<font face=verdana size=2>Age : $age<br></font>";
$sex=mysql_result($result, 0, "sex"); echo "<font face=verdana size=2>Sex : $sex<br></font>";
$hobbies=mysql_result($result, 0, "hobbies"); echo "<font face=verdana size=2>Hobbies : $hobbies<p></font>";
mysql_close();
echo"<font face=verdana size=2><a href=member.php>Back to members page</a></font>";}
?>
===============================================
login.php
$dbserver="127.0.0.1"; // Server to connect to, leave this unchanged
$dbuser="charmed_bhs"; // Username, change this to whatever you need
$dbpass="123 // Same for pass
$db="charmed_bhs"; // Database name, u need to change this
// End settings
if($_POST['check']=="Login"){
if(!$_POST['username']) {echo "You did not enter a <b>username</b><br>"; $signup="no";}
if(!$_POST['password']) {echo "You did not enter a <b>password</b><br>"; $signup="no";}
if ($signup=="no"){echo "Please go [<a href=./login.php>back</a>] and try again";}
else{
mysql_connect($dbserver,$dbuser,$dbpass);
mysql_select_db($db);
$query="SELECT * FROM users WHERE password='$password' AND username='$username'";
$result=mysql_query($query); $num_rows = mysql_num_rows($result); mysql_close();
if ($num_rows!="0"){$_SESSION['username']=$_POST['username'];$_SESSION['password']=$_POST['password'];echo "<br><font face=verdana size=2><center>You are now login.<br><br> Click [<a href=index.php>here</a>] to continue.<br><bR>";}
else {echo "<br><center>Wrong username/password<br><br>Please go [<a href=./login.php>back</a>] and try again</font></center>";}}}
else {
echo "<br><form action=login.php method=post>
<font face=Verdana size=2>Username :<input type=text name=username>
Password :<input type=password name=password>
<input type=submit name=check value=Login><br><br></font>";}
?>
Posted: Tue Nov 25, 2003 12:52 pm
by vigge89
again, place the code inside [ php ] and [/ php ] !!!!

Posted: Tue Nov 25, 2003 9:27 pm
by charmedp3
wat u mean?
Posted: Wed Nov 26, 2003 6:03 am
by m3mn0n
Use this forum's php syntax highlighting feature.
If you are going to post code, make it easier for the people who help you by adding [syntax=php]before, and[/syntax] after a piece of code. Thanks.

Posted: Wed Nov 26, 2003 7:25 am
by charmedp3
can someone tell me wat error is this..how to solve it?
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/charmed/public_html/bhs2/edit.php on line 16
Posted: Wed Nov 26, 2003 7:37 am
by mchaggis
Your solution is easy...
Your original code:
Code: Select all
<?php
mysql_connect($dbserver,$dbuser,$dbpass);
mysql_select_db($db);
$sql = "SELECT myuser, mypass, myemail, myname, myage, myhobbies FROM $db";
while ($row = mysql_fetch_array) {
$sql = "UPDATE $db SET
myuser = '$_POST[myuser]',
mypass = '$_POST[mypass]',
myemail = '$_POST[myemail]',
myname = '$_POST[myname]',
myage = '$_POST[myage]',
myhobbies = '$_POST[myhobbies]',
$result = @mysql_query($dbserver,$dbuser,$dbpass); or die(mysql_error());
?>
In this I see several problems:
1) The following line would probably cause a database error as $db is your database name not a table
Code: Select all
$sql = "SELECT myuser, mypass, myemail, myname, myage, myhobbies FROM $db";
2) you never actually execute the sql statement, so you need
Code: Select all
$res = db_query($sql) or die(mysql_error());
3) The while line should then be something similar to
Code: Select all
while ($row = mysql_fetch_array($res)) {
You code though seems very confusing, but the above are issues and once corrected you should notice and improvement (maybe)
Posted: Wed Nov 26, 2003 7:43 am
by charmedp3
now i got this error
Fatal error: Call to undefined function: db_query() in /home/charmed/public_html/bhs2/edit.php on line 16
Posted: Wed Nov 26, 2003 7:43 am
by Weirdan
please read the manual:
[php_man]mysql_query[/php_man]
[php_man]mysql_fetch_array[/php_man]
And do not blindly follow Infolock's instructions, try to
understand what is going on in your code.
2Infolock:
look at this line:
Code: Select all
$sql = "SELECT Username, Password, Email, Name, Age, hobbies FROM ".$db."" or die(mysql_error());
says: assign string to variable or die. This assignment will always return
true. And you have to pass SQL query to [php_man]mysql_query[/php_man], not to [php_man]mysql_fetch_array[/php_man].
Posted: Wed Nov 26, 2003 10:21 am
by charmedp3
sorry. i am very very very new at php...can u code that for me?
i want a script to allow member to edit their profile.