PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Smackie
Forum Contributor
Posts: 302 Joined: Sat Jan 29, 2005 2:33 pm
Post
by Smackie » Mon Jun 06, 2005 11:13 am
For some reason this script will only send blanks to MySQL why is it sending blanks??
Code: Select all
<?php
if(isset($_POST['post'])) {
$site_name = $_POST['site_name'];
$tablecolor = $_POST['tablecolor'];
$background = $_POST['background'];
}
$sql = "INSERT INTO sitestuff (site_name, tablecolor, background) VALUES ('$site_name', '$tablecolor', '$background')";
echo '<form name="form" method="post" action="../install.php?pages=site-stuff">';
echo 'Site Name:<input name="$site_name" type="text" size="35" maxlength="100"><br>';
echo 'Table Color:<input name="$tablecolor" type="text" size="35" maxlength="100"> <font color="red">*Please add # before the numbers or just use red, blue ect.*</font><br>';
echo 'Background Color:<input name="$background" type="text" size="35" maxlength="100"> <font color="red">*Please add # before the numbers or just use red, blue ect.*</font><br>';
echo '<input type="submit" name="Submit" value="Submit"></form>';
$result = mysql_query($sql);
if (!$result) {
echo '<b>Error!</b> Please contact the administrator.';
} else {
echo 'Tables were successfully added.';
}
?>
thank you
Smackie
Skara
Forum Regular
Posts: 703 Joined: Sat Mar 12, 2005 7:13 pm
Location: US
Post
by Skara » Mon Jun 06, 2005 11:22 am
you're sending the query even if the form hasn't been submitted.
Code: Select all
<?php
echo '<form name="form" method="post" action="../install.php?pages=site-stuff">';
echo 'Site Name:<input name="$site_name" type="text" size="35" maxlength="100"><br>';
echo 'Table Color:<input name="$tablecolor" type="text" size="35" maxlength="100"> <font color="red">*Please add # before the numbers or just use red, blue ect.*</font><br>';
echo 'Background Color:<input name="$background" type="text" size="35" maxlength="100"> <font color="red">*Please add # before the numbers or just use red, blue ect.*</font><br>';
echo '<input type="submit" name="Submit" value="Submit"></form>';
if(isset($_POST['post'])) {
$site_name = $_POST['site_name'];
$tablecolor = $_POST['tablecolor'];
$background = $_POST['background'];
$sql = "INSERT INTO sitestuff (site_name, tablecolor, background) VALUES ('$site_name', '$tablecolor', '$background')";
$result = mysql_query($sql);
if (!$result) {
echo '<b>Error!</b> Please contact the administrator.';
} else {
echo 'Tables were successfully added.';
}
}
?>
Smackie
Forum Contributor
Posts: 302 Joined: Sat Jan 29, 2005 2:33 pm
Post
by Smackie » Mon Jun 06, 2005 11:30 am
ok that quit making blanks but now it doesnt show anything in the database
artexercise
Forum Commoner
Posts: 33 Joined: Thu Nov 20, 2003 9:38 am
Location: Raleigh, NC
Post
by artexercise » Mon Jun 06, 2005 11:34 am
Do you have the mysql_connect statement in another file?
JOE--
Skara
Forum Regular
Posts: 703 Joined: Sat Mar 12, 2005 7:13 pm
Location: US
Post
by Skara » Mon Jun 06, 2005 11:35 am
..I didn't look at your form. -_-'
Code: Select all
<input name="e;$site_name"e; type="e;text"e; size="e;35"e; maxlength="e;100"e;>
should be
Code: Select all
<input name="e;site_name"e; type="e;text"e; size="e;35"e; maxlength="e;100"e;>
and you never once set $_POST['post'] in the form. O.o
Change
to
If this is a public form, I advise against directly entering the data. Convert quotes etc into html entities or something.
Edit: ^ posted.
Do you have the mysql_connect statement in another file?
If he didn't, he wouldn't have gotten blanks.
Smackie
Forum Contributor
Posts: 302 Joined: Sat Jan 29, 2005 2:33 pm
Post
by Smackie » Mon Jun 06, 2005 11:38 am
If you mean db.php that connects to the database yeah
Code: Select all
<?
/* Database Information - Required!! */
/* -- Configure the Variables Below --*/
$dbhost = 'localhost';
$dbuser = '';
$dbpasswd = '******';
$database = '';
/* Database Stuff, do not modify below this line */
$connection = mysql_pconnect("$dbhost","$dbuser","$dbpasswd")
or die ("Couldn't connect to server.");
$db = mysql_select_db("$database", $connection)
or die("Couldn't select database.");
?>
it is stored in install.php file
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Mon Jun 06, 2005 12:00 pm
on every mysql_*() you should run a or die(mysql_error()) to spot the problem. For example,
to
Code: Select all
$result = mysql_query($sql) or die(mysql_error());