Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
Audioslaved
Forum Newbie
Posts: 2 Joined: Tue Jun 10, 2003 11:46 pm
Location: Honolulu, HI
Contact:
Post
by Audioslaved » Tue Jun 10, 2003 11:46 pm
It is supposed to be really simple, one text field that submits to a DB table with two rows. Here is the code, for some reason it does not submit to the database. Any help would be greatly appreciated. Thank you.
Code: Select all
<?php
function defaultDisplay() {
include ('../header.php');
echo "<form action="$SERVERї'PHP_SELF']" method="post">"
."<b>AOR</b> "
."<input type="text" name="title" size="50" maxlength="80"><br>";
echo "<br><br><input type="submit" name="op" value="Submit">"
."<br>(Submit)</form>";
include ('../footer.php');
}
function SubmitStory() {
$db = mysql_connect("localhost", "********", "*******") or die("Sorry buddy that failed!");
mysql_select_db("audiosla_arc");
$title = mysql_escape_string($_POSTї'title']);
$query = "INSERT INTO arc_aor VALUES (NULL, '$title')";
$result = mysql_query($query, $db);
if(!$result) {
echo "There was some sort of error, nice try ass!<br>";
exit();
}
include ('../header.php');
$query = "SELECT * from arc_aor";
$result = mysql_query($query, $db);
$waiting = sql_num_rows($result, $db);
echo "<center><br>You just submitted $waiting To the Database. Thank you!</center>";
include ('../footer.php');
}
switch($op) {
case "Submit":
SubmitStory();
break;
default:
defaultDisplay();
break;
}
?>
[NOTE] The stars were purposely put there [/NOTE]
Sevengraff
Forum Contributor
Posts: 232 Joined: Thu Apr 25, 2002 9:34 pm
Location: California USA
Contact:
Post
by Sevengraff » Wed Jun 11, 2003 2:04 am
replace
Code: Select all
if(!$result) {
echo "There was some sort of error, nice try ass!<br>";
exit();
}
with
Code: Select all
if(!$result) {
echo mysql_error();
die();
}
And let me know what happens.
cactus
Forum Regular
Posts: 343 Joined: Tue Jun 10, 2003 4:16 am
Location: UK
Post
by cactus » Wed Jun 11, 2003 2:16 am
You are trying to submit the form to it's self but you can't becuase you are trying to access "PHP_SELF" from a undefined array $SERVER.
Try $_SERVER['PHP_SELF'] (note the underscore).
Regards,
Audioslaved
Forum Newbie
Posts: 2 Joined: Tue Jun 10, 2003 11:46 pm
Location: Honolulu, HI
Contact:
Post
by Audioslaved » Wed Jun 11, 2003 2:17 am
It says "No Database Selected"
I have triple-checked PHPMYADMIN and confirmed what I have for my DB is correct.
cactus
Forum Regular
Posts: 343 Joined: Tue Jun 10, 2003 4:16 am
Location: UK
Post
by cactus » Wed Jun 11, 2003 2:23 am
Try passing your connection ($db) to the mysql_select_db() method:
mysql_select_db("audiosla_arc", $db);
Try it, it may be that simple, other wise check the spelling of your database name, it's this silly things that always pass people by
Regards,
[]InTeR[]
Forum Regular
Posts: 416 Joined: Thu Apr 24, 2003 6:51 am
Location: The Netherlands
Post
by []InTeR[] » Wed Jun 11, 2003 2:23 am
if you build software that doesn't run, use errorhandling to find a problem. I use errorhandling by default.
Can be replaced with...
Code: Select all
mysql_select_db("audiosla_arc") or die("databaseerror: ".mysql_error());