Page 1 of 1

Please help me with my code! Thanks in advance

Posted: Tue Jun 10, 2003 11:46 pm
by Audioslaved
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() &#123;
    include ('../header.php');
    echo "<form action="$SERVER&#1111;'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');
&#125;


function SubmitStory() &#123;

$db = mysql_connect("localhost", "********", "*******") or die("Sorry buddy that failed!");
mysql_select_db("audiosla_arc");

$title = mysql_escape_string($_POST&#1111;'title']);

$query = "INSERT INTO arc_aor VALUES (NULL, '$title')";
$result = mysql_query($query, $db);
    if(!$result) &#123;
    	echo "There was some sort of error, nice try ass!<br>";
     	exit();
    &#125;
    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');
&#125;

switch($op) &#123;

    case "Submit":
	SubmitStory();
	break;

    default:
	defaultDisplay();
	break;

&#125;

?>
[NOTE] The stars were purposely put there [/NOTE]

Posted: Wed Jun 11, 2003 2:04 am
by Sevengraff
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.

Posted: Wed Jun 11, 2003 2:16 am
by cactus
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,

Posted: Wed Jun 11, 2003 2:17 am
by Audioslaved
It says "No Database Selected"
I have triple-checked PHPMYADMIN and confirmed what I have for my DB is correct.

Posted: Wed Jun 11, 2003 2:23 am
by cactus
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,

Posted: Wed Jun 11, 2003 2:23 am
by []InTeR[]
if you build software that doesn't run, use errorhandling to find a problem. I use errorhandling by default.

Code: Select all

mysql_select_db("audiosla_arc");
Can be replaced with...

Code: Select all

mysql_select_db("audiosla_arc") or die("databaseerror: ".mysql_error());