Jump to content

[SOLVED] I've changed the PHP code and now it doesn't work


Wizard4U

Recommended Posts

Hello everyone, I'm from Croatia:

Problem:

Before I've changed it was :

<? include('konekcija.php'); ?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Izmjena</title>
</head>

<body>
<p><a href="index.php">Početna</a></p>
<p><u><a href="ispis.php">Ispis</a></u></p>
<p><u><a href="izmjena.php">Izmjena</a></u></p>
<p> </p>
<p>  </p>
<?php

if(isset($_GET['id'])){
$id=$_GET['id'];
}
else{
echo "Niste odabrali kojeg kontakta želite izmijeniti!";
}
$rezultat=mysql_query("SELECT * FROM kontakti WHERE id='$id'");

echo '<form action="" method="post">';

while($red=mysql_fetch_array($rezultat)){
echo 'Ime: <input type="text" name="ime" value="'.$red['Ime'].'" /><br />
	Telefonski broj: <input type="text" name="tel" value="'.$red['Tel'].'" /><br />
	Broj mobitela: <input type="text" name="mobitel" value="'.$red['Mobitel'].'" /><br />
	Broja fax-a: <input type="text" name="fax" value="'.$red['Fax'].'" /><br />
	Email adresa: <input type="text" name="email" value="'.$red['Email'].'" /><br />
	Web adresa: <input type="text" name="web" value="'.$red['Web'].'" /><br />
	Poruka: <input type="text" name="poruka" value="'.$red['Poruka'].'" /><br />';

}

echo '<input type="submit" name="submit" value="Izmijeni!" />
</form>';

?> 


</body>
</html>
<?php
if(isset($_POST['submit'])){
$id=$_GET['id'];
$Ime=$_POST['ime'];
$Tel=$_POST['tel'];
$Mobitel=$_POST['mobitel'];
$Fax=$_POST['fax'];
$Email=$_POST['email'];
$Web=$_POST['web'];
$Poruka=$_POST['poruka'];

mysql_query("UPDATE kontakti SET Ime='$Ime' WHERE id='$id'");
mysql_query("UPDATE kontakti SET Tel='$Tel' WHERE id='$id'");
mysql_query("UPDATE kontakti SET Mobitel='$Mobitel' WHERE id='$id'");
mysql_query("UPDATE kontakti SET Fax='$Fax' WHERE id='$id'");
mysql_query("UPDATE kontakti SET Email='$Email' WHERE id='$id'");
mysql_query("UPDATE kontakti SET Web='$Web' WHERE id='$id'");
mysql_query("UPDATE kontakti SET Poruka='$Poruka' WHERE id='$id'");


echo '<script type="text/javascript">window.location="ispis.php"</script>';

}
?>

 

And now  is:

 

<? include('konekcija.php'); 
include ('FCKeditor/fckeditor.php');
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Izmjena</title>
</head>

<body>
<p><a href="index.php">Početna</a></p>
<p><u><a href="ispis.php">Ispis</a></u></p>
<p><u><a href="izmjena.php">Izmjena</a></u></p>
<p> </p>
<p>  </p>
<?php

if(isset($_GET['id'])){
$id=$_GET['id'];
}
else{
echo "Niste odabrali kojeg kontakta želite izmijeniti!";
}
$rezultat=mysql_query("SELECT * FROM kontakti WHERE id='$id'");

echo '<form action="" method="post">';



while($red=mysql_fetch_array($rezultat)){


	$ime=$red['Ime'];
	$tel=$red['Tel'];
	$mob=$red['Mobitel'];
	$fax=$red['Fax'];
	$email=$red['Email'];
	$web=$red['Web'];
	$poruka=$red['Poruka'];



?> 

<form action="" method="post">
<input type="hidden" name="id" value="<?php echo $id;?>">
<table border="0" width="700">
<tr>
<td>
	Ime:
</td>
<td>
	<input type="text" name="naslov" value="<?php echo $ime;?>"/>
</td>
</tr>
<tr>
<td>
	Telefonski broj:
</td>
<td>
	<input type="text" name="naslov" value="<?php echo $tel;?>"/>
</td>
</tr>
<tr>
<td>
	Mobitel:
</td>
<td>
<input type="text" name="naslov" value="<?php echo $mob;?>"/>
</td>
</tr>
<tr>
<td>
	Fax:
</td>
<td>
	<input type="text" name="datum_objave" value="<?php echo $fax;?>"/>
</td>
</tr>
<tr>
<td>
	E-mail:
</td>
<td>
	<input type="text" name="naslov" value="<?php echo $email;?>"/>
</td>
</tr>
<tr>
<td>
	Web stranica:
</td>
<td>
	<input type="text" name="naslov" value="<?php echo $web;?>"/>
</td>
</tr>
<tr>
<td>
	Poruka:
</td>
<td>

        
        
        <?php
	$editor=new FCKeditor('$poruka');
	$editor->BasePath='FCKeditor/';
	$editor->ToolbarSet='Default';
	$editor->Value=$poruka;
	$editor->Height='200';
	$editor->Create();
	?>
        
</td>
</tr>
<tr>
<td colspan="2">

        <input type="submit" name="submit" value="Izmijeni!" />

</td>
</tr>
</tr>
</table>
</form>
<? } ?>

</body>
</html>
<?php
if(isset($_POST['submit'])){
$id=$_GET['id'];
$Ime=$_POST['ime'];
$Tel=$_POST['tel'];
$Mobitel=$_POST['mobitel'];
$Fax=$_POST['fax'];
$Email=$_POST['email'];
$Web=$_POST['web'];
$Poruka=$_POST['poruka'];

mysql_query("UPDATE kontakti SET Ime='$Ime' WHERE id='$id'");
mysql_query("UPDATE kontakti SET Tel='$Tel' WHERE id='$id'");
mysql_query("UPDATE kontakti SET Mobitel='$Mobitel' WHERE id='$id'");
mysql_query("UPDATE kontakti SET Fax='$Fax' WHERE id='$id'");
mysql_query("UPDATE kontakti SET Email='$Email' WHERE id='$id'");
mysql_query("UPDATE kontakti SET Web='$Web' WHERE id='$id'");
mysql_query("UPDATE kontakti SET Poruka='$Poruka' WHERE id='$id'");


echo '<script type="text/javascript">window.location="ispis.php"</script>';

}
?>

 

 

I've changed because I wanted: Not all HTML to be in PHP, and everything is OK but mow UPDATE doesn't work.

 

Please HELP ME

Link to comment
Share on other sites

I am not sure if this helps, tried to look at the differences,

 

noticed

 

<input type="text" name="naslov" value="<?php echo $ime;?>"/>

 

could be changed to....

<?php echo "<input type='text' name='naslov' value='".$ime."' />"; ?>

 

similar to original, I think it might be your quotes "" '', check those

 

also instead of multiple updates run

 

mysql_query("UPDATE kontakti SET Ime='$Ime',Tel='$Tel',Mobitel='$Mobitel',Fax='$Fax'  WHERE id='$id'");

Link to comment
Share on other sites

It doesn't work, can you PLEASE edit my code to be allright:

<? include('konekcija.php'); 
include ('FCKeditor/fckeditor.php');
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Izmjena</title>
</head>

<body>
<p><a href="index.php">Početna</a></p>
<p><u><a href="ispis.php">Ispis</a></u></p>
<p><u><a href="izmjena.php">Izmjena</a></u></p>
<p> </p>
<p>  </p>
<?php

if(isset($_GET['id'])){
$id=$_GET['id'];
}
else{
echo "Niste odabrali kojeg kontakta želite izmijeniti!";
}
$rezultat=mysql_query("SELECT * FROM kontakti WHERE id='$id'");

echo '<form action="" method="post">';



while($red=mysql_fetch_array($rezultat)){


	$ime=$red['Ime'];
	$tel=$red['Tel'];
	$mob=$red['Mobitel'];
	$fax=$red['Fax'];
	$email=$red['Email'];
	$web=$red['Web'];
	$poruka=$red['Poruka'];



?> 

<form action="" method="post">
<input type="hidden" name="id" value="<?php echo $id;?>">
<table border="0" width="700">
<tr>
<td>
	Ime:
</td>
<td>
	<input type="text" name="naslov" value="<?php echo $ime;?>"/>
</td>
</tr>
<tr>
<td>
	Telefonski broj:
</td>
<td>
	<input type="text" name="naslov" value="<?php echo $tel;?>"/>
</td>
</tr>
<tr>
<td>
	Mobitel:
</td>
<td>
<input type="text" name="naslov" value="<?php echo $mob;?>"/>
</td>
</tr>
<tr>
<td>
	Fax:
</td>
<td>
	<input type="text" name="datum_objave" value="<?php echo $fax;?>"/>
</td>
</tr>
<tr>
<td>
	E-mail:
</td>
<td>
	<input type="text" name="naslov" value="<?php echo $email;?>"/>
</td>
</tr>
<tr>
<td>
	Web stranica:
</td>
<td>
	<input type="text" name="naslov" value="<?php echo $web;?>"/>
</td>
</tr>
<tr>
<td>
	Poruka:
</td>
<td>

        
        
        <?php
	$editor=new FCKeditor('$poruka');
	$editor->BasePath='FCKeditor/';
	$editor->ToolbarSet='Default';
	$editor->Value=$poruka;
	$editor->Height='200';
	$editor->Create();
	?>
        
</td>
</tr>
<tr>
<td colspan="2">

        <input type="submit" name="submit" value="Izmijeni!" />

</td>
</tr>
</tr>
</table>
</form>
<? } ?>

</body>
</html>
<?php
if(isset($_POST['submit'])){
$id=$_GET['id'];
$Ime=$_POST['ime'];
$Tel=$_POST['tel'];
$Mobitel=$_POST['mobitel'];
$Fax=$_POST['fax'];
$Email=$_POST['email'];
$Web=$_POST['web'];
$Poruka=$_POST['poruka'];

mysql_query("UPDATE kontakti SET Ime='$Ime' WHERE id='$id'");
mysql_query("UPDATE kontakti SET Tel='$Tel' WHERE id='$id'");
mysql_query("UPDATE kontakti SET Mobitel='$Mobitel' WHERE id='$id'");
mysql_query("UPDATE kontakti SET Fax='$Fax' WHERE id='$id'");
mysql_query("UPDATE kontakti SET Email='$Email' WHERE id='$id'");
mysql_query("UPDATE kontakti SET Web='$Web' WHERE id='$id'");
mysql_query("UPDATE kontakti SET Poruka='$Poruka' WHERE id='$id'");


echo '<script type="text/javascript">window.location="ispis.php"</script>';

}
?>

Link to comment
Share on other sites

your input names are being reused. you need to use different input names. Input names become the $_POST names.

Fixed code (I hope):

<? include('konekcija.php'); 
include ('FCKeditor/fckeditor.php');
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Izmjena</title>
</head>

<body>
<p><a href="index.php">Početna</a></p>
<p><u><a href="ispis.php">Ispis</a></u></p>
<p><u><a href="izmjena.php">Izmjena</a></u></p>
<p> </p>
<p>  </p>
<?php

if(isset($_GET['id'])){
$id=$_GET['id'];
}
else{
echo "Niste odabrali kojeg kontakta želite izmijeniti!";
}
$rezultat=mysql_query("SELECT * FROM kontakti WHERE id='$id'");

echo '<form action="" method="post">';



while($red=mysql_fetch_array($rezultat)){


	$ime=$red['Ime'];
	$tel=$red['Tel'];
	$mob=$red['Mobitel'];
	$fax=$red['Fax'];
	$email=$red['Email'];
	$web=$red['Web'];
	$poruka=$red['Poruka'];



?> 

<form action="" method="post">
<input type="hidden" name="id" value="<?php echo $id;?>">
<table border="0" width="700">
<tr>
<td>
	Ime:
</td>
<td>
	<input type="text" name="ime" value="<?php echo $ime;?>"/>
</td>
</tr>
<tr>
<td>
	Telefonski broj:
</td>
<td>
	<input type="text" name="tel" value="<?php echo $tel;?>"/>
</td>
</tr>
<tr>
<td>
	Mobitel:
</td>
<td>
<input type="text" name="mob" value="<?php echo $mob;?>"/>
</td>
</tr>
<tr>
<td>
	Fax:
</td>
<td>
	<input type="text" name="fax" value="<?php echo $fax;?>"/>
</td>
</tr>
<tr>
<td>
	E-mail:
</td>
<td>
	<input type="text" name="email" value="<?php echo $email;?>"/>
</td>
</tr>
<tr>
<td>
	Web stranica:
</td>
<td>
	<input type="text" name="web" value="<?php echo $web;?>"/>
</td>
</tr>
<tr>
<td>
	Poruka:
</td>
<td>

        
        
        <?php
	$editor=new FCKeditor('$poruka');
	$editor->BasePath='FCKeditor/';
	$editor->ToolbarSet='Default';
	$editor->Value=$poruka;
	$editor->Height='200';
	$editor->Create();
	?>
        
</td>
</tr>
<tr>
<td colspan="2">

        <input type="submit" name="submit" value="Izmijeni!" />

</td>
</tr>
</tr>
</table>
</form>
<? } ?>

</body>
</html>
<?php
if(isset($_POST['submit'])){
$id=$_GET['id'];
$Ime=$_POST['ime'];
$Tel=$_POST['tel'];
$Mobitel=$_POST['mobitel'];
$Fax=$_POST['fax'];
$Email=$_POST['email'];
$Web=$_POST['web'];
$Poruka=$_POST['poruka'];
$sql = "UPDATE `kontakti` SET `Ime`='$Ime', `Tel`='$Tel', Mobitel='$Mobitel', Fax='$Fax', Email='$Email', Web='$Web', Poruka='$Poruka' WHERE id='$id' LIMIT 1;";
mysql_query($sql);
/*
mysql_query("UPDATE kontakti SET Ime='$Ime' WHERE id='$id'");
mysql_query("UPDATE kontakti SET Tel='$Tel' WHERE id='$id'");
mysql_query("UPDATE kontakti SET Mobitel='$Mobitel' WHERE id='$id'");
mysql_query("UPDATE kontakti SET Fax='$Fax' WHERE id='$id'");
mysql_query("UPDATE kontakti SET Email='$Email' WHERE id='$id'");
mysql_query("UPDATE kontakti SET Web='$Web' WHERE id='$id'");
mysql_query("UPDATE kontakti SET Poruka='$Poruka' WHERE id='$id'");
*/

echo '<script type="text/javascript">window.location="ispis.php"</script>';

}
?>

Link to comment
Share on other sites

There are no php errors in the code, but you should make the query die if there is an error, perhaps you

have something wrong in your query, and you could write it as one query like this:

 

mysql_query("UPDATE kontakti SET Ime='$Ime', Tel='$Tel', Mobitel='$Mobitel', Fax='$Fax',  Email='$Email', Web='$Web', Poruka='$Poruka' WHERE id='$id'");

 

 

Note, before posting to the database you should use mysql_real_escape_string() on your variables too.

 

Link to comment
Share on other sites

Mr. Wizard4U, can you please be so kind as to give us an update as to what you have tried to do, as far as fixing your code (other than shoving it at us and asking for a magic wand to be waved)?

 

Because at this point in time, based on your most recent comment, I would suggest seeking a freelancer (please go to freelance forum).  We aren't here to do your work for you. 

Link to comment
Share on other sites

Understand, sorry :

Problem is with "Poruka", in textarea show, but when I UPDATE, it doesn't UPDATE "Poruka".

You see that I edit with FCKeditor, but with that is everythnig ok because I INSERT in MYSQL with that editor and is OK.

Link to comment
Share on other sites

doh!. just realized. you need to sanitize the fckeditor output.  Because we are good, and you came to us, you must also be good, so I will let you figure out the code:

        $message_clean1 = str_replace("\'", "'", $_POST['Poruka']);
        $message_clean2 = str_replace('"', "'", $message_clean1);
        $message_clean3 = str_replace("\v", "", $message_clean2);
        $message_clean4 = str_replace("\'", "'", $message_clean3);
$Poruka = $message_clean4;

Link to comment
Share on other sites

Mr. Wizard4U, can you please be so kind as to give us an update as to what you have tried to do, as far as fixing your code (other than shoving it at us and asking for a magic wand to be waved)?

 

Because at this point in time, based on your most recent comment, I would suggest seeking a freelancer (please go to freelance forum).  We aren't here to do your work for you. 

Also, I agree. From now on, if you want my help, you'll get it after I get my retainer fee.

Link to comment
Share on other sites

Mr. Wizard4U, can you please be so kind as to give us an update as to what you have tried to do, as far as fixing your code (other than shoving it at us and asking for a magic wand to be waved)?

 

Because at this point in time, based on your most recent comment, I would suggest seeking a freelancer (please go to freelance forum).  We aren't here to do your work for you. 

Also, I agree. From now on, if you want my help, you'll get it after I get my retainer fee.

 

Sory but I don't understand this "you'll get it after I get my retainer fee." , can you please explain detailed please?!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.