Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 24th, 2006, 05:17 AM
Authorized User
 
Join Date: Nov 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default i cannot save to my database

i cannot save to my database, the username and the table name has the same value so i put the session username to $tblname but when i call the $tblname the output is The data was not save, is there something wrong to the command in the red text... anyone can explain to me my error? thanks...

<?

include 'config.php';

$dbname = 'log';
$tblname = $_SESSION['username'];

mysql_select_db("$dbname") or die ("<h3>Cannot select the Database.</h3>");
$date = date('Y-d-m');
$time = date('h:i:s A');


$request = "insert into '$tblname' values ('$date', '$time', '$time')";
$results = mysql_query($request);

if($results)
{
    echo "The data was saved";
}
else
{
    echo "<h3>There was an error. The data was not saved.</h3>";
}

?>

<html>
<body>
<br>
<br>
<form method = post action = page1.php>
<input type = 'submit' value = 'Back to Admin Page'>
</form>
</html>
</body>

 
Old December 3rd, 2006, 02:18 AM
Registered User
 
Join Date: Dec 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It doesn't look like you have defined the columns that you want to insert your values into:

$request = "INSERT INTO $tblname(col1,col2,col3) VALUES('$date','$time','$time')";

Does that help?

 
Old December 6th, 2006, 02:28 AM
Authorized User
 
Join Date: Nov 2006
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to talk2leo
Default

first of all check code in ur config.php file
is it giving valid connection resource.if no then deacre it as global in config.php.(if u have already done this) then do the following

$request ="insert into username values($date, $time, $time)";

reply me if still having prob.

 
Old January 29th, 2007, 08:06 AM
Authorized User
 
Join Date: Jan 2007
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

INSERT INTO $tblname(col1,col2,col3) VALUES('$date','$time','$time') would be used to insert into target columns of the table.
If the table has 3 columns only: INSERT INTO $tblname VALUES('$date','$time','$time') will do.

Visit my page: http://www.webrickco.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Save Listview Data to a DataBase ecabralrojas Beginning VB 6 0 June 30th, 2008 10:33 AM
save database kim VB How-To 3 April 2nd, 2006 09:26 AM
save database kim Visual Basic 2005 Basics 0 March 20th, 2006 04:34 PM
How to i save checkbox value to database ADO guanxian VB Components 1 December 13th, 2005 06:19 PM
how to save an array to database say2x VB Databases Basics 0 November 8th, 2005 05:05 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.