Jump to content


Photo

X-solved-Xerror editing mysql using php


  • Please log in to reply
23 replies to this topic

#1 ludjer

ludjer
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts
  • LocationSouth Africa-Pretoria

Posted 30 August 2006 - 12:49 PM

i am having problems editing the sql database
<?php
$hostname_intranet = "localhost";
$database_intranet = "intranet";
$username_intranet = "root";
$password_intranet = "***";
$intranet = mysql_pconnect($hostname_intranet, $username_intranet, $password_intranet) or trigger_error(mysql_error(),E_USER_ERROR);
$sqlqup= "UPDATE club_data SET Head=$gethead, Teacher=$getteacher, News=$getnews, Message=$getmessage, members=$getmembers WHERE ClubID='$clubno'";
$sqlview="select * from `intranet`.`club_data` WHERE ClubID='$clubno'";
 
if(isset($_POST['Submit_1'])) {

								$gethead = $_POST['head'];
								$getteacher = $_POST['teacher'];
								$getnews = $_POST['news'];
								$getmessage = $_POST['message'];
								$getmembers = $_POST['members'];
								$error = "";
								if($gethead =="") $error.="*Please enter a head"."<br>";
								if($getteacher=="") $error.="*Please enter a Teacher"."<br>";
								if($getnews=="") $error.="*Please enter some news"."<br>";
								if($getmessage=="") $error.="*Please enter a message"."<br>";
								if($getmembers=="") $error.="*Please enter the members of this club"."<br>";

 								if($error==""){
    
      												if(mysql_query($sqlqup))
 																			{
    																			echo " Club page updated ";
    																			echo '<hr>';
    																			echo 'head:';
	 																			echo $gethead;
	 																			echo '<hr>';
	 																			echo 'Teacher:';
	 																			echo $getteacher;
	 																			echo '<hr>';
	 																			echo 'News:';
	 																			echo $getnews;
	 																			echo '<hr>';
	 																			echo 'Message:';
	 																			echo $getmessage;
	 																			echo '<hr>';
	 																			echo 'Members';
	 																			echo $getmembers;
	 																			echo '<hr>';
 																			}
  													else {
															echo " Failed to upadate";
					 									 }

											  }
 											  else{
    												echo "<div align='center'>". $error ."</div>";
												   }

							}
else {
	  $mclubqu=mysql_query($sqlview);
	  $club= mysql_fetch_array($mclubqu);
	  ?>

  		<div align="center">
  		  		<h1><? echo $club['Club']?> Club</h1>
  		     		<form action="" method="POST">
  					<table width="588"  border="1.2">
  		  				<tr>
  		    				<td width="95">Head</td>
		  					<td width="7">&nbsp;</td>
   				  		    <td width="302"><input name="head" type="text"/></td>
					  		<td width="166"><? echo $club['Head']?> </td>
  				  		</tr>
				        <tr>
    				  		<td>Teacher</td>
  							<td>&nbsp;</td>
    	  					<td><input name="teacher" type="text"/></td>
				  			<td><? echo $club['Teacher']?> </td>
  				  		</tr>
  		  				<tr>
    			  			<td>News</td>
		  					<td>&nbsp;</td>
      						<td><textarea name="news" cols="40" rows="10"></textarea></td>
	  						<td><? echo $club['News']?> </td>
  	  					</tr>
	  					<tr>
    		  				<td>Message</td>
	  						<td>&nbsp;</td>
    			  			<td><textarea name="message" cols="40" rows="10"></textarea></td>
				  			<td><? echo $club['Message']?> </td>
  		  				</tr>
		  					<tr>
    			  			<td>Members</td>
  							<td>&nbsp;</td>
    	  		  			<td><textarea name="members" cols="40" rows="10"></textarea></td>
  							<td><? echo $club['members']?> </td>
  		  				</tr>
				  		</tr>
				  			<tr>
    				  		<td>&nbsp;</td>
					  		<td>&nbsp;</td>
    				  		<td><center><input type="submit" name="Submit_1" value="Submit" /> </center>
						</td>
    						<td>&nbsp;</td>
  						</tr>
		  			</table>
					</form>
     </div>

	<?php
}
?>

my problem is that it says
failed to update

this code here is a magnified verison of the top 1
where somthing goes wrong
<?php
$sqlqup= "UPDATE club_data SET Head=$gethead, Teacher=$getteacher, News=$getnews, Message=$getmessage, members=$getmembers WHERE ClubID=$clubno";
if(mysql_query($sqlqup))
{
echo " Club page updated ";
echo '<hr>';
echo 'head:';
echo $gethead;
echo '<hr>';
echo 'Teacher:';
echo $getteacher;
echo '<hr>';
echo 'News:';
echo $getnews;
echo '<hr>';
echo 'Message:';
echo $getmessage;
echo '<hr>';
echo 'Members';
echo $getmembers;
echo '<hr>';
}
  													
else {
															
        echo " Failed to upadate";
					 									 
 }
what could be wrong
is it a sql query error
cause i have bo clue

ps it says that the sql query is correct on sqlyog

regards ludger
:D

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 30 August 2006 - 01:00 PM

Whats the error, cant help much without seeing the error(s) being returned. Post the errors here

#3 ludjer

ludjer
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts
  • LocationSouth Africa-Pretoria

Posted 30 August 2006 - 01:14 PM

the error is that it does not edit database witch it is ment to edit it
just returns to the main page with the header looking like this
http://localhost/intranet/clubs/admins/edit.php?head=213324&teacher=234324&latest+news=234324324&message=234234423&members=324324324324&Submit=Submit

PS.. the 1234123 is what i edited it into
here is a better one
http://localhost/intranet/clubs/admins/edit.php?head=Ludger&teacher=Piet&latest+news=Welcome&message=This+is+a+club&members=22&Submit=Submit

i am thinking of getting the info from the headder using
<?php 
if (isset($_GET['club'])) $club = $_GET['club'];
php?>

but there could be alot of info so i really dont know

regards
Ludger



:D

#4 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 30 August 2006 - 01:28 PM

Are you getting the "Failed to Update" error or is the data just not changing?

ALWAYS... let me repeat ALWAYS do the following:

1) build your query outside of the mysql_query function:
<?php
$query = "UPDATE tablexyz blah blah";
$result = mysql_query($query) or die(mysql_error());
?>

Right now, you're checking whether you have a valid result or not, but you're not displaying any error or even logging the error.  Mysql can provide you with some valuable troubleshooting information!

Info: PHP Manual


#5 ludjer

ludjer
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts
  • LocationSouth Africa-Pretoria

Posted 30 August 2006 - 02:59 PM

i have updated it
but now there is another error
:D

#6 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 30 August 2006 - 03:00 PM

.... do you want to tell us what that error was??

Info: PHP Manual


#7 ludjer

ludjer
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts
  • LocationSouth Africa-Pretoria

Posted 30 August 2006 - 03:05 PM

this is what pops up on the screen

Failed to upadate



:D

#8 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 30 August 2006 - 03:08 PM

Chnage this:
echo " Failed to upadate";
to
echo " Failed to upadate, Reason for failing<br />\n" . mysql_error());
With this code you shoul now get an error message from MySQL why your query is failing

What I think is the problem is is becuase you are not use quotes around your values. Try thhe following as the query:
$sqlqup = "UPDATE club_data SET Head='$gethead', Teacher='$getteacher', News='$getnews', Message='$getmessage', members='$getmembers' WHERE ClubID='$clubno'";


#9 ludjer

ludjer
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts
  • LocationSouth Africa-Pretoria

Posted 30 August 2006 - 03:14 PM

Failed to upadate, Reason for failing
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' Teacher=, News=, Message=, members= WHERE ClubID='1'' at line 1
i see

i will try it now with quots
:D

#10 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 30 August 2006 - 03:17 PM

From the error you are getting it looks like your variables are being replaced with their values. But I'm not sure. Did the new query work?

#11 ludjer

ludjer
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts
  • LocationSouth Africa-Pretoria

Posted 30 August 2006 - 03:18 PM

ye it did

Club page updated
--------------------------------------------------------------------------------
head:sanan
--------------------------------------------------------------------------------
Teacher:none
--------------------------------------------------------------------------------
News:noen
--------------------------------------------------------------------------------
Message:13
--------------------------------------------------------------------------------
Members12213


but now another error

they did not go into the database

my database is emtey

[attachment deleted by admin]
:D

#12 ludjer

ludjer
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts
  • LocationSouth Africa-Pretoria

Posted 30 August 2006 - 03:36 PM

maby if you could give me a quick example
on taking a string and putting it into a database
cause i know that it is getting the info from the forms
but its not getting onto the database
it puts " " (nothing and turns current into nothing) in the database

thx alot

ludger

:D

#13 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 30 August 2006 - 03:46 PM

I think I know whats happing. You are setting up your query before you define the variables you use in your query. The query should be defined before this:
if(mysql_query($sqlqup))
This si what your code should be:
<?php

$hostname_intranet = "localhost";
$database_intranet = "intranet";
$username_intranet = "root";
$password_intranet = "***";

$intranet = mysql_pconnect($hostname_intranet, $username_intranet, $password_intranet) or trigger_error(mysql_error(),E_USER_ERROR);

if(isset($_POST['Submit_1']))
{

    $gethead = $_POST['head'];
	$getteacher = $_POST['teacher'];
	$getnews = $_POST['news'];
	$getmessage = $_POST['message'];
	$getmembers = $_POST['members'];
	$error = "";

    if($gethead =="") $error.="*Please enter a head"."<br>";
	if($getteacher=="") $error.="*Please enter a Teacher"."<br>";
	if($getnews=="") $error.="*Please enter some news"."<br>";
	if($getmessage=="") $error.="*Please enter a message"."<br>";
	if($getmembers=="") $error.="*Please enter the members of this club"."<br>";

 	if(isset($errro))
    {
        $sqlqup= "UPDATE club_data SET Head=$gethead, Teacher=$getteacher, News=$getnews, Message=$getmessage, members=$getmembers WHERE ClubID='$clubno'";

        if(mysql_query($sqlqup))
 		{
    	    echo " Club page updated ";
    		echo '<hr>';
    		echo 'head:';
	 		echo $gethead;
	 		echo '<hr>';
	 		echo 'Teacher:';
	 		echo $getteacher;
	 		echo '<hr>';
	 		echo 'News:';
	 		echo $getnews;
	 		echo '<hr>';
	 		echo 'Message:';
	 		echo $getmessage;
	 		echo '<hr>';
	 		echo 'Members';
	 		echo $getmembers;
	 		echo '<hr>';
 		}
  		else
        {
		    echo " Failed to upadate";
		}

	}
 	else
    {
    	    echo "<div align='center'>". $error ."</div>";
	}
}
else
{
    $sqlview="select * from `intranet`.`club_data` WHERE ClubID='$clubno'";

    $mclubqu = mysql_query($sqlview);
    
	$club = mysql_fetch_array($mclubqu);
?>
  		<div align="center">
  		  		<h1><? echo $club['Club']?> Club</h1>
  		     		<form action="" method="POST">
  					<table width="588"  border="1.2">
  		  				<tr>
  		    				<td width="95">Head</td>
		  					<td width="7">&nbsp;</td>
   				  		    <td width="302"><input name="head" type="text"/></td>
					  		<td width="166"><? echo $club['Head']?> </td>
  				  		</tr>
				        <tr>
    				  		<td>Teacher</td>
  							<td>&nbsp;</td>
    	  					<td><input name="teacher" type="text"/></td>
				  			<td><? echo $club['Teacher']?> </td>
  				  		</tr>
  		  				<tr>
    			  			<td>News</td>
		  					<td>&nbsp;</td>
      						<td><textarea name="news" cols="40" rows="10"></textarea></td>
	  						<td><? echo $club['News']?> </td>
  	  					</tr>
	  					<tr>
    		  				<td>Message</td>
	  						<td>&nbsp;</td>
    			  			<td><textarea name="message" cols="40" rows="10"></textarea></td>
				  			<td><? echo $club['Message']?> </td>
  		  				</tr>
		  					<tr>
    			  			<td>Members</td>
  							<td>&nbsp;</td>
    	  		  			<td><textarea name="members" cols="40" rows="10"></textarea></td>
  							<td><? echo $club['members']?> </td>
  		  				</tr>
				  		</tr>
				  			<tr>
    				  		<td>&nbsp;</td>
					  		<td>&nbsp;</td>
    				  		<td><center><input type="submit" name="Submit_1" value="Submit" /> </center>
						</td>
    						<td>&nbsp;</td>
  						</tr>
		  			</table>
					</form>
     </div>

	<?php
}
?>


#14 ludjer

ludjer
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts
  • LocationSouth Africa-Pretoria

Posted 30 August 2006 - 04:28 PM

it says no database selected??

Failed to upadate, Reason for failing
No database selected

i used your code and it said that
then i tried using my code but just move

$sqlqup= "UPDATE club_data SET Head=$gethead, Teacher=$getteacher, News=$getnews, Message=$getmessage, members=$getmembers WHERE ClubID='$clubno'";

        if(mysql_query($sqlqup))

same resault both ways
:D

#15 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 30 August 2006 - 04:32 PM

Add
mysql_select_db($database_intranet, $intranet);

after
$intranet = mysql_pconnect($hostname_intranet, $username_intranet, $password_intranet) or trigger_error(mysql_error(),E_USER_ERROR);


#16 ludjer

ludjer
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts
  • LocationSouth Africa-Pretoria

Posted 30 August 2006 - 04:35 PM

Failed to upadate, Reason for failing
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''club_data' SET Head=sanan, Teacher=none, News=noneeen, Message=noneoneo, member' at line 1

here is my qeury
UPDATE 'club_data' SET Head='$gethead', Teacher='$getteacher', 
News='$getnews', Message='$getmessage', members='$getmembers' 
WHERE ClubID='$clubno'

:D

#17 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 30 August 2006 - 04:38 PM

You dont need quotes around club_data, that is fine on its own as its the table name. You only use quotes around the columns values.
So use this as the query:
UPDATE club_data SET Head='$gethead', Teacher='$getteacher', News='$getnews', Message='$getmessage', members='$getmembers' WHERE ClubID='$clubno'
If I put quotes around club_data then I apologiese fro my mistake.

#18 ludjer

ludjer
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts
  • LocationSouth Africa-Pretoria

Posted 30 August 2006 - 04:42 PM

if there are no quots then it gives no database selected


so i used your query and add the quots and this is what i got

with quots:
Failed to upadate, Reason for failing
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''club_data' SET Head='sanan', Teacher='none', News='noneeen', Message='noneoneo'' at line 1

without:
Failed to upadate, Reason for failing
No database selected

:D

#19 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 30 August 2006 - 04:43 PM

please re-post all of your code as it looks like now.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#20 ludjer

ludjer
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts
  • LocationSouth Africa-Pretoria

Posted 30 August 2006 - 04:45 PM

<?php
/*session checker */
if (!isset($_SESSION)) {
  session_start();
}
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
  // For security, start by assuming the visitor is NOT authorized. 
  $isValid = False; 

  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  if (!empty($UserName)) { 
    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
    // Parse the strings into arrays. 
    $arrUsers = Explode(",", $strUsers); 
    $arrGroups = Explode(",", $strGroups); 
    if (in_array($UserName, $arrUsers)) { 
      $isValid = true; 
    } 
    // Or, you may restrict access to only certain users based on their username. 
    if (in_array($UserGroup, $arrGroups)) { 
      $isValid = true; 
    } 
    if (($strUsers == "") && true) { 
      $isValid = true; 
    } 
  } 
  return $isValid; 
}

$MM_restrictGoTo = "login.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0) 
  $MM_referrer .= "?" . $QUERY_STRING;
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo); 
  exit;
}
##club veryfiyer
if (isset($_GET['club'])) $club = $_GET['club']; 

else $club = 'error';
$error='no';

switch ($club) {

case 'error': 
$error='yes';  
break;

case '1': 
$clubno='1';  
break;
case '2': 
$clubno='2';  
break;
case '3': 
$clubno='3';  
break;

default:
$error='yes';
break;
} 
 
$hostname_intranet = "localhost";
$database_intranet = "intranet";
$username_intranet = "root";
$password_intranet = "jam3s0n";

$intranet = mysql_pconnect($hostname_intranet, $username_intranet, $password_intranet) or trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db($club_data, $intranet);

if(isset($_POST['Submit_1']))
{

    $gethead = $_POST['head'];
	$getteacher = $_POST['teacher'];
	$getnews = $_POST['news'];
	$getmessage = $_POST['message'];
	$getmembers = $_POST['members'];
	$error = "";

    if($gethead =="") $error.="*Please enter a head"."<br>";
	if($getteacher=="") $error.="*Please enter a Teacher"."<br>";
	if($getnews=="") $error.="*Please enter some news"."<br>";
	if($getmessage=="") $error.="*Please enter a message"."<br>";
	if($getmembers=="") $error.="*Please enter the members of this club"."<br>";

 	if(isset($error))
    {
        $sqlqup= "UPDATE 'club_data' SET Head='$gethead', Teacher='$getteacher', News='$getnews', Message='$getmessage', members='$getmembers' WHERE ClubID='$clubno'";

        if(mysql_query($sqlqup))
 		{
    	    echo " Club page updated ";
    		echo '<hr>';
    		echo 'head:';
	 		echo $gethead;
	 		echo '<hr>';
	 		echo 'Teacher:';
	 		echo $getteacher;
	 		echo '<hr>';
	 		echo 'News:';
	 		echo $getnews;
	 		echo '<hr>';
	 		echo 'Message:';
	 		echo $getmessage;
	 		echo '<hr>';
	 		echo 'Members';
	 		echo $getmembers;
	 		echo '<hr>';
 		}
  		else
        {
		    echo " Failed to upadate, Reason for failing<br />\n" . mysql_error();
		}

	}
 	else
    {
    	    echo "<div align='center'>". $error ."</div>";
	}
}
else
{
    $sqlview="select * from `intranet`.`club_data` WHERE ClubID='$clubno'";

    $mclubqu = mysql_query($sqlview);
    
	$club = mysql_fetch_array($mclubqu);
?>
  		<div align="center">
  		  		<h1><? echo $club['Club']?> Club</h1>
  		     		<form action="" method="POST">
  					<table width="588"  border="1.2">
  		  				<tr>
  		    				<td width="95">Head</td>
		  					<td width="7">&nbsp;</td>
   				  		    <td width="302"><input name="head" type="text"/></td>
					  		<td width="166"><? echo $club['Head']?> </td>
  				  		</tr>
				        <tr>
    				  		<td>Teacher</td>
  							<td>&nbsp;</td>
    	  					<td><input name="teacher" type="text"/></td>
				  			<td><? echo $club['Teacher']?> </td>
  				  		</tr>
  		  				<tr>
    			  			<td>News</td>
		  					<td>&nbsp;</td>
      						<td><textarea name="news" cols="40" rows="10"></textarea></td>
	  						<td><? echo $club['News']?> </td>
  	  					</tr>
	  					<tr>
    		  				<td>Message</td>
	  						<td>&nbsp;</td>
    			  			<td><textarea name="message" cols="40" rows="10"></textarea></td>
				  			<td><? echo $club['Message']?> </td>
  		  				</tr>
		  					<tr>
    			  			<td>Members</td>
  							<td>&nbsp;</td>
    	  		  			<td><textarea name="members" cols="40" rows="10"></textarea></td>
  							<td><? echo $club['members']?> </td>
  		  				</tr>
				  		</tr>
				  			<tr>
    				  		<td>&nbsp;</td>
					  		<td>&nbsp;</td>
    				  		<td><center><input type="submit" name="Submit_1" value="Submit" /> </center>
						</td>
    						<td>&nbsp;</td>
  						</tr>
		  			</table>
					</form>
     </div>

	<?php
}
?>

:D




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users