28, May 2012

this page wont write to database - webmaster forum

 
Webdigity webmaster forums
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: this page wont write to database
« previous next »
Pages: [1] 2 Print
Instabuck - The easy way to sell digital products online

Author Topic: this page wont write to database  (Read 2094 times)
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 886
1148 credits
Members referred : 4



« on: Jan 23, 2006, 09:06:06 pm »

Code:
<?php
ob_start
(); 
include(
"config.php"); 
if(
$logged[username] && $logged[level] ==5

//checks to see if the user is logged in, and if their user level 
//is 5 (this is administrator)
if($_GET[links]) 

//checks to see if there is a ?user=username variable in the url. 
if (!$_POST[update]) 

// the form hasn't been submitted.  We continue... 
$data mysql_query("SELECT * from links where id = '$_GET[links]'"); 
$data mysql_fetch_array($data); 
//these lines get the user's information and put it in an array. 
//we will display the information in the html form 
echo(
<div align=\"center\"><form method=\"post\">
<table>

<tr>
<td valign=\"top\">Links Title: </td>
<td valign=\"top\"><input name=\"title\" type=\"text\" value=\"
$data[title]\"></td>
</tr>
<tr>
<td valign=\"top\">Links URL: </td>
<td valign=\"top\"><input name=\"url\" type=\"text\" value=\"
$data[url]\"></td>
</tr>
<tr>
<td height=\"85\" valign=\"top\">Description: <br> </td>
<td valign=\"top\"><textarea cols=\"30\" rows=\"5\" name=\"description\">
$data[description]</textarea>
</td>
</tr>
<tr>
<td align=\"center\" colspan=2><input type=\"submit\" name=\"submit\" value=\"Update\"></td>
</tr>
</table>
</form> 
</div>"
); 
//displays the html form 

else 

$url = ($_POST[url]); 
$title = ($_POST[title]); 
$description = ($_POST[description]);
// the above lines get rid of all html. 
echo ("The link has been successfully updated."); 
$update mysql_query("Update links set url = '$url', title = '$title', description = '$description' where id = '$_GET[links]'"); 
// updates the information in the database. 


else 

$getlinks mysql_query("Select * from links order by id asc"); 
while(
$data mysql_fetch_array($getlinks)) 

//makes a list of all the links 
echo("<a href=\"?open=15&links=$data[id]\">$data[title]</a><br />"); 
//displays the link names 


}
else

//the user's level is not 5!  They cannot view this page 
echo("Sorry, but you are not allowed to view this page!"); 


?>


ive tried everything.. any ideas?


Last blog : phpHaze 1.59.1 in Development
Global Moderator
Internet Junkie
*****
Gender: Male
Posts: 1807
9006 credits
Members referred : 6



« Reply #1 on: Jan 23, 2006, 09:37:12 pm »

You should use "INSERT INTO" instead of "UPDATE" if you want to write new records to your table. The "UPDATE" statement is to update a read record


Last blog : Are You Stumbling Yet?
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 886
1148 credits
Members referred : 4



« Reply #2 on: Jan 24, 2006, 06:59:21 am »

this isnt for writing new records, this is for changing existing records..


Last blog : phpHaze 1.59.1 in Development
Global Moderator
Internet Junkie
*****
Gender: Male
Posts: 1807
9006 credits
Members referred : 6



« Reply #3 on: Jan 24, 2006, 07:08:11 am »

Don't you have to add the information on the existing record to the update statement the? (ie. Update table set field=value WHERE FIELD=OLDVALUE)


Last blog : Are You Stumbling Yet?
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 886
1148 credits
Members referred : 4



« Reply #4 on: Jan 24, 2006, 08:48:29 am »

ive already done this, "$update = mysql_query... " so on & so forth, here is new code but still no luck:

Code:
<?php
ob_start
(); 
include(
"config.php"); 
if($logged[username] && $logged[level] == 5

//checks to see if the user is logged in, and if their user level 
//is 5 (this is administrator)
if($_GET[links]) 

//checks to see if there is a ?user=username variable in the url. 
if (!$_POST[update]) 

// the form hasn't been submitted.  We continue... 
$data mysql_query("SELECT * from links where id = '$_GET[links]'"); 
$data mysql_fetch_array($data); 
//these lines get the user's information and put it in an array. 
//we will display the information in the html form 
echo(
<div align=\"center\"><form method=\"post\">
<table>

<tr>
<td valign=\"top\">Links Title: </td>
<td valign=\"top\"><input name=\"title\" type=\"text\" value=\"
$data[title]\"></td>
</tr>
<tr>
<td valign=\"top\">Links URL: </td>
<td valign=\"top\"><input name=\"url\" type=\"text\" value=\"
$data[url]\"></td>
</tr>
<tr>
<td height=\"85\" valign=\"top\">Description: <br> </td>
<td valign=\"top\"><textarea cols=\"30\" rows=\"5\" name=\"description\">
$data[description]</textarea>
</td>
</tr>
<tr>
<td align=\"center\" colspan=2><input type=\"submit\" name=\"submit\" value=\"Update\"></td>
</tr>
</table>
</form> 
</div>"
); 
//displays the html form 

else 

$url $_POST[url]; 
$title $_POST[title]; 
$description $_POST[description];
// the above lines set variables used below
$update = ("UPDATE links set url = '$url', title = '$title', description = '$description' where id = '$_GET[links]'"); 
mysql_query($update) or die(mysql_error());
// updates the information in the database.
echo "The link has been successfully updated."


else 

$getlinks mysql_query("SELECT * from links order by id asc"); 
while($data mysql_fetch_array($getlinks)) 
//makes a list of all the links

  echo("<a href=\"?open=15&links=$data[id]\">$data[title]</a><br />"); 
//displays the link names 


}
else

//the user's level is not 5!  They cannot view this page 
echo("Sorry, but you are not allowed to view this page!"); 


?>



Last blog : phpHaze 1.59.1 in Development
Global Moderator
Internet Junkie
*****
Gender: Male
Posts: 1525
6359 credits
Members referred : 8


Gimme all your cookies!!!


« Reply #5 on: Jan 24, 2006, 11:09:09 am »

Is the page echoing "The link has been successfully updated."?


Last blog : Canonical URL Links / Tags
Global Moderator
Internet Junkie
*****
Gender: Male
Posts: 1525
6359 credits
Members referred : 8


Gimme all your cookies!!!


« Reply #6 on: Jan 24, 2006, 11:14:32 am »

Try...
Code:
$update = ("UPDATE links set url = '$url', title = '$title', description = '$description' where id = '{$_GET[links]}'");


Last blog : Canonical URL Links / Tags
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 886
1148 credits
Members referred : 4



« Reply #7 on: Jan 24, 2006, 12:33:43 pm »

no, it never displays the succesful message and that 2nd solution didnt work either Sad


Last blog : phpHaze 1.59.1 in Development
Global Moderator
Internet Junkie
*****
Gender: Male
Posts: 1525
6359 credits
Members referred : 8


Gimme all your cookies!!!


« Reply #8 on: Jan 24, 2006, 12:52:42 pm »

If this form posts to itself then try...

Code:
if (!$_POST[Update])


Last blog : Canonical URL Links / Tags
Global Moderator
Internet Junkie
*****
Gender: Male
Posts: 1525
6359 credits
Members referred : 8


Gimme all your cookies!!!


« Reply #9 on: Jan 24, 2006, 12:56:56 pm »

Please list a sample of your url string so I can see what $_GET[links] is...


Last blog : Canonical URL Links / Tags
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 886
1148 credits
Members referred : 4



« Reply #10 on: Jan 24, 2006, 02:09:52 pm »

what u suggested for post update i already have in the page but i tried what u suggested and that also didnt work.. the url would look like ?open=15&links=13...


Last blog : phpHaze 1.59.1 in Development
Global Moderator
Internet Junkie
*****
Gender: Male
Posts: 1525
6359 credits
Members referred : 8


Gimme all your cookies!!!


« Reply #11 on: Jan 24, 2006, 02:16:41 pm »

What exactly are you getting when you click update?


Last blog : Canonical URL Links / Tags
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 886
1148 credits
Members referred : 4



« Reply #12 on: Jan 24, 2006, 02:56:41 pm »

nothing page refreshes and the update never takes place


Last blog : phpHaze 1.59.1 in Development
Global Moderator
Internet Junkie
*****
Gender: Male
Posts: 1525
6359 credits
Members referred : 8


Gimme all your cookies!!!


« Reply #13 on: Jan 24, 2006, 02:58:26 pm »

so the form shows again...


Last blog : Canonical URL Links / Tags
Global Moderator
Internet Junkie
*****
Gender: Male
Posts: 1525
6359 credits
Members referred : 8


Gimme all your cookies!!!


« Reply #14 on: Jan 24, 2006, 03:04:31 pm »

AH... try...

Code:
if ($_POST['submit'] != 'Update')
« Last Edit: Jan 24, 2006, 03:11:44 pm by wineo »


Last blog : Canonical URL Links / Tags
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 886
1148 credits
Members referred : 4



« Reply #15 on: Jan 24, 2006, 03:31:56 pm »

yes! it works now. awesome..thx wineo.. im working on creating my own CMS for sleekpixel.net its turning out quite nicely thx to you and this forum as well as nikolas Tongue


Last blog : phpHaze 1.59.1 in Development
Global Moderator
Internet Junkie
*****
Gender: Male
Posts: 1525
6359 credits
Members referred : 8


Gimme all your cookies!!!


« Reply #16 on: Jan 24, 2006, 03:34:51 pm »

No worries!


Last blog : Canonical URL Links / Tags
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 886
1148 credits
Members referred : 4



« Reply #17 on: Jan 24, 2006, 03:54:35 pm »

think u could help with another page?


Last blog : phpHaze 1.59.1 in Development
Global Moderator
Internet Junkie
*****
Gender: Male
Posts: 1525
6359 credits
Members referred : 8


Gimme all your cookies!!!


« Reply #18 on: Jan 24, 2006, 04:03:25 pm »

Fire away, I will help where I can...


Last blog : Canonical URL Links / Tags
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 886
1148 credits
Members referred : 4



« Reply #19 on: Jan 24, 2006, 04:04:47 pm »

another database update problem (man i suck with updating a database, thats the only probs i really have)

link_mod.php

Code:
<?
ob_start();
include("config.php");
if ($logged[username] && $logged[level] >= 2) 
{
// the user is logged in!  We continue...
if (!$_POST[update])
{
// the form hasn't been submitted.  We continue...
$data2 = mysql_query("SELECT * from users where username = '$logged[username]'");
$data2 = mysql_fetch_array($data2);
$urlid = $data2[urlid];
$data = mysql_query("SELECT * from links where id = '$urlid'");
$data = mysql_fetch_array($data);
// the above lines get the information so that it can be displayed in the html form.
echo("
<div align=\"center\"><form method=\"post\">
<table>

<tr>
<td valign=\"top\">Links Title: </td>
<td valign=\"top\"><input name=\"title\" type=\"text\" value=\"$data[title]\"></td>
</tr>
<tr>
<td valign=\"top\">Links URL: </td>
<td valign=\"top\"><input name=\"url\" type=\"text\" value=\"$data[url]\"></td>
</tr>
<tr>
<td height=\"85\" valign=\"top\">Description: <br> </td>
<td valign=\"top\"><textarea cols=\"30\" rows=\"5\" name=\"description\">$data[description]</textarea>
</td>
</tr>
<tr>
<td align=\"center\" colspan=2><input type=\"submit\" name=\"update\" value=\"Update\"></td>
</tr>
</table>
</form>
</div>");
}
else
{
$url = $_POST[url];
$title = $_POST[title];
$description = $_POST[description];
// the above lines set variables used below
$update = ("UPDATE links set url = '$url', title = '$title', description = '$description' where id = '$urlid'");
mysql_query($update) or die(mysql_error());
// updates the information in the database.
echo "Your link has been successfully updated."; 
}
}
else
{
// They aren't logged in!
echo "You have either not paid for your link to even submit it, or you are not logged in.";
}
?>


Last blog : phpHaze 1.59.1 in Development
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=1329
Tags : php html forums databases cms Bookmark this thread : Digg Del.icio.us Dzone more....

Pages: [1] 2 Print 
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: this page wont write to database
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 28, 2012, 05:35:45 am





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!


Forum Statistics
Total Posts: 62.837
Total Topics: 11.030
Total Members: 21.452
Tutorials : 58
Resources : 929
Designs : 395
Latest Member: iplaytheme

114 Guests, 3 Users online :

13 users online today:




Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2012 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.