User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 402,681 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,272 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting

writitng data from php to mysql

Join Date: Jan 2007
Posts: 58
Reputation: crazynp is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 2
crazynp crazynp is offline Offline
Junior Poster in Training

Re: writitng data from php to mysql

  #3  
Mar 15th, 2007
does this work?

Originally Posted by sam1 View Post
hi,

it is giving me headache to write data from a php file to mysql( i can read from the table but cant write) here is my connect.php which connects to mysql:

<?php
$mysql_host = "localhost";
$mysql_user = "sam";
$mysql_pass = "123456";
$mysql_data = "website";
$mysql_table = "shoutbox";
mysql_connect($mysql_host,$mysql_user,$mysql_pass) or die("Couldnt connect, try again. " . mysql_error());
mysql_select_db($mysql_data) or die("Cannot select database! Please Try again." . mysql_error());
?>

here is the php file that should write it to table:

<html>
<head><title></title></head>
<body>
<?
include("connect.php");
 
if($_POST['process'] == 1){    
 
$name = $_POST['name'];
$url = $_POST['url'];
$message = $_POST['message'];
$date = date('jS \o\f F, Y \a\t g\:iA');
$ip = $_SERVER['REMOTE_ADDR'];
 
if (!$name || !$message) {
die ('You left a field blank. Please check again.');
}
else {
mysql_query("INSERT INTO shoutbox (id,ip,name,url,message,date) VALUES('','$ip','$name','$url','$message','$date')") or die('Error inserting into DB.');
}
}
?>
 
<form name="shout" method="post" action="process.php">
<div align="center"><iframe height="200" width="120" src="show.php" name="shoutbox"></iframe>
<br>
Name:<br>
<input name="name" type="text" size="15" style="border: solid 1px #000000; font: Verdana; font-size: 10px; background: #f8f8f8;">
<br>
URL:<br>
<input name="url" type="text" size="15" style="border: solid 1px #000000; font: Verdana; font-size: 10px; background: #f8f8f8;">
<br>
Message:<br>
<textarea name="message" cols="15" wrap="VIRTUAL" style="border: solid 1px #000000; font: Verdana; font-size: 10px; background: #f8f8f8;"></textarea>
<br>
<input type="hidden" name="process" value ="1" />
<input type="submit" name="Submit" value="Submit" style="border: solid 1px #000000; font: Verdana; font-size: 10px; background: #f8f8f8;">
</div></form>
</body>
</html>

can anyone please point out my mistake.

thank you
Reply With Quote  
All times are GMT -4. The time now is 4:43 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC