Help displaying select result from table

  • Thread starter Thread starter Anonymous
  • Start date Start date
A

Anonymous

Guest
hey there.. :help: needed here too. i think maybe i got the same problem as u do. im trying to retrieve data from the database and return in row after row in a table. however it always returns the mysql_fetch_array() error. im not sure what or where went wrong as im extremely new to php/mysql. think u could give me a hand on this?

here's the code that i used:
<?php
$select = mysql_query("SELECT * FROM 'user'", $cn1);
while($row = mysql_fetch_array($select, mysql_assoc))
{
$username = $row['username'];
$fullname = $row['fullname'];
$memberstatus = $row['memberstatus'];
echo "$username";

echo "$fullname";

echo "$memberstatus";

}

?>


here's my many thanks in advance!
 
Run the code again , get error , copy error from browser and paste it here.
I think u might get this error :

Warning: mysql_fetch_array(): The result type should be either MYSQL_NUM, MYSQL_ASSOC or MYSQL_BOTH. in
 
this is the error:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/signup/domains/online-signup.com/public_html/test/website/manageuser.php on line 120
 
The posibility is that your SQL statement is wrong.

Use this : $select = mysql_query("SELECT * FROM `user`", $cn1);

You have used this : $select = mysql_query("SELECT * FROM 'user'", $cn1);

Problem is single quote(') instead of backtick(`).
 
oh right. fixed that. :) overseen it. but it's okay to use them without any backticks yep?
 
roger that! have another problem.. :? inputting data from text fields to the database.. the data doesn't go into the database.. =/
 
viralupadhyaya said:
The posibility is that your SQL statement is wrong.

Use this : $select = mysql_query("SELECT * FROM `user`", $cn1);

You have used this : $select = mysql_query("SELECT * FROM 'user'", $cn1);

Problem is single quote(') instead of backtick(`).
viralupadhyaya is right, however both backtick or quotes are not necessary in this case.
 
Are you getting errors leen ?

Just use the method post in your form and than retrieve the input values throught the $_POST superglobl array.

Example:
Code:
<?php

if(isset($_POST['AddIt'])) {
     # trim() remove right/left spaces
     $name = trim($_POST['uname']);

     $result = mysql_query("INSERT INTO users SET username='{$name}'");
     print ($result) ? 'Done!' : 'Error!'; 
}
else {

# Let's show the form if there's no submittion

?>
<form name="f" method="post" action="<?php print $_SERVER['PHP_SELF']; ?>">
  <input type="text" name="uname" value="" />
  <input type="submit" name="AddIt" value="Add name">
</form>
<?php } ?>
 
oh wow. i need some time to digest those! im like a newborn with php & mysql. ahah.. so yea. rather slow. :oops:

and this is what i have:

<?php


if(isset($_GET['adduser']))
{

echo('User has been added successfully.');

$username = $_GET['username'];
$password = $_GET['password'];
$fullname = $_GET['fullname'];
$memberstatus = $_GET['memberstatus'];
$datacreated = $_GET['datacreated'];

$add_all = mysql_query("INSERT INTO user(username, password, fullname, memberstatus, datecreated) VALUES('$username','$password','$fullname','$memberstatus','$datecreated')");
mysql_query($add_all) or die(mysql_error());
}
else
{
echo ("Please try again.");
}
?>
 
you form method is get , i guessed , right???

submit html too. No prob in this code.
 
i tried the post method too.. but the data input via the text fields doesn't register into the database.. :(
 
What about errors ?
Also use error_reporting(E_ALL); at first in your code so you'll notified about every little error!
 
hmm.. something's still not quite right..

<?php if ($HTTP_POST_VARS["submit"] == "True") {
$error = '';
$username = $HTTP_SESSION_VARS['username'];

if(isset($_POST['adduser'])) {
#trim() remove right/left spaces
$username = $trim($_POST['username']);
$userpwd = $trim($_POST['userpwd']);
$fullname = $trim($_POST['fullname']);
$memberstatus = $trim($_POST['memberstatus']);
$datecreated = $trim($_POST['datecreated']);

$result = mysql_query("INSERT INTO users SET username='{$username}', userpwd='{$userpwd}', fullname='{$fullname}', memberstatus='{$memberstatus}', datecreated='{$datecreated}'");
$insertGoTo = "adduserconfirm.php";

header(sprintf("Location: %s", $insertGoTo));
}

else
{
$error = true;
}
}
}
?>
 
Back
Top