Forum Moderators: coopster

Message Too Old, No Replies

php Newb . help

why isnt this working?

         

cuce

11:18 pm on May 26, 2006 (gmt 0)

10+ Year Member



why isnt this working?

{
include("assets/includes/header.inc");// connects to the database and selects the table
echo ('<div id="primary">');?>
<?php
if(isset($_POST['go']))
{
$sql = "INSERT INTO cms_amazonmusic (title, link, description) VALUES ('$title','$link','$description')";
mysql_query($sql);
if(!mysql_error()){echo $title . " has been added to the database<br/><br/><a href=\"#\">add another</a>";
}
else
{
echo
('
<form method="post" action="'.$_SERVER["PHP_SELF"].'">
<p>title : <br/> <input type="text" id="title" name="title" ></p>
<p>amazon link : <br/><input type="text" id="link" name="link" /></p>
<p>description : <br/><input type="text" id="description" name="description" /></p>
<p><input type="submit" id="go" name="go" value="go" /></p>
</form>
');
}
}

eelixduppy

3:14 am on May 27, 2006 (gmt 0)



Hello. Try changing it to the following. I changed only a couple things, im not quite sure if its going to make any difference. Also, for further debugging, use error_reporting(E_ALL); at the top of the script.


<?php
include("assets/includes/header.inc");//I would suggest storing these functions in a file called header.php NOT header.inc because with an extension of .inc, the code can be viewed by anyone as plain text, therefore revealing your username and password

echo "<div id='primary'>";
if(isset($_POST["go"]))
{
$sql = "INSERT INTO cms_amazonmusic (title, link, description) VALUES ('$title','$link','$description')";
$result = mysql_query($sql) or die("Information was not added");
if($result){echo $title . " has been added to the database<br/><br/><a href=\"#\">add another</a>";
}
else
{
echo "
<form method='post' action='".$_SERVER["PHP_SELF"]."'>
<p>title : <br/> <input type='text' id='title' name='title' ></p>
<p>amazon link : <br/><input type='text' id='link' name='link' /></p>
<p>description : <br/><input type='text' id='description' name='description' /></p>
<p><input type='submit' id='go' name='go' value='go' /></p>
</form>
";
}
?>

Habtom

5:19 am on May 27, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The problem lies most probably on the query. Rewrite the query to the following:

$sql = "INSERT INTO cms_amazonmusic (title, link, description) VALUES ('". $title ."','". $link ."','". $description ."')";

Habtom

dreamcatcher

6:58 am on May 27, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Its possibly a register globals issue and you have them OFF.

Try putting the following BEFORE your query:

$title = $_POST['title'];
$link = $_POST['link'];
$description = $_POST['description'];

dc

Habtom

1:38 pm on May 27, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Dreamcatcher, that could be too. Cuce, try adding it with the solution I provided above.

Hab

eelixduppy

1:50 pm on May 27, 2006 (gmt 0)



The query should be interpreted correctly in either case. Look at Variable Parsing [us3.php.net]. I think it is just register globals; nice one dc . I wasn't thinking of that :)