English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I have an html form with three fields. The same three fields are the 3 columns in a table in a mysql database. I have a php scipt to add these filds in a new row using INSERT, but when the form is submitted, a new row is created in the table but the 3 fields are bank. Not sure whats wrong with the variables.
The form info:


Title Link


Content:




The addpdx.php info:
$query = "INSERT INTO pdx (title, link, content)
VALUES ('$title', '$link', '$content')";
$result = mysql_query($query);
print "Data submitted to database! (Click here to view)
mysql_close();
?>

2007-10-22 03:17:06 · 4 answers · asked by mjcarney23 2 in Computers & Internet Programming & Design

4 answers

well in the addpdx.php you do not have access to the original variables. They are held in the Global Array $_POST[];
so you need to go in and grab each one ie;
$title = $_POST['title'];

then you will be able to use them.
Also, do you have your connect string at the top of your addpdx.php or include it in.
One last thing. You should make your 'Success" message conditional to whether or not the query actually executed successfully/.

2007-10-22 03:37:55 · answer #1 · answered by nickname 3 · 1 0

Since you do a POST in the form, in addpdx.php:
// Extract the variables you have: $title, $link and $content.
while (list ( $name , $value ) = each ( $_POST ) )
$$name = $value;
// build your querry: NOTE the single, reverse and double quotes!
// not always necessary, but I found it ALWAYS working with
// all versions of PhP. Spaces added for readability:
$query = ' INSERT INTO ` pdx ` ( ` title ` , ` link ` , ` content ` )
VALUES ( " ' . $title . ' " , " ' . $link . ' " , " ' . $content . ' " ) ";
// now place your query:
mysql_query ( $query ) or die("Query failed : " . mysql_error());

2007-10-22 06:25:08 · answer #2 · answered by just "JR" 7 · 0 0

Create table: create table check (id int not nul auto_increment primary key, email varchar(50)) Check whether session contains value or not.

2016-05-24 03:51:29 · answer #3 · answered by ? 3 · 0 0

This is how I would do it ... maybe it will help, maybe it won't:

$sql = "insert into pdx (title,link,content) values (";
$sql .= "'" . addslashes( $_POST["title"] ) . "',";
$sql .= "'" . addslashes( $_POST["link"] ) . "',";
$sql .= "'" . addslashes( $_POST["content"] ) . "')";

mysql_query($sql);

(Those are single quotes inside the double quotes ... it's hard to see when it's not courier)

PS: You don't need to wrap each variable with the addslashes() function if you have magic_quotes_gpc turned on.

2007-10-22 03:36:41 · answer #4 · answered by Anonymous · 0 0

fedest.com, questions and answers