PDA

View Full Version : Recordset Actions - The start of a new begining!


gavimobile
03-09-2007, 05:54 AM
Hey all,
hold your wine glass up and say cheers! This is my first form post EVER!

Ok So here it is....

Ive been following tutorials and reading up on working with a database in dreamweaver 8 to add/search/edit/delete records from mysql. So far i created a master page with all the records and each record in this master page has a link to view the details, and the part that im working on now is the inserting records.

Now the insert records works depending on the action i add for the form.
The form will add entrys in to the database with this action <?php echo $editFormAction; ?>. Now the insert_record.php page goes to an after_insert.php page when i submit the form. The After_insert.php page has form variables to view what the insert_record.php has JUST submitted. Now heres where the problem comes in to play.

If the action is set to <?php echo $editFormAction; ?>,The form WILL submit the information into the database, BUT nothing is displayed in the form variables on the after_insert.php page.
Now if the action is set to after_insert.php,The form variables on the after_insert.php page DISPLAY the information that was submitted, BUT it does not add anything in to the database.

I hope i was clear enough, and any sugesstions are appreciated.

Gavimobile

davidj
03-09-2007, 08:34 AM
first and only sugestion

while you have stepped into this PHP world but are still in the doorway i advise to follow these video tutorials

http://www.dreamweaverclub.com/vtm

you will thank me and all will become allot clearer

oh.. Welcome to the forum

gavimobile
03-10-2007, 10:19 AM
Davidj,

thank you very much for the reply. I looked at your videos and they were excellent. However i came to another dead end. I put all my current work in to another folder, and started from fresh in the root directory. I followed along to your tutorials untill inserting data. The echo commands worked fine. my script was without any errors i believe and it wouldnt add entries. If dreamweaver allows me to do all these things in just a matter of minutes, why is it worth it for me now and start actually learning php?

thanks for your support

lux
03-10-2007, 03:09 PM
dreamweaver only offers so many solutions to your web development needs.

once your needs out stretch the capabilities on offer through dremweaver you will be well and truly stuck.

being able to understand the code that makes up your web page will mean you will be able to identify faults with your work and be able to easily improve upon your work in the future.

post your code you have so far that you think isnt working and ill have a look and give you some advise

regards

gavimobile
03-10-2007, 05:56 PM
ok here is the code for the tutorial. however i believe that it would be better to work on the original file i started with. i mean how hard can it be to put 2 actions. was i not clear in my first post? maybe thats the problem. dreamweaver already made me a insert form a details page a details page with links. now im going backwards. anyways thanks to you all who are kindly helping.


<?php
require_once("connections/connection.php"); //database connection
////////////////////////////////////////////////////////////////////
$Neighborhood = $_POST['Neighborhood'];
$Type = $_POST['Type'];
$Rooms = $_POST['Rooms'];
$Size = $_POST['Size'];
$Price = $_POST['Price'];
$Details = $_POST['Details'];
$Picture = $_POST['Picture'];
$submit = $_POST['submit'];
///////////////////////////////////////////////////////////////////
if ($submit && $Neighborhood && $Type && $Rooms && $Size && $Price && $Details && $Picture){
//////////////////////////////////////////////////////////////////
$query = sprintf("INSERT into table1 (Neighborhood, Type, Rooms, Size, Price, Details, Picture) values ('$Neighborhood', '$Type', '$Size', '$Price', '$Details', '$Picture')");
mysql_query($query)or die(mysql_error());
/////////////////////////////////////////////////////////////////
}
/////////////////////////////////////////////////////////////////
$query = sprintf("SELECT * FROM table1");
$result = @mysql_query($query);
$row = mysql_fetch_array($result);
/////////////////////////////////////////////////////////////
?>

<!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>
<p>&nbsp;</p>
<p>&nbsp;</p>
<form id="form1" name="form1" method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
<p>Neighborhood:<br>
<input name="Neighborhood" type="text" id="Neighborhood" />
</p>
<p>Type:<br>
<input name="Type" type="text" id="Type" />
</p>
<p>
Rooms:<br>
<input name="Rooms" type="text" id="Rooms" />
</p>
<p>Size SQM:<br>
<input name="Size" type="text" id="Size" />
</p>
<p>Price US$:<br>
<input name="Price" type="text" id="Price" />
</p>
<p>Details:<br>
<input name="Details" type="text" id="Details" />
</p>
<p>Picture:<br>
<input name="Picture" type="file" id="Picture" />
</p>
<p>
<input name="submit1" type="submit" id="submit1" value="Submit" />
<input name="submit" type="hidden" id="submit" value="1" />
</p>
</form>
<p>&nbsp;</p>
<table width="756" border="0" cellspacing="0" cellpadding="2">
<tr bgcolor="#CCCCCC">
<th height="25" scope="col"><strong>Asse t#</strong></th>
<th scope="col"><strong>Neighborhood</strong></th>
<th scope="col"><strong>Type</strong></th>
<th scope="col"><strong>Rooms</strong></th>
<th scope="col"><strong>Size SQM </strong></th>
<th scope="col"><strong>Price US$ </strong></th>
<th scope="col"><strong>Details</strong></th>
<th scope="col"><strong>Picture</strong></th>
</tr>

<?php do {?>
<tr>
<td><div align="center"><?php echo $row['Asset'];?></div></td>
<td><div align="center"><?php echo $row['Neighborhood'];?></div></td>
<td><div align="center"><?php echo $row['Type'];?></div></td>
<td><div align="center"><?php echo $row['Rooms'];?></div></td>
<td><div align="center"><?php echo $row['Size'];?></div></td>
<td><div align="center"><?php echo $row['Price'];?></div></td>
<td><div align="center"><?php echo $row['Details'];?></div></td>
<td><div align="center"><?php echo $row['Picture'];?></div></td>
</tr>
<?php }while ($row = mysql_fetch_array($result)); ?>

</table>
</body>
</html>


thanks guys

lux
03-10-2007, 06:06 PM
could you just clear up for me what it is left that you want to achieve,

the script you have posted inserts a record and you can see the new record displayed on the same page. is the only difference that you want the new inserted record to be displayed on a new page?

regards

gavimobile
03-11-2007, 07:56 AM
ok lex,

believe it or not i think im understanding much more. the page right now goes to a details page, and all the information i submited is listed, however it does not add the information to the database. IF i remove the part of the link from the form action which says afterinsert.php, IT ADDS the information but it does not show any information on the details page. ALSO, when it brings be to the details page when it works with the mysql but doesnt show the information, all the links on the page look like this http://localhost/afterinsert.php/thelinkiwant.php. but theres no links there because EVERYTHING is in the root folder. i noticed in the top it says $editFormAction = $_SERVER['PHP_SELF']; so i assume this is where the problem lies. beacuse since i want it to go to a details page after, than the page cant link back to itself. but than again im not the expert at php. i hope i was clear enough you dont need to worry cause i check back very often for replies. Here is the ORIGINAL script which i did without tutorials, and just with dreamweaver and html. Thank You :-D



<?php require_once('Connections/connection1.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO table1 (Asset, Neighborhood, Type, Rooms, `Size`, Price, Details, Picture) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['Asset'], "int"),
GetSQLValueString($_POST['Neighborhood'], "text"),
GetSQLValueString($_POST['Type'], "text"),
GetSQLValueString($_POST['Rooms'], "text"),
GetSQLValueString($_POST['Size'], "text"),
GetSQLValueString($_POST['Price'], "text"),
GetSQLValueString($_POST['Details'], "text"),
GetSQLValueString($_POST['Picture'], "text"));
mysql_select_db($database_connection1, $connection1);
$Result1 = mysql_query($insertSQL, $connection1) or die(mysql_error());
$insertGoTo = "afterinsert.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?><!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>
<style type="text/css">
<!--
.style1 {
font-size: 12px;
font-family: Arial, Helvetica, sans-serif;
}
-->
</style>
</head>
<body>
<table cellpadding="0" cellspacing="0">
<tr><td height="149" colspan="2" valign="top">&nbsp;</td>
</tr>
<form action="afterinsert.php<?php echo $editFormAction; ?>" method="post" enctype="multipart/form-data" name="form1">
<tr>
<td width="203" valign="top">&nbsp;</td>
<td width="524">
<p><span class="style1">Neighborhood:</span><br />
<input name="Neighborhood" type="text" value="" size="32" maxlength="32" />
</p>
<p> Type:<br />
<input name="Type" type="text" value="" size="32" maxlength="32" />
</p>
<p> <span class="style1">Rooms:</span><br />
<input name="Rooms" type="text" value="" size="32" maxlength="32" />
</p>
<p> <span class="style1">Size:</span><br />
<input name="Size" type="text" value="" size="32" maxlength="32" />
</p>
<p> <span class="style1">Price:</span><br />
<input name="Price" type="text" value="" size="32" maxlength="32" />
</p>
<p> <span class="style1">Details:</span><br />
<textarea name="Details" cols="32" rows="4" id="Details"></textarea>
</p>
<p> <span class="style1">Picture:</span><br />
<input name="Picture" type="file" id="Picture" size="32" />
</p>
<p>
<input name="submit" type="submit" value="Submit" />
<input type="hidden" name="Asset" value="" />
<input type="hidden" name="MM_insert" value="form1" />
</p>
</td>
</tr>
</form>
</table>
<p>&nbsp;</p>
</body>
</html>

gavimobile
03-11-2007, 08:06 AM
i changed
$editFormAction = $_SERVER['PHP_SELF'];

to
$editFormAction = $_POST['PHP_SELF'];

and it solved the link problem, but it still wont add information to the database unless i take out the

afterinsert.php from the actions

<form action="afterinsert.php<?php echo $editFormAction; ?>" method="post" enctype="multipart/form-data" name="form1">

and if i do that the information wont display on the afterinsert.php page.

gavimobile
03-12-2007, 09:26 AM
im becomming desperate... Anyone?