Jump to content

Recommended Posts

i need help i have a very basic script that i need help with it basically has a form that saves data to a mysql db and then displlays the data on another page. very simple but it wont submit all the data im asking it to.. the code is below dont laugh at me im a php n00b.

 

MYSQL CODE:

 

CREATE TABLE `clients` (
  `id` int(4) NOT NULL auto_increment,
  `name` varchar(65) NOT NULL default '',
  `email` varchar(65) NOT NULL default '',
  `phone` varchar(65) NOT NULL default '',
  `website` varchar(65) NOT NULL default '',
  `comment` longtext NOT NULL,
  `datetime` varchar(65) NOT NULL default '',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;

PHP CODE:

 

<?php
$host=""; // Host name 
$username=""; // Mysql username 
$password=""; // Mysql password 
$db_name=""; // Database name 
$tbl_name=""; // Table name 

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect server "); 
mysql_select_db("$db_name")or die("cannot select DB");

$datetime=date("y-m-d h:i:s"); //date time

$sql="INSERT INTO $tbl_name(name, email, comment, datetime)VALUES('$name', '$email', '$comment', '$datetime')";
$result=mysql_query($sql);

//check if query successful 
if($result){
echo "Client Added Successfully!";
echo "<BR>";
echo "<a href='clients.php'>View Clients</a>"; // link to view guestbook page 
}

else {
echo "ERROR";
}

mysql_close();
?>

 

above is the php that submits the data from a html form... but every time i submit data it doesnt have any errors it seems to work but the data doesnt get sent to the database. to see what im talking about look here >>> http://www.jswebmedia.com.au/admin/clients.php l

ook at ID 2 the id works and date works but other data is blank. ID 1 i added manually through the database.

 

please help!!! im sure its something small ... the whole script has 3 php pages reply if u need to know any of the other code.

Link to comment
https://forums.phpfreaks.com/topic/52301-solved-n33d-help-im-stuck/
Share on other sites

If No then

 

$sql="INSERT INTO $tbl_name(name, email, comment, datetime)

VALUES

('{$_REQUEST['name']}', '{$_REQUEST['email']}', '{$_REQUEST ['$comment']}', '{$_REQUEST['$datetime']}')";

 

OR

 

$sql="INSERT INTO $tbl_name(name, email, comment, datetime)

VALUES

('".$_REQUEST['name']."', '".$_REQUEST['email']."', '".$_REQUEST['$comment']."', '".$_REQUEST['$datetime']."')";

 

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.