...

View Full Version : What do i have Wrong (Data not being added to DB)



jman888
04-29-2009, 12:53 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<?php
include ("config.php");
mysql_select_db ("$dbname") or die ("Cannot Connect to the Database") ;
$adddata = "INSERT INTO `db_data` (
`title`,
`subtitle`,
`text`,
`moretext`)
VALUES ( '$title', '$subtitle', '$text', '$moretext' )";
if(isset($newpost) && $newpost=="yes") {
mysql_query($adddata) or die("Could not complete posting") ;
$adddata2 = "INSERT INTO `db_data` (
`title`,
`subtitle`,
`text`,
`moretext`)
VALUES ( 'title', 'subtitle', 'text', 'moretext' )";
if(isset($newpost) && $newpost=="test") {
mysql_query($adddata2) or die("Could not complete posting") ;

?>

What is wrong with that? All i get is


Parse error: syntax error, unexpected $end in /home/content/k/i/n/kingdomworks1/html/geeklog/phptest/index.php on line 28

*After reading the forum rules i edited my title to make it more relevant. ,well at least to the below post

Eran
04-29-2009, 01:36 PM
you are missing the `if` ends -> }

jman888
04-29-2009, 02:30 PM
you are missing the `if` ends -> }
then what should it look like

djm0219
04-29-2009, 02:55 PM
You're missing the closing braces for both of your if statements.



if(isset($newpost) && $newpost=="yes") {
mysql_query($adddata) or die("Could not complete posting") ;
$adddata2 = "INSERT INTO `db_data` (
`title`,
`subtitle`,
`text`,
`moretext`)
VALUES ( 'title', 'subtitle', 'text', 'moretext' )";
} // <-- This was missing
if(isset($newpost) && $newpost=="test") {
mysql_query($adddata2) or die("Could not complete posting") ;
} // <-- This was missing

jman888
04-29-2009, 09:20 PM
Ok now another Question.
www.deadant.org/phptest/index.php?newpost=test

Why doesnt it insert anything into my DB?

djm0219
04-29-2009, 09:54 PM
The link doesn't help at all. You have no form values in what you posted nor is there anything that is retrieving, checking or setting the variables you're trying to use in your SQL.

jman888
04-29-2009, 11:16 PM
Config.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
</body>
</html>
<?php
$dbname = "" ;
$dbpass = "" ;
$dbuser = "" ;
$dbhost = "" ;
$connect = mysql_connect($dbhost, $dbuser, $dbpass) or die("Cannot Connect") ;
?>

index.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<?php
include ("config.php");
mysql_select_db ("$dbname") or die ("Cannot Connect to the Database") ;
$adddata = "INSERT INTO `db_data` (
`title`,
`subtitle`,
`text`,
`moretext`)
VALUES ( '$title', '$subtitle', '$text', '$moretext' )";
if(isset($newpost) && $newpost=="yes") {
mysql_query($adddata) or die("Could not complete posting") ;
$adddata2 = "INSERT INTO `db_data` (
`title`,
`subtitle`,
`text`,
`moretext`)
VALUES ( 'title', 'subtitle', 'text', 'moretext' )";
} // <-- This was missing
if(isset($newpost) && $newpost=="test") {
mysql_query($adddata2) or die("Could not complete posting") ;
} // <-- This was missing
?>

im starting on a new website, wanting it to be kinda like a cms but mostly just something that looks like static html but if logged in i can just edit my pages.
And i was testing out to see if it can insert into my db and its not working.
i want index.php?newpost=yes to add the basic data just for testing for now

ie, i wanna be able to go to ?newpost=test and have it just insert the names of the normally would be variables.

ptmuldoon
04-29-2009, 11:48 PM
You need to create a form where you will insert the values into your form. Then you'll pass those values to your script to add them to the database.

Take is slow, and you'll begin to understand things a little better.

Your want to add/insert things into a database. Yet you haven't created a form to tell your script what values you want to insert.

jman888
04-30-2009, 01:49 AM
Isnt that done with something like


$value=$_POST['formvalue'];
??

Hayyel
04-30-2009, 02:33 AM
Read this (http://www.w3schools.com/html/html_forms.asp)

Also your names for your input fields would be:

$title
$subtitle
$text
$moretext



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum