Current location: Hot Scripts Forums » Programming Languages » PHP » Can record arrays on database?


Can record arrays on database?

Reply
  #1 (permalink)  
Old 02-14-05, 10:11 AM
mhs12grade1992's Avatar
mhs12grade1992 mhs12grade1992 is offline
Newbie Coder
 
Join Date: Feb 2005
Location: USA
Posts: 84
Thanks: 0
Thanked 0 Times in 0 Posts
Can record arrays on database?

Is there any possible to record arrays on a database without creating table and inserting into the table? I won't have to use INSERT INTO, CREATE DATABASE, CREATE TABLE, SELECT * FROM, etc., won't I?

Like I want to save arrays in my database....
$name="MHS". How can I record it on database? I want it show $name on every page.

If I required to use those code above, then it won't work. Forget it.
INSERT INTO works, CREATE TABLE works and SELECT * FROM doesn't work.
SELECT won't show arrays at all.

Can you help?
__________________
Sincerely,
MHS (Mansfield High School)

Create your own short/long story within few minutes.
Simply fill out the form and it will write the story itself.

Go to: www.storymakerpro.com

Am I rich in million or just my 2 cents poor?
Reply With Quote
  #2 (permalink)  
Old 02-14-05, 10:49 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
Quote:
Is there any possible to record arrays on a database without creating table and inserting into the table?
you are actually asking to use a databse with out using a database!!?
well, this is a tough one..

you said you could insert and create, why can't you SELECT?
show us the SELECT query you used, we might be able to help..
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #3 (permalink)  
Old 02-14-05, 03:02 PM
mhs12grade1992's Avatar
mhs12grade1992 mhs12grade1992 is offline
Newbie Coder
 
Join Date: Feb 2005
Location: USA
Posts: 84
Thanks: 0
Thanked 0 Times in 0 Posts
I am making a guestbook using those code:
It's on view_guestbook01.php


<?php

define('DB_HOST','mysql');
define('DB_USER','idididididid');
define('DB_PASSWORD', '*********');
define('DB_NAME','guestbook');

@mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die('Unfortunately, your webmaster cannot connect to his database. '.mysql_error());
mysql_select_db(DB_NAME) or die('Cannot select dataname from the database. '.mysql_error());

$query1="SELECT user_id FROM guestbook WHERE user_id=11";
@mysql_query($query1) or die(mysql_error());
$over_ten="";
if (user_id>10) {$over_ten="ten";}



echo '<table cellpadding="0" cellspacing="0" border="0">';
echo '<tr><td valign="top">';
echo '<a href="view_guestbook01.php"><img hspace="1" vspace="1" border="0" src="button_home.jpg"></a>';
echo '</td><td valign="top">';
echo '<a href="view_guestbook01.php"><img hspace="1" vspace="1" border="0" src="button_back.jpg"></a>';
echo '</td><td valign="top">';
echo '<a href="view_guestbook02.php">';
if ($over_ten=="ten") {echo '<img hspace="1" vspace="1" border="0" src="button_next.jpg">';}
echo '</a>';
echo '</td><td valign="top">';
echo '<a href="post_guestbook.php"><img hspace="1" vspace="1" border="0" src="button_post.jpg"></a>';
echo '</td></tr>';
echo '</table>';




$query="SELECT name FROM guestbook WHERE user_id=1";
@mysql_query($query) or die(mysql_error());
if ($name!="")
{
echo 'Name: '.$_POST['name'];
echo '<br>';
}

$query="SELECT email FROM guestbook WHERE user_id=1";
@mysql_query($query) or die(mysql_error());
if ($email!="")
{
echo 'Email: <a href="mailto:'.$email.'">'.$email.'</a>';
echo '<br>';
}

$query="SELECT website FROM guestbook WHERE user_id=1";
@mysql_query($query) or die(mysql_error());
if ($website!="")
{
echo 'Website: <a href="http://'.$website.'">'.$website.'</a>';
echo '<br>';
}

$query="SELECT message FROM guestbook WHERE user_id=1";
@mysql_query($query) or die(mysql_error());
if ($message!="")
{
echo 'Message: '.$message;
}
echo '<br><br>';


@mysql_close();

?>
__________________
Sincerely,
MHS (Mansfield High School)

Create your own short/long story within few minutes.
Simply fill out the form and it will write the story itself.

Go to: www.storymakerpro.com

Am I rich in million or just my 2 cents poor?
Reply With Quote
  #4 (permalink)  
Old 02-15-05, 04:29 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
I'll tell you why it's not working!
you were doing all these mysql_query() but not once have fetched the results!
another thing, you didn't surround the user_id with quotes..
also, you are doing the same query over and over but just changing the field you are fetching!
use one query with all fields and then do your IFs..
try this one instead:
PHP Code:

<?php


define
('DB_HOST','mysql');
define('DB_USER','idididididid');
define('DB_PASSWORD''*********');
define('DB_NAME','guestbook');

@
mysql_connect(DB_HOSTDB_USERDB_PASSWORD) or die('Unfortunately, your webmaster cannot connect to his database. '.mysql_error());
mysql_select_db(DB_NAME) or die('Cannot select dataname from the database. '.mysql_error());

$query1 "SELECT * FROM guestbook WHERE user_id='11'";

$fetch mysql_query($query1)or
die(
mysql_error());

$row mysql_fetch_assoc($fetch);
extract($row);

if (
$user_id>10)
  
$over_ten 'ten';



echo 
'<table cellpadding="0" cellspacing="0" border="0">';
echo 
'<tr><td valign="top">';
echo 
'<a href="view_guestbook01.php"><img hspace="1" vspace="1" border="0" src="button_home.jpg"></a>';
echo 
'</td><td valign="top">';
echo 
'<a href="view_guestbook01.php"><img hspace="1" vspace="1" border="0" src="button_back.jpg"></a>';
echo 
'</td><td valign="top">';
echo 
'<a href="view_guestbook02.php">';

if (
$over_ten == 'ten')
   echo 
'<img hspace="1" vspace="1" border="0" src="button_next.jpg">';

echo 
'</a>';
echo 
'</td><td valign="top">';
echo 
'<a href="post_guestbook.php"><img hspace="1" vspace="1" border="0" src="button_post.jpg"></a>';
echo 
'</td></tr>';
echo 
'</table>';


if (
$name!='')
   echo 
"Name: $name<br />";

if (
$email!='')
   echo 
'Email: <a href="mailto:'.$email.'">'.$email.'</a><br />';

if (
$website!='')
   echo 
'Website: <a href="http://'.$website.'">'.$website.'</a><br />';

if (
$message!='')
   echo 
"Message: $message<br />";

echo 
'<br><br>';


@
mysql_close();
?>
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #5 (permalink)  
Old 02-15-05, 07:17 PM
mhs12grade1992's Avatar
mhs12grade1992 mhs12grade1992 is offline
Newbie Coder
 
Join Date: Feb 2005
Location: USA
Posts: 84
Thanks: 0
Thanked 0 Times in 0 Posts
Oh thanks. That big help.
__________________
Sincerely,
MHS (Mansfield High School)

Create your own short/long story within few minutes.
Simply fill out the form and it will write the story itself.

Go to: www.storymakerpro.com

Am I rich in million or just my 2 cents poor?
Reply With Quote
  #6 (permalink)  
Old 02-17-05, 11:20 AM
mhs12grade1992's Avatar
mhs12grade1992 mhs12grade1992 is offline
Newbie Coder
 
Join Date: Feb 2005
Location: USA
Posts: 84
Thanks: 0
Thanked 0 Times in 0 Posts
Well, I read through some pages in the book about mysql_fetch_array() and mysql_num_rows() and $column[0].
I understand how SELECT works. In order to show it on guestbook, I have to use the codes......

$fetch=mysql_fetch_array($query, MYSQL_NUM);
That is the only one I can see from SELECT by using the fetch code above.
__________________
Sincerely,
MHS (Mansfield High School)

Create your own short/long story within few minutes.
Simply fill out the form and it will write the story itself.

Go to: www.storymakerpro.com

Am I rich in million or just my 2 cents poor?
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Form to update a MySQL database? Scoobler PHP 9 09-04-08 01:41 AM
Can't Retrieve New Record Database mathieu67 PHP 2 09-27-04 04:24 PM
PHP/MySQL Web Database Programmer Needed - PAID richardhay Job Offers & Assistance 3 07-16-04 02:21 PM
i have a problem regarding updating database online GENIUSAdnan PHP 1 06-23-04 03:53 AM


All times are GMT -5. The time now is 05:30 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.