![]() |
|
|
|
|
|||||||
| PHP / MySQL Assistance We understand. Not all of you are experienced programmers, but some of you are highly skilled at coding. So we've set aside this forum so you can ask questions, and provide answers to the most commonly asked PHP / MySQL issues. |
![]() |
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi,
I'm having a problem using PHP in conjunction with MySQL. This is what I've done: 1. Created a MySQL database using cPanels 2. Created a table and inserted 3 data records into it using phpmyadmin 3. Wrote a PHP script to print out the data I entered in step #2. It worked with no problem 4. Added on to the end of that script some code to insert one more data record. That appeared to work well until I added more code to the script to print out the newly updated database. This showed that it really didn't get updated. NOTE: I did the same thing on my godaddy account and the exact same thing happened so I suspect its something very simple I am doing wrong. Here's the code and output when I ran it: I also tried to create a table in a PHP script. It appeared to work well until I went to cPanels only to find the table not there. //Connect To Database $hostname='localhost'; $username='familyon_john'; $password='pasword'; $dbname='familyon_blog'; $usertable='your_tablename'; $yourfield = 'your_field'; mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to MySQL! Please try again later.'); echo "Connected to MySQL "; mysql_select_db($dbname)OR DIE ('Unable to connect to database! Please try again later.');; echo "Connected to Database "; // Print out the database $query = "SELECT * FROM comments"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo $row['date']. " - ". $row['name']. " - ". $row['email']. " - ". $row['url']. " - ". $row['comment']; echo " "; } // Attempt to insert something into database $query="INSERT INTO `familyon_blog`.`comments` ( `day` , `name` , `email` , `url` , `comment` ) VALUES ( '2007-11-21', 'Katrina', 'kjlkdf@gmila.com', 'this.com', 'this is a katrina')"or die(mysql_error()); echo "Data Entered!"; // Print out the database $query = "SELECT * FROM comments"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo $row['date']. " - ". $row['name']. " - ". $row['email']. " - ". $row['url']. " - ". $row['comment']; echo " "; } ?> OUTPUT: Connected to MySQL Connected to Database - John Vogel - sdfs@jkl .com - asdfsa@com - This is a test from John - Nancy Vogel - sathren@t.com - jksldj.com - This is from Nancy - David Vogel - sldkfj@dsk.com - dlkj.com - This is from David Data Entered! - John Vogel - sdfs@jkl .com - asdfsa@com - This is a test from John - Nancy Vogel - sathren@t.com - jksldj.com - This is from Nancy - David Vogel - sldkfj@dsk.com - dlkj.com - This is from David Last edited by familyon; 11-13-2007 at 05:50 PM. Reason: code was left out |
|
#2
|
||||
|
||||
|
I'm not programmer. However, you may want to check that you have the right permissions on the database by going to >> cPanel >> MySQL >> changing the permissions to "All Permissions" then you should be set. Otherwise, you need to look at the code (I don't know PHP, or I'd help).
__________________
Thanks, Denis Motova Affiliate / Operations Manager HostICan Answers | Become a HostICan Affiliate | Create a Support Ticket. |
|
#3
|
|||
|
|||
|
Thanks Denis,
I checked the permissions and I had all the possible permissions. I'll keep trying. |
|
#4
|
||||
|
||||
|
The problem is that you never ran your INSERT query.
The result is that you didn't insert the record and didn't receive an error message. You just need to modify your code to run the INSERT query and you should be set. Change this part: Code:
// Attempt to insert something into database $query="INSERT INTO `familyon_blog`.`comments` ( `day` , `name` , `email` , `url` , `comment` ) VALUES ( '2007-11-21', 'Katrina', 'kjlkdf@gmila.com', 'this.com', 'this is a katrina')"or die(mysql_error()); echo "Data Entered!"; Code:
// Attempt to insert something into database $query="INSERT INTO `familyon_blog`.`comments` ( `day` , `name` , `email` , `url` , `comment` ) VALUES ( '2007-11-21', 'Katrina', 'kjlkdf@gmila.com', 'this.com', 'this is a katrina')"; $result = mysql_query($query) or die(mysql_error()); echo "Data Entered!"; Code:
$query="INSERT INTO `familyon_blog`.`comments` ( `day` , `name` , `email` , `url` , `comment` ) VALUES ( '2007-11-21', 'Katrina', 'kjlkdf@gmila.com', 'this.com', 'this is a katrina')"or die(mysql_error()); echo "Data Entered!"; Code:
$query="INSERT INTO comments ( day, name, email, url, comment) VALUES ( '2007-11-21', 'Katrina', 'kjlkdf@gmila.com', 'this.com', 'this is a katrina')";
|
|
#5
|
||||
|
||||
|
itwasntme - you're a star! - Hopefully this will resolve that users problem
Keep up the excellent work!
__________________
Thanks, Denis Motova Affiliate / Operations Manager HostICan Answers | Become a HostICan Affiliate | Create a Support Ticket. |
|
#6
|
||||
|
||||
|
Thanks, Denis. I'm just trying to give back a little for all the help I have received here.
|
![]() |
| Tags |
| php or mysql, problems |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Again problems receiving outside list server web based e-mails | patthronson | Shared Hosting | 4 | 09-08-2008 01:45 PM |
| Problems Installing JDK | aarellano | Virtual Private Servers (VPS) | 4 | 08-07-2008 02:05 PM |
| Subdomain problems | sweetsweden | Shared Hosting | 1 | 05-10-2008 11:17 AM |
| Problems with uploaded pages | smartecosse | Shared Hosting | 5 | 03-08-2008 04:15 PM |
| Mail problems caused by invalid reverse DNS? | bkark | Virtual Private Servers (VPS) | 33 | 12-15-2007 01:15 PM |