Jump to content

How to print data into php from mysql


mark103

Recommended Posts

Hi guys,

 

I have a little problem here. I have stored the data in firstname column of mysql database. I am trying to achieve by print the data from the mysql and input the data on my php page, but the page is blank.

 

Here it is the code:

 

 

<?phpsession_start();    define('DB_HOST', 'localhost');    define('DB_USER', 'myusername');    define('DB_PASSWORD', 'mypassword');    define('DB_DATABASE', 'mydatabasename');           $errmsg_arr = array();    $errflag = false;    $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);    if(!$link) {  die('Failed to connect to server: ' . mysql_error());    }    $db = mysql_select_db(DB_DATABASE);    if(!$db) {  die("Unable to select database");    }   function clean($var){return mysql_real_escape_string(strip_tags($var));    }      $login = clean($_GET['user']);    $password = clean($_GET['pass']);    if($login == '') {  $errmsg_arr[] = 'Login ID missing';  $errflag = true;    }    if($password == '') {  $errmsg_arr[] = 'PASSWORD ID missing';  $errflag = true;    }    if($errflag) {  $_SESSION['ERRMSG_ARR'] = $errmsg_arr;  echo implode('<br />',$errmsg_arr);   }   else {  $qry="SELECT * FROM members WHERE login='$login' AND passwd='$password'";  $result=mysql_query($qry) or die('Error:<br />' . $qry . '<br />' . mysql_error());if(mysql_num_rows($result) > 0) {  $row = mysql_fetch_row($result);    $firstname = htmlspecialchars($author['firstname']);    echo("$firstname <br>");      }else {echo 'Username and/or Password not found.';}}?>

 

 

Do you know why the php page is blank as I effort to get the data from mysql??

 

Any idea??

Link to comment
Share on other sites

You're using mysql_fetch_row(), which returns an enumerated array, then you try to get a value from an array that doesn't exist ($author) , using an associative key, which also doesn't exist )( ['firstname'] ). You need to enable error reporting so you can see these things.

 

if(mysql_num_rows($result) > 0) {

  $row = mysql_fetch_row($result);
    $firstname = htmlspecialchars($author['firstname']);
    echo("$firstname <br>");
      }

Link to comment
Share on other sites

I didn't change anything. You need to read what I typed and figure it out on your own, or at least try to, and then post any changes you make.

 

I have tried everything I could do for and it is still have not print out the data from mysql onto php page.

 

That's why I need your advice. I am not sure how to print them out?

Link to comment
Share on other sites

However, I have tried this...

 

while ($firstname = mysql_fetch_array($firstname)) {
    $firstname = htmlspecialchars($author['firstname']);
    echo("$firstname <br>");
  }
}

 

Error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/myusername/public_html/mysite.com/testget.php on line 46

 

 

The error are jumping on this line:

 

while ($firstname = mysql_fetch_array($firstname)) {

 

 

I think I am nearly there, but something got to supplied the argument which it is not valid?

Link to comment
Share on other sites

Thanks for your help. How can I make separate for both data and make split for each line?

 

  $query  = "SELECT firstname, lastname FROM members WHERE login='$login' AND passwd='$password'";
  $result=mysql_query($query) or die('Error:<br />' . $qry . '<br />' . mysql_error());


while ($row = mysql_fetch_array($result)) { 
  echo $row['firstname']; // presumes there is a field named firstname
  echo $row['lastname']; // presumes there is a field named lastname
  }
}

 

As the code on above, it will make the both data to join it together. How can I make them goes separate and split for each line??

Link to comment
Share on other sites

echo $row['firstname'] . "<br>"; // presumes there is a field named firstname  echo $row['lastname']; // presumes there is a field named lastname

 

Thanks, but I am only getting the data from the firstname. I want to get both data of firstname and lastname from mysql and split for each line which it should be like this:

 

Myfirstname
Mylastname

Link to comment
Share on other sites

No offense intended, but since you evidently don't have even the most basic understanding of how things like code comments work, I'd suggest you read a book and familiarize yourself with php syntax before attempting to write scripts that integrate database operations, etc.

Link to comment
Share on other sites

No offense intended, but since you evidently don't have even the most basic understanding of how things like code comments work, I'd suggest you read a book and familiarize yourself with php syntax before attempting to write scripts that integrate database operations, etc.

 

Oi, you don't need to suggests people to GO AND READ a bloody book if they don't want to, so why make them?

God dare you to not to suggests or make people to do when they don't want to. I dare that you are the only person I have seen on this forum to seen to be very rude.

 

Apart from this, think I have found solution here. However, I cannot included the "" tags for the page.

 

Here it is the error I am getting:

 

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/myusername/public_html/mysite.com/testget.php on line 47

 

  echo "<p = "myfirstname">";
  echo $row['firstname'] . "</p>";

 

 

That is the last things I need an help before I will mark this thread as resolve. So please try and be nice, so my problem will be finish by in any time and in any seconds.

 

Thanks!

Link to comment
Share on other sites

As I stated, there was no offense intended. All I'm saying is the questions you've asked in this thread are things that you would have no problem figuring out on your own, in much less time, if you'd do some reading. This forum is a good resource for getting help, but it can't replace having the knowledge to be able to fix problems on your own when they happen.

Link to comment
Share on other sites

As I stated, there was no offense intended. All I'm saying is the questions you've asked in this thread are things that you would have no problem figuring out on your own, in much less time, if you'd do some reading. This forum is a good resource for getting help, but it can't replace having the knowledge to be able to fix problems on your own when they happen.

 

I disagreed with you, I'd find forum as much quicker than reading those bloody books which it will takes ages to find out the real problem. Forums can take up to few mins which it are much quicker in this way and people can learn from it. So why are you moaning at me that you wanted me to read books that I wouldn't need to?  I think you are being a fools to suggests people and make them to read books when they don't really want to and if they don't have to.

 

As this is a forum, people are suppose to help each other out rather than being nasty, either way, some people do read books and some don't read books. So why moan??  :confused:

 

Over the top of this, please can you help me as I am getting an parse error with unexpected T_STRING, expecting ',' or ';' in line 47 which I have already included them in my previous post??

Link to comment
Share on other sites

hmm, It seems my suspicion in another topic was pretty right. Mark103 please do understand that without even a basic knowledge of php, your value to a "helping each other forum" is that of a pure breed leech. Don't see that as an insult but as empiric data. I still am a complete noob comparing to most others here, but i do take time to read almost every topic because I find it fun to learn and in the end help other's with the knowledge I find here or read somewhere. Anyway, I don't want to force you to do anything, but i do like to advice to show effort. I am now repeating myself in a multi topic way. I hope I didn't insult anyone  ::)

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.