following the tutorial but... result is different

Codes here !

Moderators: macek, egami, gesf

GIORGOS_K
New php-forum User
New php-forum User
Posts: 2
Joined: Tue Apr 22, 2003 9:19 am

following the tutorial but... result is different

Postby GIORGOS_K » Tue Apr 22, 2003 9:35 am

Hi,

I am a new php/mysql user. Did a tutorial and I tried to do something similar with this:
http://hotwired.lycos.com/webmonkey/99/ ... rogramming

My code is similar... but result is different. Can you understand what is wrong? That's my code:

<html>

<body>



<?php



$db = mysql_connect("localhost", "root");

mysql_select_db("e-box",$db);



if ($submit) {

// here if no ID then adding else we're editing

if ($id) {

$sql = "UPDATE e-box SET serial_no='$serial_no',country='$country',area='$area',organisation='$organisation',place='$place',installer='$installer',person_in_charge='$person_in_charge',ip='$ip',user_name='$user_name',password='$password',inside_temperature_sensors='$inside_temperature_sensors',ambient_temperature_sensors='$ambient_temperature_sensors',humidity_sensors='$humidity_sensors',counter_sensors='$counter_sensors',AD_sensors='$AD_sensors',electricity_current_sensors='$electricity_current_sensors',occupancy_sensors='$occupaancy_sensors',CO_sensors='$CO_sensors' WHERE id=$id";

} else {

$sql = "INSERT INTO e-box (serial_no,country,area,organisation,place,installer,person_in_charge,ip,user_name,password,inside_temperature_sensors,ambient_temperature_sensors,humidity_sensors,counter_sensors,AD_sensors,electricity_current_sensors,occupancy_sensors,CO_sensors) VALUES ('$serial_no','$country','$area','$organisation','$place','$installer','$person_in_charge','$ip','$user_name','$password','$inside_temperature_sensors','$ambient_temperature_sensors','$humidity_sensors','$counter_sensors','$AD_sensors','$electricity_current_sensors','$occupancy_sensors','$CO_sensors')";

}

// run SQL against the DB

$result = mysql_query($sql);

echo "Record updated/edited!<p>";

} elseif ($delete) {

// delete a record

$sql = "DELETE FROM e-box WHERE id=$id";

$result = mysql_query($sql);

echo "$sql Record deleted!<p>";

} else {

// this part happens if we don't press submit

if (!$id) {

// print the list if there is not editing

$result = mysql_query("SELECT * FROM e-box",$db);

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

printf("<a href=\"%s?id=%s\">%s %s</a> \n", $PHP_SELF, $myrow["id"], $myrow["serial_no"], $myrow["organisation"]);

printf("<a href=\"%s?id=%s&delete=yes\">(DELETE)</a><br>", $PHP_SELF, $myrow["id"]);

}

}



?>

<P>

<a href="<?php echo $PHP_SELF?>">ADD A RECORD</a>

<P>

<form method="post" action="<?php echo $PHP_SELF?>">

<?php



if ($id) {

// editing so select a record

$sql = "SELECT * FROM e-box WHERE id=$id";

$result = mysql_query($sql);

$myrow = mysql_fetch_array($result);

$id = $myrow["id"];

$serial_no = $myrow["serial_no"];

$country = $myrow["country"];

$area = $myrow["area"];

$organisation = $myrow["organisation"];

$place = $myrow["place"];

$installer = $myrow["installer"];

$person_in_charge = $myrow["person_in_charge"];

$ip = $myrow["ip"];

$user_name = $myrow["user_name"];

$password = $myrow["password"];

$inside_temperature_sensors = $myrow["inside_temperature_sensors"];

$ambient_temperature_sensors = $myrow["ambient_temperature_sensors"];

$humidity_sensors = $myrow["humidity_sensors"];

$counter_sensors = $myrow["counter_sensors"];

$AD_sensors = $myrow["AD_sensors"];

$electricity_current_sensors = $myrow["electricity_current_sensors"];

$occupancy_sensors = $myrow["occupancy_sensors"];

$CO_sensors = $myrow["CO_sensors"];

// print the id for editing



?>

<input type=hidden name="id" value="<?php echo $id ?>">

<?php

}



?>

serial_no:<input type="Text" name="serial_no" value="<?php echo $serial_no ?>"><br>

country:<input type="Text" name="country" value="<?php echo $country ?>"><br>

area:<input type="Text" name="area" value="<?php echo $area ?>"><br>

organisation:<input type="Text" name="organisation" value="<?php echo $organisation ?>"><br>

place:<input type="Text" name="place" value="<?php echo $place ?>"><br>

installer:<input type="Text" name="installer" value="<?php echo $installer ?>"><br>

person_in_charge:<input type="Text" name="person_in_charge" value="<?php echo $person_in_charge ?>"><br>

ip:<input type="Text" name="ip" value="<?php echo $ip ?>"><br>

user_name:<input type="Text" name="user_name" value="<?php echo $user_name ?>"><br>

password:<input type="Text" name="password" value="<?php echo $password ?>"><br>

inside_temperature_sensors:<input type="Text" name="inside_temperature_sensors" value="<?php echo $inside_temperature_sensors ?>"><br>

ambient_temperature_sensors:<input type="Text" name="ambient_temperature_sensors" value="<?php echo $ambient_temperature_sensors ?>"><br>

humidity_sensors:<input type="Text" name="humidity_sensors" value="<?php echo $humidity_sensors ?>"><br>

counter_sensors:<input type="Text" name="counter_sensors" value="<?php echo $counter_sensors ?>"><br>

AD_sensors:<input type="Text" name="AD_sensors" value="<?php echo $AD_sensors ?>"><br>

electricity_current_sensors:<input type="Text" name="electricity_current_sensors" value="<?php echo $electricity_current_sensors ?>"><br>

occupancy_sensors:<input type="Text" name="occupancy_sensors" value="<?php echo $occupancy_sensors ?>"><br>

CO_sensors:<input type="Text" name="CO_sensors" value="<?php echo $CO_sensors ?>"><br>

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

</form>



<?php



}



?>



</body>

</html>

liquedus
php-forum Active User
php-forum Active User
Posts: 266
Joined: Tue Apr 08, 2003 5:18 am
Location: Ottawa, Canada
Contact:

Postby liquedus » Tue Apr 22, 2003 10:11 am

Hi,

Thats quite a bit of code my eyes hurt 8O ... anyways

$db = mysql_connect("localhost", "root");

try

$db = mysql_connect("localhost","root","yourPassword");

..... next

if($submit) ..... use instead

if(isset($_GET['submit'])) or if(isset($_POST['submit'))

depending on how your form submits the info... for a beginner I would not do that tutorial, I've read it before.... but rather I would go pick up a PHP book and read the whole thing. Thats all i can offer now, cause im a little busy...

GIORGOS_K
New php-forum User
New php-forum User
Posts: 2
Joined: Tue Apr 22, 2003 9:19 am

not working

Postby GIORGOS_K » Tue Apr 29, 2003 2:44 am

still can not manage to do what the tutorial does. Dit it only by following exactly what it writes and works fine but by just changing the "variables" (???) and the database...is not working the same. Can not understand the difference..
I don't have any password so the first suggestion can not be applied. By changing the code according to the 2nd suggestion, I have a "parse error" in my file "on line 17"
Thanks anyway! :oops:

User avatar
Redcircle
Moderator
Moderator
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA
Contact:

Postby Redcircle » Tue Apr 29, 2003 2:54 am

Sorry to say but that tutorial is outdated. See the stickies in the General PHP forum about why forms do not work.


Return to “mySQL & php coding”

Who is online

Users browsing this forum: No registered users and 1 guest