| View previous topic :: View next topic |
| Author |
Message |
pappszaby
Joined: 21 Nov 2005 Posts: 30
|
Posted: Sat Sep 01, 2007 5:02 pm Post subject: empty data sent to mysql |
|
|
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?  |
|
| Back to top |
|
 |
Fed Site Admin

Joined: 12 Aug 2005 Posts: 176
|
Posted: Sun Sep 02, 2007 11:30 pm Post subject: |
|
|
| try printing the values before running the query, so you'll see if the variables actually contain the values |
|
| Back to top |
|
 |
pappszaby
Joined: 21 Nov 2005 Posts: 30
|
Posted: Mon Sep 03, 2007 8:25 am Post subject: |
|
|
| It looks like the variables does not contain the values. |
|
| Back to top |
|
 |
Fed Site Admin

Joined: 12 Aug 2005 Posts: 176
|
Posted: Mon Sep 03, 2007 10:07 am Post subject: |
|
|
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  |
|
| Back to top |
|
 |
pappszaby
Joined: 21 Nov 2005 Posts: 30
|
Posted: Mon Sep 03, 2007 4:02 pm Post subject: |
|
|
Hi Fed
Nice to see you again too.
Do you think the html would be the problem.  |
|
| Back to top |
|
 |
pappszaby
Joined: 21 Nov 2005 Posts: 30
|
Posted: Mon Sep 03, 2007 4:07 pm Post subject: |
|
|
<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 |
|
 |
Fed Site Admin

Joined: 12 Aug 2005 Posts: 176
|
Posted: Mon Sep 03, 2007 4:08 pm Post subject: |
|
|
| you should post the section where you put the values in the variables to see what it could be |
|
| Back to top |
|
 |
pappszaby
Joined: 21 Nov 2005 Posts: 30
|
Posted: Mon Sep 03, 2007 4:58 pm Post subject: |
|
|
| 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 |
|
 |
Fed Site Admin

Joined: 12 Aug 2005 Posts: 176
|
Posted: Mon Sep 03, 2007 9:01 pm Post subject: |
|
|
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 |
|
 |
pappszaby
Joined: 21 Nov 2005 Posts: 30
|
Posted: Fri Sep 07, 2007 9:56 pm Post subject: |
|
|
Thanks Fed. I have work it out  |
|
| Back to top |
|
 |
Fed Site Admin

Joined: 12 Aug 2005 Posts: 176
|
Posted: Fri Sep 07, 2007 10:02 pm Post subject: |
|
|
you're welcome  |
|
| Back to top |
|
 |
pappszaby
Joined: 21 Nov 2005 Posts: 30
|
Posted: Tue Sep 11, 2007 7:37 pm Post subject: |
|
|
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 |
|
 |
Fed Site Admin

Joined: 12 Aug 2005 Posts: 176
|
Posted: Tue Sep 11, 2007 8:08 pm Post subject: |
|
|
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 |
|
 |
|