Jump to content


Photo

Newbie question/help


  • Please log in to reply
5 replies to this topic

#1 SharkEye

SharkEye
  • Members
  • Pip
  • Newbie
  • 6 posts

Posted 27 February 2003 - 08:55 PM

I have just set up serve on my pc and got php and mysql and stuff

I am trying to get started by using a very simple script to gather data from a form and add it to the database and then read all teh data into a table. I am using a book and i have all the code right i am sure but it is not working. What i do not understand is that it worked the first tiem i did it but not anymore :S

Can anyone maybe help me by testign the files on there server or somthing? or shall i post code on this site?

OR does anyone know of anything (any settings) that i might have to change? Thanks veyr much James

I know i have the db and table set up ok!

THE FORM

<form name="form1" method="post" action="handle_form.php">

  <p>First Name 

    <input name="Array[firstName]" type="text" id="sadfsdf">

  </p>

  <p>Last Name 

    <input name="Array[lastName]" type="text" id="Array[firstName]">

  </p>

  <p>EMail Address 

    <input type="text" name="Array[email]">

  </p>

  <p>DOB 

    <input type="text" name="Array[DOB]">

  </p>

  <p>Info 

    <textarea name="Array[info]"></textarea>

  </p>

  <p>

    <input type="submit" name="Submit" value="Submit">

  </p>

</form>

HANDLE PAGE



<?php



//Database Info

$host = "localhost";

$user = "";

$password = "";

$dbName = "jmusers";

$tableName = "userInfo";



//Connect to the database

$link = mysql_connect($host, $user, $password);



$query = "INSERT into $tableName values 

(\'0\', \'$Array[firstName]\',\'$Array[lastName]\',\'$Array[email]\',\'$Array[DOB]\',\'$Array[info]\')";



print "The query is:<BR>$query<P>n";



if (mysql_db_query($dbName, $query, $link)) {

print "The query was successfully executed<br><br>";

}

else {

print "The query could not be executed";

}



//close the link to the database

mysql_close($link);

?>

GET DB DATA PAGE



<?php

//Database Info

$host = "localhost";

$user = "";

$password = "";

$dbName = "jmusers";

$tableName = "userInfo";

//Connect to the database

$link = mysql_connect($host, $user, $password);



$query = "SELECT * from $tableName";

$result = mysql_db_query ($dbName, $query, $link);



//creat a table to show the table results in

print "<table border=1 width ="100%" cellspacing=2 cellpadding=2 align=center>n";

print "<tr align=center valign=top>n";

print "<td align=center valigntop>Name</td>n";

print "<td align=center valigntop>EMail</td>n";

print "<td align=center valigntop>DOB</td>n";

print "<td align=center valigntop>Comments/Info</td>n";

print "</tr>n";



//fetch the results from the database

while ($row = mysql_fetch_array($result)) {

	print "<tr align=center valign=top>n";

	print "<td align=center valign=top>$row[firstName] $row[firstName]</td>n";

	print "<td align=center valign=top>$row[email]</td>n";

	print "<td align=center valign=top>$row[DOB]</td>n";

	print "<td align=center valign=top>$row[info]</td>n";

	print "</tr>n";

	}

//close the link to the database

mysql_close($link);



print "</table>n";



?>

[url=http://www.deepbluehosting.co.uk][/url]

#2 metalblend

metalblend
  • Members
  • PipPipPip
  • Advanced Member
  • 89 posts
  • LocationCalifornia, USA

Posted 27 February 2003 - 09:23 PM

If you\'ve installed the latest version of PHP (4.3), you\'re working with register_globals off.

On the handle page, add this to the beginning of the code:[php:1:8db01511b1]$Array = $HTTP_POST_VARS[\'Array\'];[/php:1:8db01511b1]

You\'ll want to read up on working with register_globals off: http://www.php.net/m...sterglobals.php

Hope that helps.

#3 SharkEye

SharkEye
  • Members
  • Pip
  • Newbie
  • 6 posts

Posted 28 February 2003 - 02:24 AM

thanks very much for your help but that has not made it work! i added that bit of code to the script on the page that you told me to and it still does not work?

anything else? i really dont know what i am doing wrong
[url=http://www.deepbluehosting.co.uk][/url]

#4 metalblend

metalblend
  • Members
  • PipPipPip
  • Advanced Member
  • 89 posts
  • LocationCalifornia, USA

Posted 28 February 2003 - 03:18 AM

http://code.phirebrush.com/ref/form01

index.html:
<form method="post" action="handle_form.php">

  <p>First Name

    <input type="text" name="firstname">

  </p>

  <p>Last Name

    <input type="text" name="lastname">

  </p>

  <p>EMail Address

    <input type="text" name="email">

  </p>

  <p>DOB

    <input type="text" name="dob">

  </p>

  <p>Info

    <textarea name="info"></textarea>

  </p>

  <p>

    <input type="submit" value="Submit">

  </p>

</form>

handle_form.php:[php:1:9b6ade3a63]<?php

//Get POST Variables
$firstname = $HTTP_POST_VARS[\'firstname\'];
$lastname = $HTTP_POST_VARS[\'lastname\'];
$email = $HTTP_POST_VARS[\'email\'];
$dob = $HTTP_POST_VARS[\'dob\'];
$info = $HTTP_POST_VARS[\'info\'];

//Connect to the database
$link = mysql_connect($host, $user, $password) or die(\"<code>Error: <i>\".mysql_error().\"</i></code>\");
mysql_select_db($dbName,$link) or die(\"<code>Error: <i>\".mysql_error().\"</i></code>\");
$q = mysql_query(\"INSERT INTO `\".$tableName.\"` (`firstname`,`lastname`,`email`,`dob`,`info`) VALUES (\'\".$firstname.\"\',\'\".$lastname.\"\',\'\".$email.\"\',\'\".$dob.\"\',\'\".$info.\"\')\",$link) or die(\"<code>Error: <i>\".mysql_error().\"</i></code>\");

mysql_close($link);
header(\"Location: results.php\");

?>[/php:1:9b6ade3a63]

results.php:[php:1:9b6ade3a63]<?php

$link = mysql_connect($host, $user, $password) or die(\"<code>Error: <i>\".mysql_error().\"</i></code>\");
mysql_select_db($dbName,$link) or die(\"<code>Error: <i>\".mysql_error().\"</i></code>\");
$q = mysql_query(\"SELECT * FROM `\".$tableName.\"` ORDER BY `id` DESC\",$link) or die(\"<code>Error: <i>\".mysql_error().\"</i></code>\");

//creat a table to show the table results in
print \"<table border=1 width =\"100%\" cellspacing=2 cellpadding=2 align=center>n\";
print \"<tr align=center valign=top>n\";
print \"<td align=center valigntop>Name</td>n\";
print \"<td align=center valigntop>EMail</td>n\";
print \"<td align=center valigntop>DOB</td>n\";
print \"<td align=center valigntop>Comments/Info</td>n\";
print \"</tr>n\";

//fetch the results from the database
while ($row = mysql_fetch_array($q)) {
print \"<tr align=center valign=top>n\";
print \"<td align=center valign=top>\".$row[\'firstname\'].\" \".$row[\'lastname\'].\"</td>n\";
print \"<td align=center valign=top>\".$row[\'email\'].\"</td>n\";
print \"<td align=center valign=top>\".$row[\'dob\'].\"</td>n\";
print \"<td align=center valign=top>\".$row[\'info\'].\"</td>n\";
print \"</tr>n\";
}
//close the link to the database
mysql_close($link);

print \"</table>n\";

?>[/php:1:9b6ade3a63]

Hope that helps.

#5 SharkEye

SharkEye
  • Members
  • Pip
  • Newbie
  • 6 posts

Posted 28 February 2003 - 10:45 AM

thanks so much for you time mate...you never guess what it was!!!


I HAD THE TABLE NAME AS [b]userinfo

doh!!


that will teach me to rush into things!
[url=http://www.deepbluehosting.co.uk][/url]

#6 metalblend

metalblend
  • Members
  • PipPipPip
  • Advanced Member
  • 89 posts
  • LocationCalifornia, USA

Posted 28 February 2003 - 11:30 AM

lol .. Glad you got it worked out.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users