Hejsan!
Jag behöver hjälp... Har gjort ett formulär för inmating av olika länder och information om landet. Nu vill jag även kunna uppdatera informationen, men detta vill inte fungera. Jag har märkt att det är själva sql-update-fråge-raden som är den som gör att allting ballar ut, men kan inte se vad som är fel.
Tanken med det hela är att man matar in ett namn på ett land, trycker man på sök, ska infon om landet visas. Man ska sedan kunna ändra och sedan trycka på Uppdatera. I nuläget kan man mata in landets namn, och trycka på sök. Sedan blir sidan helt vit och tom.
Tar jag bort raden med update-frågan fungerar det. Men ändringen skrivs ju inte till databasen.
<?
if(isset($add))
{
if($ocountry!="")
{
$check_existing = mysql_query("SELECT * FROM country_info WHERE country='$ocountry' AND status='1' ") OR die ("Error: " . mysql_error());
$exist = mysql_num_rows($check_existing);
if($exist==0)
{
$insert_new_row = mysql_query("INSERT into country_info(status,country,country_intro,country_text,date) VALUES('1','$ocountry','$ocountry_intro','$ocountry_text','$date')") OR die ("Error: " . mysql_error());
}
else
{
echo "<p align='left'><font color='red'>Landet du försöker lägga till existerar redan!</font>";
echo "<br><br>";
echo "<a href='javascript:history.go(-1)'><--- Tillbaka</p>";
exit;
}
}
else
{
echo "<p align='left'><font color='red'>Du måste mata in ett land!</font>";
echo "<br><br>";
echo "<a href='javascript:history.go(-1)'><--- Tillbaka</p>";
exit;
}
}
if(isset($search))
{
$get_countryinfo = mysql_query("SELECT * FROM country_info WHERE country='$ocountry' AND status=1 ") OR die ("Error: " . mysql_error());
while($country_row = mysql_fetch_array($get_countryinfo))
{
$ocountry_intro = $country_row['country_intro'];
$ocountry_text = $country_row['country_text'];
$ocountry = $country_row['country'];
}
}
if(isset($update))
{
if($ocountry!="")
{
$get_countryinfo = mysql_query("SELECT * FROM country_info WHERE country='$ocountry' AND status=1 ") OR die ("Error: " . mysql_error());
$ocountry = "";
while($country_row = mysql_fetch_array($get_countryinfo))
{
$ocountry_id = $country_row['id'];
}
print $ocountry_id;
if($ocountry_id!="")
{
print "Uppdaterar ";
$update_row = mysql_query("UPDATE country_info SET date='$date', country_intro='$ocountry_intro', country_text='$ocountry_text' WHERE id='$ocountry_id'"); OR die ("Error: " . mysql_error());
}
else
{
print "Lägger till ny ";
$insert_new_row = mysql_query("INSERT into country_info(status,country,country_intro,country_text,date) VALUES('1','$ocountry','$ocountry_intro','$ocountry_text','$date')") OR die ("Error: " . mysql_error());
}
// else
// {
// while($country_rad = mysql_fetch_array($check_existing))
// {
// $ocountry_id=countr_rad['id'];
// }
/*
$update_row = mysql_query("UPDATE country_info SET status='1', date='$date', country_intro='$ocountry_intro', country_text='$country_text' WHERE id='$ocountry_id'"); OR die ("Error: " . mysql_error());
$alter_property = mysql_query("UPDATE properties SET date='$date',area='$area',country='$country',city='$city',name='$name',class='$class', address='$address',phone='$phone',fax='$fax',email='$email',underground='$underground',location='$location',desc_hotel='$desc_hotel',desc_room='$desc_room',elevator='$elevator',misc='$misc',notes='$notes',notes2='$notes2',link_text='$link_text',link_url='$link_url' WHERE id='$p_id'") OR die ("Error: " . mysql_error());
}
*/
}
}
if(isset($reset))
{
$ocountry="";
$ocountry_intro="";
$ocountry_text="";
}
?>
<form action="<? print $PHP_SELF?>" method="post" name="country" id="country">
<table width="400" border="0" align="center">
<tr>
<td colspan="2"><h3>Lägg till eller uppdatera land</h3></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td width="20%"><strong>Land:</strong></td>
<td><input name="ocountry" value="<? echo $ocountry ?>" type="text" size="40"> </td>
<td><input name="search" type="Submit" value="Sök"></td>
</tr>
<tr>
<td width="20%"><strong>Ingress:</strong></td>
<td><textarea name="ocountry_intro" rows="6" cols="40"><? echo $ocountry_intro ?></textarea> </td>
</tr>
<tr>
<td width="20%"><strong>Information:</strong></td>
<td><textarea name="ocountry_text" rows="6" cols="40"><? echo $ocountry_text ?></textarea> </td>
</tr>
<tr>
<td><input name="add" type="Submit" value="Lägg till"></td>
<td><input name="update" type="Submit" value="Uppdatera"></td>
<td><input name="reset" type="Submit" value="Rensa"></td>
</form>
Tack på förhand!!
/Kicki