You are here: Re: PHP/MySQL data entry problem « PHP Language « IT news, forums, messages
Re: PHP/MySQL data entry problem

Posted by Gleep on 05/22/07 03:35

On Mon, 21 May 2007 22:21:24 -0400, Robert <lektrikpuke@_yahoo.com> wrote:

>connect.php (note: I have tried localhost)
>***************************
><?php
>$conn = mysql_connect("127.0.0.1:3306", "user_name", "password");
>mysql_select_db("dbase_name", $conn);
>?>
>**************************
>
>insert_names.php (html, to make it easier for humans)
>**************************
><HTML>
><HEAD>
><TITLE>Insert Form</TITLE>
></HEAD>
><BODY>
><FORM ACTION="insert_data.php" METHOD=POST>
><P>Advertiser:&nbsp; <input type=text name="adv_name" size=20><P>
>Contact:&nbsp; <input type=text name="cont_name"
>size=20>&nbsp;&nbsp;&nbsp;&nbsp;
>Title:&nbsp; <input type=text name="cont_title" size=20><P>Street:&nbsp;
><input type=text name="address" size=40>&nbsp;&nbsp;&nbsp;&nbsp;
>Suite:&nbsp;
><input type=text name="apt" size=10><P>City:&nbsp;
><input type=text name="city" size=20>&nbsp;&nbsp;&nbsp;&nbsp;State:&nbsp;
><input type=text name="state" size=5>&nbsp;&nbsp;&nbsp;&nbsp;Zip:&nbsp;
><input type=text name="zip" size=10><br><br>
>Notes:<P style="margin-top: 0; margin-bottom: 0">
><textarea cols="50" rows="12" name="notes"></textarea><p>
><input type=submit name="submit" value="Insert Record"></p>
></FORM>
></BODY>
></HTML>
>*************************
>
>insert_data.php (I have tried echoing output here and everything is blank)
>*************************
><?php
>include ("connect.php");
>$sql = "INSERT INTO advertiser_tbl (adv_name, address, apt, city, state,
>zip, notes) values ('$adv_name', '$address', '$apt', '$city', '$state',
>'$zip', '$notes')";
>echo $sql;
>if (mysql_query($sql, $conn)){
> echo "record added!";
>} else {
> echo "something went wrong";
>}
>?>
>
>I can get this working locally on my Windoze and Linux installations.
>When I try it on my friend's server, nothing but the defaults are put in
>to the database. All fields except those with defaults and
>autoincrement primary are blank. Any clues?
>
>Thanks.
>
>Robert

You need to get some decent books on the topic. On your local machine globals is probably turned on.
By default and most servers globals is turned off. So you need to specifie the posted values like
so..

$adv_name = $_POST['adv_name'];
$address = $_POST['address'];
$apt = $_POST['apt'];

you get the idea.
In additional to that you need to understand validation technique. To protect you db from being
attacked and to make sure people are not posting garbage. But that's another topic.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация