Tutorialstream.com Forum Index
 FAQ   Search   Members   Usergroups   Register   Profile   Log in to check your private messages   Log in 

Log in
Username:    Password:      Log me on automatically each visit    
empty data sent to mysql

 
Post new topic   Reply to topic    Tutorialstream.com Forum Index -> Tutorial Help
View previous topic :: View next topic  
Author Message
pappszaby



Joined: 21 Nov 2005
Posts: 30

PostPosted: Sat Sep 01, 2007 5:02 pm    Post subject: empty data sent to mysql Reply with quote

I have a small simple html form wich should sent data to a mysql database. The connection is fine but only empty data si going through. INSERT INTO `details` VALUES (31, '', '', '');
here is the scripts:
<?
$DBhost = "host";
$DBuser = "user";
$DBpass = "pass";
$DBName = "example";
$table = "details";
mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");

@mysql_select_db("$DBName") or die("Unable to select database $DBName");

$sqlquery = "INSERT INTO $table VALUES('$id','$name','$telephone','$birthday')";

$results = mysql_query($sqlquery);

mysql_close();

print "<html><body><center>";
print "<p>You have just entered this record<p>";
print "Name : $name<br>";
print "Telephone : $telephone<br>";
print "Birthday :$birthday";
print "</body></html>";
?>

Any idea why? Sad
Back to top
View user's profile Send private message
Fed
Site Admin


Joined: 12 Aug 2005
Posts: 176

PostPosted: Sun Sep 02, 2007 11:30 pm    Post subject: Reply with quote

try printing the values before running the query, so you'll see if the variables actually contain the values
Back to top
View user's profile Send private message Send e-mail Visit poster's website
pappszaby



Joined: 21 Nov 2005
Posts: 30

PostPosted: Mon Sep 03, 2007 8:25 am    Post subject: Reply with quote

It looks like the variables does not contain the values.
Back to top
View user's profile Send private message
Fed
Site Admin


Joined: 12 Aug 2005
Posts: 176

PostPosted: Mon Sep 03, 2007 10:07 am    Post subject: Reply with quote

so the problem is before this part of the script, check where you assign the values to the variables

I haven't see you on the forum for some time, welcome back pappszaby Wink
Back to top
View user's profile Send private message Send e-mail Visit poster's website
pappszaby



Joined: 21 Nov 2005
Posts: 30

PostPosted: Mon Sep 03, 2007 4:02 pm    Post subject: Reply with quote

Hi Fed Wink

Nice to see you again too.

Do you think the html would be the problem. Sad
Back to top
View user's profile Send private message
pappszaby



Joined: 21 Nov 2005
Posts: 30

PostPosted: Mon Sep 03, 2007 4:07 pm    Post subject: Reply with quote

<html>
<head>
</head>
<body>
<center>
<form method="post" action="script.php">
<input type="hidden" name="id" value="null">
<table>
<tr><td align="left">Name</td>
<td><input type="text" name="name"></td>
</tr>
<tr><td align="left">Telephone</td>
<td><input type="text" name="telephone" size="20"></td>
</tr>
<tr><td align="left">Birthday</td>
<td><input type="text" name="birthday" size="20"></td>
</tr>
<tr><td colspan="2">
<p align="center">
<input type="submit" value="Enter record">
</td>
</tr>
</table>
</form>
</center>
</body>
</html>
Back to top
View user's profile Send private message
Fed
Site Admin


Joined: 12 Aug 2005
Posts: 176

PostPosted: Mon Sep 03, 2007 4:08 pm    Post subject: Reply with quote

you should post the section where you put the values in the variables to see what it could be
Back to top
View user's profile Send private message Send e-mail Visit poster's website
pappszaby



Joined: 21 Nov 2005
Posts: 30

PostPosted: Mon Sep 03, 2007 4:58 pm    Post subject: Reply with quote

I tried it without the print part only the script where I assign the values to the variables and still nothing happenes.
Back to top
View user's profile Send private message
Fed
Site Admin


Joined: 12 Aug 2005
Posts: 176

PostPosted: Mon Sep 03, 2007 9:01 pm    Post subject: Reply with quote

but do you actually put the values in the $_GET array into the variables? you should have something like
Code:

$name = $_GET['name'];
$telephone = $_GET['telephone'];

etc, and it looks like you have nothing like this in your script
you need to put all the values from the $_GET array into the respective variables you'll use in your script
Back to top
View user's profile Send private message Send e-mail Visit poster's website
pappszaby



Joined: 21 Nov 2005
Posts: 30

PostPosted: Fri Sep 07, 2007 9:56 pm    Post subject: Reply with quote

Thanks Fed. I have work it out Very Happy
Back to top
View user's profile Send private message
Fed
Site Admin


Joined: 12 Aug 2005
Posts: 176

PostPosted: Fri Sep 07, 2007 10:02 pm    Post subject: Reply with quote

you're welcome
Back to top
View user's profile Send private message Send e-mail Visit poster's website
pappszaby



Joined: 21 Nov 2005
Posts: 30

PostPosted: Tue Sep 11, 2007 7:37 pm    Post subject: Reply with quote

Fed,

Do you have any idea how I could have the results of the mysql database displayed by reversing the rows with the colums. I don't know if I was clear enough.
As it for now when the mysql_query runs it displays me the database the same way.
id name telephone birthday.

What I would like is

id
name
telephone
birthday

Thanks
Back to top
View user's profile Send private message
Fed
Site Admin


Joined: 12 Aug 2005
Posts: 176

PostPosted: Tue Sep 11, 2007 8:08 pm    Post subject: Reply with quote

I'm not sure I get you..
do you want the column titles vertically in the first column and a record of data per column?

since you lay out the HTML sequentially, hence all the cells of a row before all the cells of the following row it might be a problem...

you should retrieve all the data from the database and store all those of the same field in a separate array, then print this stuff looping through the arrays

it can be done for sure....no need to say that it wouldn't probably be so easy, specially if you're not so familiar with displaying query results, working with arrays etc
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Tutorialstream.com Forum Index -> Tutorial Help All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

phpBB SEO URLs V2 - Icons by Mark James

Powered by phpBB © 2001, 2005 phpBB Group