Forum Moderators: coopster

Message Too Old, No Replies

help with some simple php

I am new to php / web design

         

theebrettroberts

7:21 am on Oct 17, 2007 (gmt 0)

10+ Year Member



Ok guys i am new to php. I am having some trouble getting a script to INSERT data into table "RSVP" in database "wedding" so far i have 2 files - rsvp.php and rsvp2.php rsvp.php will contain the form where rsvp2.php will pass the info to sql. but as you can tell as why i am posting this its not passing the information in the form. so heres my server information:

Apache version : Apache/1.3.33 (Win32) JRun/4.0
PHP version : 5.0.4
MySQL version : 4.1.10a-nt - extension : mysqli

here is my rsvp.php

<?
$fname= $_POST[’fname’];
$lname= $_POST[’lname’];
$number=$_POST[’number’];
$emailaddy=$_POST[’email’];

echo "The following information will be entered into the database<br><br><br>";
echo "<b>FirstName:</b>&nbsp;$_POST[fname]<br>";
echo "<b>LastName:</b>&nbsp;$_POST[lname]<br>";
echo "<b># of Guests</b>&nbsp;$_POST[number]<br>";
echo "<b>Email:</b>&nbsp;$_POST[email]<br>";
echo "Thanks for taking the time to submit your information.";

if(isset($_POST['submit']))
{
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("wedding") or die(mysql_error());
mysql_query("INSERT INTO `rsvp` (`FirstName`, `LastName`, `Guests`, `emailaddy`) values ('$fname', ‘$lname','$number','$email')");
die(mysql_error());

echo "The following information was entered into the database<br><br><br>";
echo "<b>FirstName:</b>&nbsp;$_POST[’fname’]<br>";
echo "<b>LastName:</b>&nbsp;$_POST[lname’]<br>";
echo "<b># of Guests</b>&nbsp;$_POST[number]<br><br><br>";
echo "<b>Email:</b>&nbsp;$_POST[email]<br>";
echo "Thanks for taking the time to submit your information.";

mysql_close();

} else {

echo "Do not try to visit this page directly. Please use the <a href=form1.php>forms</a>";
}
?>

I know this maybe more than enough information or not enough information but any insight maybe helpful. Thanks in advance.

[edited by: eelixduppy at 1:37 pm (utc) on Oct. 17, 2007]
[edit reason] removed excess html [/edit]

Habtom

7:47 am on Oct 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Replace the necessary part, if this works for you edit the rest accordingly:

$fname= $_POST['fname'];
$lname= $_POST['lname'];
$number=$_POST['number'];
$emailaddy=$_POST['email'];

echo "The following information will be entered into the database<br><br><br>";
echo "<b>FirstName:</b>&nbsp;". $_POST['fname'] ."<br>";
echo "<b>LastName:</b>&nbsp;". $_POST['lname'] ."<br>";
echo "<b># of Guests</b>&nbsp;". $_POST['number'] ."<br>";
echo "<b>Email:</b>&nbsp;". $_POST['email'] ."<br>";
echo "Thanks for taking the time to submit your information.";

akameng

9:03 am on Oct 17, 2007 (gmt 0)

10+ Year Member



however, Habtom gives good solution, but you can try also this:

<?php
//---
//--
echo "<pre>";
foreach($_POST as $key=>$value){
echo '$_POST["'.$key.'"]='.$value;
}
echo "</pre>";
?>

The above code will print all post data that submited, then you can check the result.

theebrettroberts

3:53 am on Oct 19, 2007 (gmt 0)

10+ Year Member



The problem isnt with the information showing on the page. I am trying to find out why the record isnt being inserted in to the my sql data base. It all displays on the page correctly. Is there something wrong with my query?

deMorte

7:00 am on Oct 19, 2007 (gmt 0)

10+ Year Member



I'm not sure if this solves your problem, but this is the way I input data into MySQL -db:

mysql_query("INSERT INTO rsvp ( FirstName, LastName, Guests, emailaddy ) values ( '".$fname."', '".$lname."', '".$number."', '".$email."' )");

I'm not sure about the spacings there, but that's the way I do it. So, try emitting the single quotes from the table and cell names and encase the php-variables with double quotes and dots.

Hope this helps some.

[edited by: jatar_k at 12:24 pm (utc) on Oct. 19, 2007]
[edit reason] fixed sidescroll [/edit]

akameng

3:21 pm on Oct 19, 2007 (gmt 0)

10+ Year Member



Use this code to check your error:

<?php
$link = mysql_connect("localhost", "root", "");

mysql_select_db("db_name", $link);
echo mysql_errno($link) . ": " . mysql_error($link). "\n";

mysql_query("INSERT ..", $link);
echo mysql_errno($link) . ": " . mysql_error($link) . "\n";
?>

Edit it for your need!

Habtom

3:51 pm on Oct 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am trying to find out why the record isnt being inserted in to the my sql data base. It all displays on the page correctly. Is there something wrong with my query?

You need to get the values right, to get the right data inserted. See my previous post.

Habtom