Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

following the tutorial but... result is different

Codes here !

Moderators: macek, egami, gesf

following the tutorial but... result is different

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


I am a new php/mysql user. Did a tutorial and I tried to do something similar with this: ... rogramming

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




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


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"]);





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


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


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 ?>">




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">






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

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


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

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


$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...
php-forum Active User
php-forum Active User
Posts: 266
Joined: Tue Apr 08, 2003 5:18 am
Location: Ottawa, Canada

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 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:
New php-forum User
New php-forum User
Posts: 2
Joined: Tue Apr 22, 2003 9:19 am

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.
User avatar
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA

Return to mySQL & php coding

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.